Commit 6b920417 authored by Daniel Siepmann's avatar Daniel Siepmann

Merge branch '29-implement-php-mess-detector' into 'develop'

Resolve "Implement PHP Mess Detector"

Closes #29

See merge request !35
parents dafe0b42 f55c37b9
Pipeline #148 passed with stage
in 3 minutes and 33 seconds
......@@ -9,7 +9,7 @@ before_script:
- apt-get update; apt-get install -y unzip
- composer install --optimize-autoloader --no-interaction --no-ansi --prefer-dist
lint:coding-guideline:
lint:coding-guideline: &PHP-LINTING
image: tetraweb/php:7.0
stage: test
script:
......@@ -19,6 +19,12 @@ lint:coding-guideline:
when: on_failure
paths:
- result
lint:php-mass-detection:
<<: *PHP-LINTING
script:
- mkdir result
- ./vendor/bin/phpmd src text phpmd.xml | tee result/phpmd.txt
test:5.3: &PHP-UNITTESTING
image: tetraweb/php:5.3
stage: test
......
......@@ -35,7 +35,8 @@
},
"require-dev": {
"composer/composer": "^1.4",
"phpunit/phpunit": "^4.5 || ^5.0.5"
"phpunit/phpunit": "^4.5 || ^5.0.5",
"phpmd/phpmd": "^2.6"
},
"extra": {
"class": "Higidi\\ComposerPhpCSStandardsPlugin\\Plugin",
......
<?xml version="1.0"?>
<ruleset name="My first PHPMD rule set"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="
http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/cleancode.xml" />
<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/controversial.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml" />
<rule ref="rulesets/unusedcode.xml" />
</ruleset>
......@@ -45,6 +45,8 @@ class Installer extends LibraryInstaller
* @param string $type
* @param Filesystem $filesystem
* @param BinaryInstaller $binaryInstaller
*
* @SuppressWarnings(PHPMD.ShortVariable)
*/
public function __construct(
IOInterface $io,
......@@ -64,12 +66,12 @@ class Installer extends LibraryInstaller
if (!parent::isInstalled($repo, $package)) {
return false;
}
$sourceStandards = $this->getSourceStandards($package);
$destinationStandards = $this->getDestinationStandards($repo);
$srcStandards = $this->getSourceStandards($package);
$dstStandards = $this->getDestinationStandards($repo);
foreach ($sourceStandards as $sourceStandard) {
if (!$destinationStandards->hasStandard($sourceStandard)
|| !$this->compareStandards($sourceStandard, $destinationStandards->getStandard($sourceStandard))
foreach ($srcStandards as $srcStandard) {
if (!$dstStandards->hasStandard($srcStandard)
|| !$this->compareStandards($srcStandard, $dstStandards->getStandard($srcStandard))
) {
return false;
}
......@@ -113,6 +115,8 @@ class Installer extends LibraryInstaller
* @param PackageInterface $package
* @param bool $override
* @return void
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
protected function installStandards(
InstalledRepositoryInterface $repo,
......@@ -120,14 +124,14 @@ class Installer extends LibraryInstaller
$override = false
) {
$filesystem = new SymfonyFilesystem();
$sourceStandards = $this->getSourceStandards($package);
$destStandardsBasePath = $this->getPHPCodeSnifferStandardsBasePath($repo);
$srcStandards = $this->getSourceStandards($package);
$dstStdBasePath = $this->getPHPCodeSnifferStandardsBasePath($repo);
$this->io->writeError(' Installing PHP-CodeSniffer Standards:', false);
foreach ($sourceStandards as $sourceStandard) {
$this->io->writeError(sprintf(' <info>%s</info>', $sourceStandard->getName()));
$sourcePath = $sourceStandard->getPath();
$destPath = $destStandardsBasePath . DIRECTORY_SEPARATOR . $sourceStandard->getName();
$filesystem->mirror($sourcePath, $destPath, null, array('override' => $override));
foreach ($srcStandards as $srcStandard) {
$this->io->writeError(sprintf(' <info>%s</info>', $srcStandard->getName()));
$srcPath = $srcStandard->getPath();
$dstPath = $dstStdBasePath . DIRECTORY_SEPARATOR . $srcStandard->getName();
$filesystem->mirror($srcPath, $dstPath, null, array('override' => $override));
}
}
......@@ -138,17 +142,17 @@ class Installer extends LibraryInstaller
*/
protected function removeStandards(InstalledRepositoryInterface $repo, PackageInterface $package)
{
$sourceStandards = $this->getSourceStandards($package);
$destinationStandards = $this->getDestinationStandards($repo);
$srcStandards = $this->getSourceStandards($package);
$dstStandards = $this->getDestinationStandards($repo);
$this->io->writeError(' Removing PHP-CodeSniffer Standards:', false);
foreach ($sourceStandards as $sourceStandard) {
if (!$destinationStandards->hasStandard($sourceStandard)) {
foreach ($srcStandards as $srcStandard) {
if (!$dstStandards->hasStandard($srcStandard)) {
continue;
}
$this->io->writeError(sprintf(' <info>%s</info>', $sourceStandard->getName()));
$destinationStandard = $destinationStandards->getStandard($sourceStandard);
$this->io->writeError(sprintf(' <info>%s</info>', $srcStandard->getName()));
$dstStandard = $dstStandards->getStandard($srcStandard);
$this->filesystem->removeDirectory($destinationStandard->getPath());
$this->filesystem->removeDirectory($dstStandard->getPath());
}
}
......@@ -249,10 +253,10 @@ class Installer extends LibraryInstaller
*/
public function supports($packageType)
{
$secondaryPackageTypes = array('phpcodesniffer-standards');
$deprecatedPackageTypes = array('php-codesniffer-standards');
$secondaryTypes = array('phpcodesniffer-standards');
$deprecatedTypes = array('php-codesniffer-standards');
return parent::supports($packageType)
|| in_array($packageType, array_merge($secondaryPackageTypes, $deprecatedPackageTypes));
|| in_array($packageType, array_merge($secondaryTypes, $deprecatedTypes));
}
}
......@@ -32,6 +32,8 @@ class Plugin implements PluginInterface
* @param IOInterface $io
*
* @return void
*
* @SuppressWarnings(PHPMD.ShortVariable)
*/
public function activate(Composer $composer, IOInterface $io)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment