diff --git a/phpstan.neon b/phpstan.neon index 405b71ab3aa..23efbf5bee5 100644 --- a/phpstan.neon +++ b/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 diff --git a/src/ConfigInterface.php b/src/ConfigInterface.php index bc16c199bf7..86662021cfb 100644 --- a/src/ConfigInterface.php +++ b/src/ConfigInterface.php @@ -15,6 +15,7 @@ namespace PhpCsFixer; use PhpCsFixer\Fixer\FixerInterface; +use SplFileInfo; /** * @author Fabien Potencier @@ -39,7 +40,7 @@ public function getCustomFixers(): array; /** * Returns files to scan. * - * @return iterable|\Traversable + * @return iterable */ public function getFinder(): iterable; @@ -99,6 +100,9 @@ public function registerCustomFixers(iterable $fixers): self; */ public function setCacheFile(string $cacheFile): self; + /** + * @param iterable $finder + */ public function setFinder(iterable $finder): self; public function setFormat(string $format): self; diff --git a/src/Console/ConfigurationResolver.php b/src/Console/ConfigurationResolver.php index ac3f08a0d33..e845a857ee1 100644 --- a/src/Console/ConfigurationResolver.php +++ b/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 + */ + private ?array $path = null; /** * @var null|string @@ -480,6 +483,9 @@ public function getUsingCache(): bool return $this->usingCache; } + /** + * @return iterable<\SplFileInfo> + */ public function getFinder(): iterable { if (null === $this->finder) { @@ -803,6 +809,8 @@ private function validateRules(array $rules): void /** * Apply path on config instance. + * + * @return iterable<\SplFileInfo> */ private function resolveFinder(): iterable { diff --git a/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php b/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php index 8f260d8cabc..808e1453fad 100644 --- a/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php +++ b/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php @@ -116,6 +116,9 @@ private function clearOverCompleteBraces(Tokens $tokens, int $openIndex, int $cl $tokens->clearTokenAndMergeSurroundingWhitespace($openIndex); } + /** + * @return iterable + */ private function findCurlyBraceOpen(Tokens $tokens): iterable { for ($i = \count($tokens) - 1; $i > 0; --$i) { diff --git a/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php b/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php index 55dc6471e2e..9a08aae5ab4 100644 --- a/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php +++ b/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php @@ -180,6 +180,9 @@ private function replaceByShortType(Tokens $tokens, TypeAnalysis $type, array $u } } + /** + * @return iterable + */ private function getTypes(Tokens $tokens, int $index, int $endIndex): iterable { $index = $typeStartIndex = $typeEndIndex = $tokens->getNextMeaningfulToken($index - 1); diff --git a/src/Fixer/Import/GlobalNamespaceImportFixer.php b/src/Fixer/Import/GlobalNamespaceImportFixer.php index 183e26cb3bc..04a92e52517 100644 --- a/src/Fixer/Import/GlobalNamespaceImportFixer.php +++ b/src/Fixer/Import/GlobalNamespaceImportFixer.php @@ -652,6 +652,9 @@ private function filterUseDeclarations(array $declarations, callable $callback, return [$global, $other]; } + /** + * @return iterable + */ private function findFunctionDeclarations(Tokens $tokens, int $start, int $end): iterable { for ($index = $start; $index <= $end; ++$index) { diff --git a/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php b/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php index fbb93985aef..72508df69d3 100644 --- a/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php @@ -507,6 +507,14 @@ private function fixAssertSameEquals(Tokens $tokens, array $assertCall): void ]); } + /** + * @return iterable + */ private function getPreviousAssertCall(Tokens $tokens, int $startIndex, int $endIndex): iterable { $functionsAnalyzer = new FunctionsAnalyzer(); diff --git a/tests/AbstractFunctionReferenceFixerTest.php b/tests/AbstractFunctionReferenceFixerTest.php index e7841336ad3..10c30dea52a 100644 --- a/tests/AbstractFunctionReferenceFixerTest.php +++ b/tests/AbstractFunctionReferenceFixerTest.php @@ -24,22 +24,6 @@ */ 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 @@ public function testAbstractFunctionReferenceFixer( 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, diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index e20643bae0b..ecf7f65fb57 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\AutoReview; +use PhpCsFixer\DocBlock\Annotation; use PhpCsFixer\DocBlock\DocBlock; use PhpCsFixer\FixerFactory; use PhpCsFixer\Preg; @@ -726,6 +727,9 @@ public function testConstantsAreInUpperCase(string $className): void } } + /** + * @return iterable + */ private function getUsedDataProviderMethodNames(string $testClassName): iterable { foreach ($this->getAnnotationsOfTestClass($testClassName, 'dataProvider') as $methodName => $dataProviderAnnotation) { @@ -735,6 +739,9 @@ private function getUsedDataProviderMethodNames(string $testClassName): iterable } } + /** + * @return iterable + */ private function getAnnotationsOfTestClass(string $testClassName, string $annotation): iterable { $tokens = Tokens::fromCode(file_get_contents( diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 90983f68b05..51727195704 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -193,7 +193,8 @@ public function testThatMutatorHasFluentInterface(): void } /** - * @param FixerInterface[] $expected + * @param list $expected + * @param iterable $suite * * @dataProvider provideRegisterCustomFixersCases */ diff --git a/tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php b/tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php index ac2b15abd27..40685381aef 100644 --- a/tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php +++ b/tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php @@ -330,6 +330,9 @@ private static function assertCandidateTokenType(int $expected, AbstractFixer $f static::assertSame($expected, $reflectionProperty->getValue($fixer)); } + /** + * @return iterable + */ private static function getCodeSnippetsToConvertBothWays(): iterable { yield 'inside of HTML' => '
'; diff --git a/tests/Fixer/Basic/BracesFixerTest.php b/tests/Fixer/Basic/BracesFixerTest.php index 9cdac9fa464..e5c994ebc9a 100644 --- a/tests/Fixer/Basic/BracesFixerTest.php +++ b/tests/Fixer/Basic/BracesFixerTest.php @@ -28,9 +28,9 @@ */ final class BracesFixerTest extends AbstractFixerTestCase { - private static $configurationOopPositionSameLine = ['position_after_functions_and_oop_constructs' => BracesFixer::LINE_SAME]; - private static $configurationCtrlStructPositionNextLine = ['position_after_control_structures' => BracesFixer::LINE_NEXT]; - private static $configurationAnonymousPositionNextLine = ['position_after_anonymous_constructs' => BracesFixer::LINE_NEXT]; + private const CONFIGURATION_OOP_POSITION_SAME_LINE = ['position_after_functions_and_oop_constructs' => BracesFixer::LINE_SAME]; + private const CONFIGURATION_CTRL_STRUCT_POSITION_NEXT_LINE = ['position_after_control_structures' => BracesFixer::LINE_NEXT]; + private const CONFIGURATION_ANONYMOUS_POSITION_NEXT_LINE = ['position_after_anonymous_constructs' => BracesFixer::LINE_NEXT]; public function testInvalidConfigurationClassyConstructs(): void { @@ -208,7 +208,7 @@ public function bar( while (false); };', null, - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ 'next());', null, - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ 'getTest());', - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ 'getTest());', - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ 'c()}d"; }', - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ 'c()}d"; }', - self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE + self::CONFIGURATION_CTRL_STRUCT_POSITION_NEXT_LINE, ], [ '{$r}, $s->{$t}); $u->{$v}->w = 1; }', - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ '{$r}, $s->{$t}); $u->{$v}->w = 1; }', - self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE + self::CONFIGURATION_CTRL_STRUCT_POSITION_NEXT_LINE, ], [ '{"a{$c}d"}(); }', - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ '{"a{$c->{\'foo-bar\'}()}d"}(); }', - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ '{"a{$c->{\'foo-bar\'}()}d"}(); }', - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ 'x', 'x', - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ 'getFile()) { }', - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ 'getFile()) { }', - self::$configurationAnonymousPositionNextLine, + self::CONFIGURATION_ANONYMOUS_POSITION_NEXT_LINE, ], [ 'bar(), function ($o) { return $o->isBaz(); }); }, $collection));', - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ 'bar(), function ($o) { return $o->isBaz(); }); }, $collection));', - self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE + self::CONFIGURATION_ANONYMOUS_POSITION_NEXT_LINE, ], [ 'tesT ($test)) { }', - self::$configurationOopPositionSameLine, + self::CONFIGURATION_OOP_POSITION_SAME_LINE, ], [ 'createCasesFor('real'); } + /** + * @return iterable + */ private function createCasesFor(string $type): iterable { yield [ diff --git a/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php b/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php index 2c7740d5ba7..3da7a181bba 100644 --- a/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php +++ b/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php @@ -87,6 +87,9 @@ public function provideNoFixCases(): array return $cases; } + /** + * @return iterable + */ private function createCasesFor(string $from, string $to): iterable { yield [ diff --git a/tests/Fixer/ControlStructure/NoUselessElseFixerTest.php b/tests/Fixer/ControlStructure/NoUselessElseFixerTest.php index 86d925110c0..cb03210a407 100644 --- a/tests/Fixer/ControlStructure/NoUselessElseFixerTest.php +++ b/tests/Fixer/ControlStructure/NoUselessElseFixerTest.php @@ -938,6 +938,9 @@ public function provideIsInConditionWithoutBracesCases(): array ]; } + /** + * @return iterable + */ private function generateConditionsWithoutBracesCase(string $statement): iterable { $ifTemplate = '}> + */ private static function pairs(): iterable { yield 'handle equal sign' => [ diff --git a/tests/Test/TestCaseUtils.php b/tests/Test/TestCaseUtils.php index c95222bc312..201ee97d18f 100644 --- a/tests/Test/TestCaseUtils.php +++ b/tests/Test/TestCaseUtils.php @@ -19,6 +19,11 @@ */ final class TestCaseUtils { + /** + * @param iterable $cases + * + * @return iterable + */ public static function swapExpectedInputTestCases(iterable $cases): iterable { foreach ($cases as $case) { diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index f83136bb217..651b88ca920 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -32,6 +32,9 @@ final class UtilsTest extends TestCase { use ExpectDeprecationTrait; + /** + * @var null|false|string + */ private $originalValueOfFutureMode; protected function setUp(): void