Browse Source

DX: Fix PHPStan errors (#6504)

Fix PHPStan errors
Julien Falque 2 years ago
parent
commit
40716fc8c2

+ 1 - 5
phpstan.neon

@@ -23,10 +23,6 @@ parameters:
         -
             message: '#^.+no value type specified in iterable type.+\.$#'
             path: *
-            count: 561
-        -
-            message: '#^Property .+ has no type specified\.$#'
-            path: *
-            count: 7
+            count: 542
     tipsOfTheDay: false
     tmpDir: dev-tools/phpstan/cache

+ 5 - 1
src/ConfigInterface.php

@@ -15,6 +15,7 @@ declare(strict_types=1);
 namespace PhpCsFixer;
 
 use PhpCsFixer\Fixer\FixerInterface;
+use SplFileInfo;
 
 /**
  * @author Fabien Potencier <fabien@symfony.com>
@@ -39,7 +40,7 @@ interface ConfigInterface
     /**
      * Returns files to scan.
      *
-     * @return iterable|\Traversable
+     * @return iterable<SplFileInfo>
      */
     public function getFinder(): iterable;
 
@@ -99,6 +100,9 @@ interface ConfigInterface
      */
     public function setCacheFile(string $cacheFile): self;
 
+    /**
+     * @param iterable<SplFileInfo> $finder
+     */
     public function setFinder(iterable $finder): self;
 
     public function setFormat(string $format): self;

+ 10 - 2
src/Console/ConfigurationResolver.php

@@ -147,14 +147,17 @@ final class ConfigurationResolver
      */
     private ?iterable $finder = null;
 
-    private $format;
+    private ?string $format = null;
 
     /**
      * @var null|Linter
      */
     private $linter;
 
-    private $path;
+    /**
+     * @var null|list<string>
+     */
+    private ?array $path = null;
 
     /**
      * @var null|string
@@ -480,6 +483,9 @@ final class ConfigurationResolver
         return $this->usingCache;
     }
 
+    /**
+     * @return iterable<\SplFileInfo>
+     */
     public function getFinder(): iterable
     {
         if (null === $this->finder) {
@@ -803,6 +809,8 @@ final class ConfigurationResolver
 
     /**
      * Apply path on config instance.
+     *
+     * @return iterable<\SplFileInfo>
      */
     private function resolveFinder(): iterable
     {

+ 3 - 0
src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php

@@ -116,6 +116,9 @@ namespace Foo {
         $tokens->clearTokenAndMergeSurroundingWhitespace($openIndex);
     }
 
+    /**
+     * @return iterable<int>
+     */
     private function findCurlyBraceOpen(Tokens $tokens): iterable
     {
         for ($i = \count($tokens) - 1; $i > 0; --$i) {

+ 3 - 0
src/Fixer/Import/FullyQualifiedStrictTypesFixer.php

@@ -180,6 +180,9 @@ class SomeClass
         }
     }
 
+    /**
+     * @return iterable<string, array{int, int}>
+     */
     private function getTypes(Tokens $tokens, int $index, int $endIndex): iterable
     {
         $index = $typeStartIndex = $typeEndIndex = $tokens->getNextMeaningfulToken($index - 1);

+ 3 - 0
src/Fixer/Import/GlobalNamespaceImportFixer.php

@@ -652,6 +652,9 @@ if (count($x)) {
         return [$global, $other];
     }
 
+    /**
+     * @return iterable<string>
+     */
     private function findFunctionDeclarations(Tokens $tokens, int $start, int $end): iterable
     {
         for ($index = $start; $index <= $end; ++$index) {

+ 8 - 0
src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php

@@ -507,6 +507,14 @@ final class MyTest extends \PHPUnit_Framework_TestCase
         ]);
     }
 
+    /**
+     * @return iterable<array{
+     *     index: int,
+     *     loweredName: string,
+     *     openBraceIndex: int,
+     *     closeBraceIndex: int,
+     * }>
+     */
     private function getPreviousAssertCall(Tokens $tokens, int $startIndex, int $endIndex): iterable
     {
         $functionsAnalyzer = new FunctionsAnalyzer();

+ 4 - 18
tests/AbstractFunctionReferenceFixerTest.php

@@ -24,22 +24,6 @@ use PhpCsFixer\Tokenizer\Tokens;
  */
 final class AbstractFunctionReferenceFixerTest extends TestCase
 {
-    private $fixer;
-
-    protected function setUp(): void
-    {
-        $this->fixer = new FunctionReferenceTestFixer();
-
-        parent::setUp();
-    }
-
-    protected function tearDown(): void
-    {
-        $this->fixer = null;
-
-        parent::tearDown();
-    }
-
     /**
      * @param null|int[] $expected
      *
@@ -52,13 +36,15 @@ final class AbstractFunctionReferenceFixerTest extends TestCase
         int $start = 0,
         ?int $end = null
     ): void {
-        static::assertTrue($this->fixer->isRisky());
+        $fixer = new FunctionReferenceTestFixer();
+
+        static::assertTrue($fixer->isRisky());
 
         $tokens = Tokens::fromCode($source);
 
         static::assertSame(
             $expected,
-            $this->fixer->findTest(
+            $fixer->findTest(
                 $functionNameToSearch,
                 $tokens,
                 $start,

+ 7 - 0
tests/AutoReview/ProjectCodeTest.php

@@ -14,6 +14,7 @@ declare(strict_types=1);
 
 namespace PhpCsFixer\Tests\AutoReview;
 
+use PhpCsFixer\DocBlock\Annotation;
 use PhpCsFixer\DocBlock\DocBlock;
 use PhpCsFixer\FixerFactory;
 use PhpCsFixer\Preg;
@@ -726,6 +727,9 @@ final class ProjectCodeTest extends TestCase
         }
     }
 
+    /**
+     * @return iterable<string, string>
+     */
     private function getUsedDataProviderMethodNames(string $testClassName): iterable
     {
         foreach ($this->getAnnotationsOfTestClass($testClassName, 'dataProvider') as $methodName => $dataProviderAnnotation) {
@@ -735,6 +739,9 @@ final class ProjectCodeTest extends TestCase
         }
     }
 
+    /**
+     * @return iterable<string, Annotation>
+     */
     private function getAnnotationsOfTestClass(string $testClassName, string $annotation): iterable
     {
         $tokens = Tokens::fromCode(file_get_contents(

+ 2 - 1
tests/ConfigTest.php

@@ -193,7 +193,8 @@ final class ConfigTest extends TestCase
     }
 
     /**
-     * @param FixerInterface[] $expected
+     * @param list<FixerInterface>     $expected
+     * @param iterable<FixerInterface> $suite
      *
      * @dataProvider provideRegisterCustomFixersCases
      */

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