Browse Source

Increase PHPStan level to 3

Julien Falque 5 years ago
parent
commit
83c8ea1a8d

+ 2 - 1
dev-tools/composer.json

@@ -4,10 +4,11 @@
     },
     "require-dev": {
         "humbug/box": "^3.8",
+        "jangregor/phpstan-prophecy": "^0.6",
         "localheinz/composer-normalize": "^1.1",
         "mi-schi/phpmd-extension": "^4.3",
         "phpmd/phpmd": "^2.6",
-        "phpstan/phpstan-phpunit": "^0.11.2"
+        "phpstan/phpstan-phpunit": "^0.12"
     },
     "conflict": {
         "hhvm": "*"

+ 1 - 1
dev-tools/install.sh

@@ -56,4 +56,4 @@ composer info -D | sort
 
 echo λλλ phive packages
 
-./bin/phive install --trust-gpg-keys D2CCAC42F6295E7D,8E730BA25823D8B5
+./bin/phive install --trust-gpg-keys D2CCAC42F6295E7D,8E730BA25823D8B5,CF1A108D0E7AE720

+ 1 - 1
dev-tools/phive.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <phive xmlns="https://phar.io/phive">
   <phar name="composer-require-checker" version="^2.0" installed="2.0.0" location="./tools/composer-require-checker" copy="false"/>
-  <phar name="phpstan" version="^0.11.15" installed="0.11.15" location="./tools/phpstan" copy="false"/>
+  <phar name="phpstan" version="^0.12" installed="0.12.9" location="./tools/phpstan" copy="true"/>
 </phive>

+ 6 - 2
phpstan.neon

@@ -1,14 +1,18 @@
 includes:
+    - dev-tools/vendor/jangregor/phpstan-prophecy/src/extension.neon
     - dev-tools/vendor/phpstan/phpstan-phpunit/extension.neon
 
 parameters:
-    level: 1
+    level: 3
     paths:
         - src
         - tests
     excludes_analyse:
         - tests/Fixtures
     ignoreErrors:
-        - '/^.+::__construct\(\) does not call parent constructor from SplFileInfo\.$/'
         - '/^Return typehint of method PhpCsFixer\\Tests\\Test\\.+::createIsIdenticalStringConstraint\(\) has invalid type PHPUnit_Framework_Constraint_IsIdentical\.$/'
         - '/^Class (Symfony\\Contracts\\EventDispatcher\\Event|Symfony\\Component\\EventDispatcher\\Event) not found.$/'
+        - '/^(Access|Call) to an undefined (property|method) PhpCsFixer\\AccessibleObject\\AccessibleObject::.+$/'
+        -
+            message: '/^Unsafe usage of new static\(\)\.$/'
+            path: src/Config.php

+ 1 - 1
src/AbstractFixer.php

@@ -140,7 +140,7 @@ abstract class AbstractFixer implements FixerInterface, DefinedFixerInterface
                     'Option "%s" for rule "%s" is deprecated and will be removed in version %d.0. %s',
                     $name,
                     $this->getName(),
-                    (int) Application::VERSION + 1,
+                    Application::getMajorVersion() + 1,
                     str_replace('`', '"', $option->getDeprecationMessage())
                 );
 

+ 1 - 1
src/Config.php

@@ -64,7 +64,7 @@ class Config implements ConfigInterface
     }
 
     /**
-     * {@inheritdoc}
+     * @return Finder
      */
     public function getFinder()
     {

+ 8 - 0
src/Console/Application.php

@@ -63,6 +63,14 @@ final class Application extends BaseApplication
         ));
     }
 
+    /**
+     * @return int
+     */
+    public static function getMajorVersion()
+    {
+        return (int) explode('.', self::VERSION)[0];
+    }
+
     /**
      * {@inheritdoc}
      */

+ 12 - 4
src/Console/Command/DescribeCommand.php

@@ -25,7 +25,6 @@ use PhpCsFixer\FixerConfiguration\DeprecatedFixerOption;
 use PhpCsFixer\FixerDefinition\CodeSampleInterface;
 use PhpCsFixer\FixerDefinition\FileSpecificCodeSampleInterface;
 use PhpCsFixer\FixerDefinition\FixerDefinition;
-use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
 use PhpCsFixer\FixerDefinition\VersionSpecificCodeSampleInterface;
 use PhpCsFixer\FixerFactory;
 use PhpCsFixer\Preg;
@@ -330,12 +329,21 @@ final class DescribeCommand extends Command
         $help = '';
 
         foreach ($rules as $rule => $config) {
-            /** @var FixerDefinitionInterface $definition */
-            $definition = $fixers[$rule]->getDefinition();
+            $fixer = $fixers[$rule];
+
+            if (!$fixer instanceof DefinedFixerInterface) {
+                throw new \RuntimeException(sprintf(
+                    'Cannot describe rule %s, the fixer does not implement %s',
+                    $rule,
+                    DefinedFixerInterface::class
+                ));
+            }
+
+            $definition = $fixer->getDefinition();
             $help .= sprintf(
                 " * <info>%s</info>%s\n   | %s\n%s\n",
                 $rule,
-                $fixers[$rule]->isRisky() ? ' <error>risky</error>' : '',
+                $fixer->isRisky() ? ' <error>risky</error>' : '',
                 $definition->getSummary(),
                 true !== $config ? sprintf("   <comment>| Configuration: %s</comment>\n", HelpCommand::toString($config)) : ''
             );

+ 3 - 1
src/Console/Command/HelpCommand.php

@@ -12,6 +12,7 @@
 
 namespace PhpCsFixer\Console\Command;
 
+use PhpCsFixer\AbstractFixer;
 use PhpCsFixer\Console\Application;
 use PhpCsFixer\Fixer\ConfigurableFixerInterface;
 use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
@@ -400,7 +401,7 @@ EOF
             ));
         }
 
-        for ($i = (int) Application::VERSION; $i > 0; --$i) {
+        for ($i = Application::getMajorVersion(); $i > 0; --$i) {
             if (1 === Preg::match('/Changelog for v('.$i.'.\d+.\d+)/', $changelog, $matches)) {
                 $version = $matches[1];
 
@@ -440,6 +441,7 @@ EOF
     {
         $help = '';
         $fixerFactory = new FixerFactory();
+        /** @var AbstractFixer[] $fixers */
         $fixers = $fixerFactory->registerBuiltInFixers()->getFixers();
 
         // sort fixers by name

+ 1 - 1
src/Console/ConfigurationResolver.php

@@ -762,7 +762,7 @@ final class ConfigurationResolver
             if (isset($rules[$fixerName]) && $fixer instanceof DeprecatedFixerInterface) {
                 $successors = $fixer->getSuccessorsNames();
                 $messageEnd = [] === $successors
-                    ? sprintf(' and will be removed in version %d.0.', (int) Application::VERSION + 1)
+                    ? sprintf(' and will be removed in version %d.0.', Application::getMajorVersion())
                     : sprintf('. Use %s instead.', str_replace('`', '"', Utils::naturalLanguageJoinWithBackticks($successors)));
 
                 $message = "Rule \"{$fixerName}\" is deprecated{$messageEnd}";

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