Browse Source

DX: use PHPMD

Dariusz Ruminski 8 years ago
parent
commit
561fc54bdc

+ 6 - 1
.travis.yml

@@ -59,9 +59,14 @@ install:
     - travis_retry composer update $DEFAULT_COMPOSER_FLAGS $COMPOSER_FLAGS
     - composer info -D | sort
 
+before_script:
+    - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then COMMIT_RANGE=$TRAVIS_COMMIT_RANGE; else COMMIT_RANGE="HEAD~..HEAD"; fi;
+    - if [ $TASK_SCA == 1 ]; then export COMMIT_SCA_FILES=`git diff --name-only --diff-filter=ACMRTUXB $COMMIT_RANGE`; fi
+
 script:
+    - if [ $TASK_SCA == 1 ]; then ./check_trailing_spaces.sh; fi
+    - if [ $TASK_SCA == 1 ] && [ -n "$COMMIT_SCA_FILES" ]; then vendor/bin/phpmd `echo $COMMIT_SCA_FILES | sed 's/ /,/g'` text phpmd.xml --exclude src/Resources,tests/Fixtures; fi;
     - if [ $TASK_SCA == 1 ]; then php php-cs-fixer fix --rules @PHP70Migration:risky,@PHP71Migration,native_function_invocation -q; fi
-    - if [ $TASK_SCA == 1 ]; then ./check_trailing_spaces.sh || travis_terminate 1; fi
 
     - if [ $TASK_TESTS == 1 ] && [ $TASK_TESTS_COVERAGE == 0 ]; then vendor/bin/phpunit --verbose; fi
     - if [ $TASK_TESTS == 1 ] && [ $TASK_TESTS_COVERAGE == 1 ]; then phpdbg -qrr vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml; fi

+ 2 - 0
composer.json

@@ -32,6 +32,8 @@
     "require-dev": {
         "johnkary/phpunit-speedtrap": "^1.1",
         "justinrainbow/json-schema": "^5.0",
+        "mi-schi/phpmd-extension": "^4.2",
+        "phpmd/phpmd": "^2.4.3",
         "phpunit/phpunit": "^4.8.35 || ^5.4.3",
         "satooshi/php-coveralls": "^1.0",
         "symfony/phpunit-bridge": "^3.2.2"

+ 29 - 0
phpmd.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<ruleset name="friendsofphp/php-cs-fixer"
+         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/controversial.xml/CamelCaseClassName" />
+    <rule ref="rulesets/controversial.xml/CamelCaseMethodName" />
+    <rule ref="rulesets/controversial.xml/CamelCaseParameterName" />
+    <rule ref="rulesets/controversial.xml/CamelCasePropertyName" />
+    <rule ref="rulesets/controversial.xml/CamelCaseVariableName" />
+
+    <rule ref="rulesets/design.xml/DevelopmentCodeFragment" />
+    <rule ref="rulesets/design.xml/EvalExpression" />
+    <rule ref="rulesets/design.xml/ExitExpression" />
+    <rule ref="rulesets/design.xml/GotoStatement" />
+
+    <rule ref="rulesets/naming.xml/ConstantNamingConventions" />
+
+    <rule ref="vendor/mi-schi/phpmd-extension/rulesets/cleancode.xml/DataStructureMethods" />
+    <rule ref="vendor/mi-schi/phpmd-extension/rulesets/cleancode.xml/SwitchStatement" />
+
+    <rule ref="vendor/mi-schi/phpmd-extension/rulesets/naming.xml/CommentDescription">
+        <properties>
+            <property name="percent" value="70" />
+        </properties>
+    </rule>
+</ruleset>

+ 0 - 2
src/AbstractDoctrineAnnotationFixer.php

@@ -21,8 +21,6 @@ use PhpCsFixer\Tokenizer\Tokens as PhpTokens;
 use PhpCsFixer\Tokenizer\TokensAnalyzer;
 
 /**
- * Base class for Doctrine annotation fixers.
- *
  * @internal
  */
 abstract class AbstractDoctrineAnnotationFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface

+ 0 - 2
src/AbstractFunctionReferenceFixer.php

@@ -16,8 +16,6 @@ use PhpCsFixer\Tokenizer\CT;
 use PhpCsFixer\Tokenizer\Tokens;
 
 /**
- * Base class for function reference fixers.
- *
  * @internal
  *
  * @author Vladimir Reznichenko <kalessil@gmail.com>

+ 0 - 2
src/AbstractPhpdocTypesFixer.php

@@ -105,8 +105,6 @@ abstract class AbstractPhpdocTypesFixer extends AbstractFixer
     }
 
     /**
-     * Normalize the given types.
-     *
      * @param string[] $types
      *
      * @return string[]

+ 0 - 8
src/Console/Command/FixCommand.php

@@ -46,29 +46,21 @@ final class FixCommand extends Command
     const EXIT_STATUS_FLAG_EXCEPTION_IN_APP = 64;
 
     /**
-     * EventDispatcher instance.
-     *
      * @var EventDispatcher
      */
     private $eventDispatcher;
 
     /**
-     * ErrorsManager instance.
-     *
      * @var ErrorsManager
      */
     private $errorsManager;
 
     /**
-     * Stopwatch instance.
-     *
      * @var Stopwatch
      */
     private $stopwatch;
 
     /**
-     * Config instance.
-     *
      * @var ConfigInterface
      */
     private $defaultConfig;

+ 2 - 2
src/Console/Command/HelpCommand.php

@@ -312,8 +312,8 @@ EOF
 
             usort($allowed, function ($valueA, $valueB) {
                 return strcasecmp(
-                    HelpCommand::toString($valueA),
-                    HelpCommand::toString($valueB)
+                    self::toString($valueA),
+                    self::toString($valueB)
                 );
             });
 

+ 15 - 7
src/Console/ConfigurationResolver.php

@@ -200,8 +200,6 @@ final class ConfigurationResolver
     }
 
     /**
-     * Returns config instance.
-     *
      * @return ConfigInterface
      */
     public function getConfig()
@@ -234,8 +232,6 @@ final class ConfigurationResolver
     }
 
     /**
-     * Returns config file path.
-     *
      * @return null|string
      */
     public function getConfigFile()
@@ -253,7 +249,21 @@ final class ConfigurationResolver
     public function getDiffer()
     {
         if (null === $this->differ) {
-            $this->differ = false === $this->options['diff'] ? new NullDiffer() : new SebastianBergmannDiffer();
+            $mapper = [
+                'null' => function () { return new NullDiffer(); },
+                'sbd' => function () { return new SebastianBergmannDiffer(); },
+            ];
+
+            $option = $this->options['diff'] ? 'sbd' : 'null';
+
+            if (!isset($mapper[$option])) {
+                throw new InvalidConfigurationException(sprintf(
+                    'Differ must be "sbd" or "null", got "%s".',
+                    $this->options['diff']
+                ));
+            }
+
+            $this->differ = $mapper[$option]();
         }
 
         return $this->differ;
@@ -279,8 +289,6 @@ final class ConfigurationResolver
     }
 
     /**
-     * Returns fixers.
-     *
      * @return FixerInterface[] An array of FixerInterface
      */
     public function getFixers()

+ 0 - 4
src/Console/Output/ProcessOutput.php

@@ -39,15 +39,11 @@ final class ProcessOutput implements ProcessOutputInterface
     ];
 
     /**
-     * Event dispatcher instance.
-     *
      * @var EventDispatcher
      */
     private $eventDispatcher;
 
     /**
-     * Stream output instance.
-     *
      * @var OutputInterface
      */
     private $output;

Some files were not shown because too many files changed in this diff