diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1c782ce0a2811ded0dbd200d9a7eeac06e56cc38..a911950da37b5b875458e67c8842b797314fd91a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/composer.json b/composer.json index d7fd38f1e359f5829122ce8102d7e0b7514fac17..48d319023cb1ce3fb8e8dd7c7a727eeb7afcdf8c 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/phpmd.xml b/phpmd.xml new file mode 100644 index 0000000000000000000000000000000000000000..43281e441e56484bac28a2f6dd90cb4ad0541b42 --- /dev/null +++ b/phpmd.xml @@ -0,0 +1,16 @@ +<?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> diff --git a/src/Installer.php b/src/Installer.php index 721f271af891f438a5ed22590c40451a011d5855..f3f8ccb35a81723bf9a520affba98f4b45266544 100644 --- a/src/Installer.php +++ b/src/Installer.php @@ -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)); } } diff --git a/src/Plugin.php b/src/Plugin.php index 72b5fc0c8b1b5cc45a0091327e2a06df77665e33..1f82091a4876151bd44f722be1ab8dc32be62449 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -32,6 +32,8 @@ class Plugin implements PluginInterface * @param IOInterface $io * * @return void + * + * @SuppressWarnings(PHPMD.ShortVariable) */ public function activate(Composer $composer, IOInterface $io) {