diff --git a/phpstan.neon b/phpstan.neon index d2abe66078b..405b71ab3aa 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -21,28 +21,12 @@ parameters: # baseline, should only shrink - - message: '#^Method .+ has parameter .+ with no value type specified in iterable type array\.$#' + message: '#^.+no value type specified in iterable type.+\.$#' path: * - count: 363 - - - message: '#^Method .+ has parameter .+ with no value type specified in iterable type iterable\.$#' - path: * - count: 4 - - - message: '#^Method .+ return type has no value type specified in iterable type array\.$#' - path: * - count: 153 - - - message: '#^Method .+ return type has no value type specified in iterable type iterable\.$#' - path: * - count: 15 + count: 561 - message: '#^Property .+ has no type specified\.$#' path: * count: 7 - - - message: '#^Property .+ type has no value type specified in iterable type array\.$#' - path: * - count: 37 tipsOfTheDay: false tmpDir: dev-tools/phpstan/cache diff --git a/src/Console/Report/FixReport/JsonReporter.php b/src/Console/Report/FixReport/JsonReporter.php index 6bb05120c0e..4e170e4bce0 100644 --- a/src/Console/Report/FixReport/JsonReporter.php +++ b/src/Console/Report/FixReport/JsonReporter.php @@ -45,7 +45,7 @@ public function generate(ReportSummary $reportSummary): string $jsonFile['appliedFixers'] = $fixResult['appliedFixers']; } - if (!empty($fixResult['diff'])) { + if ('' !== $fixResult['diff']) { $jsonFile['diff'] = $fixResult['diff']; } diff --git a/src/Console/Report/FixReport/JunitReporter.php b/src/Console/Report/FixReport/JunitReporter.php index 1614f37ca94..9cf9c6df8ce 100644 --- a/src/Console/Report/FixReport/JunitReporter.php +++ b/src/Console/Report/FixReport/JunitReporter.php @@ -102,6 +102,9 @@ private function createFailedTestCases(\DOMDocument $dom, \DOMElement $testsuite $testsuite->setAttribute('errors', '0'); } + /** + * @param array{appliedFixers: list, diff: string} $fixResult + */ private function createFailedTestCase(\DOMDocument $dom, string $file, array $fixResult, bool $shouldAddAppliedFixers): \DOMElement { $appliedFixersCount = \count($fixResult['appliedFixers']); @@ -127,7 +130,7 @@ private function createFailedTestCase(\DOMDocument $dom, string $file, array $fi $failureContent = "Wrong code style\n"; } - if (!empty($fixResult['diff'])) { + if ('' !== $fixResult['diff']) { $failureContent .= "\nDiff:\n---------------\n\n".$fixResult['diff']; } diff --git a/src/Console/Report/FixReport/ReportSummary.php b/src/Console/Report/FixReport/ReportSummary.php index 3c48a0628e2..851d4cb3c26 100644 --- a/src/Console/Report/FixReport/ReportSummary.php +++ b/src/Console/Report/FixReport/ReportSummary.php @@ -21,6 +21,9 @@ */ final class ReportSummary { + /** + * @var array, diff: string}> + */ private array $changed; private int $time; @@ -34,8 +37,9 @@ final class ReportSummary private bool $isDecoratedOutput; /** - * @param int $time duration in milliseconds - * @param int $memory memory usage in bytes + * @param array, diff: string}> $changed + * @param int $time duration in milliseconds + * @param int $memory memory usage in bytes */ public function __construct( array $changed, @@ -63,6 +67,9 @@ public function isDryRun(): bool return $this->isDryRun; } + /** + * @return array, diff: string}> + */ public function getChanged(): array { return $this->changed; diff --git a/src/Console/Report/FixReport/ReporterFactory.php b/src/Console/Report/FixReport/ReporterFactory.php index 5ffcb5ad04b..d091f441c34 100644 --- a/src/Console/Report/FixReport/ReporterFactory.php +++ b/src/Console/Report/FixReport/ReporterFactory.php @@ -15,7 +15,6 @@ namespace PhpCsFixer\Console\Report\FixReport; use Symfony\Component\Finder\Finder as SymfonyFinder; -use Symfony\Component\Finder\SplFileInfo; /** * @author Boris Gorbylev @@ -25,19 +24,18 @@ final class ReporterFactory { /** - * @var ReporterInterface[] + * @var array */ private array $reporters = []; public function registerBuiltInReporters(): self { - /** @var null|string[] $builtInReporters */ + /** @var null|list $builtInReporters */ static $builtInReporters; if (null === $builtInReporters) { $builtInReporters = []; - /** @var SplFileInfo $file */ foreach (SymfonyFinder::create()->files()->name('*Reporter.php')->in(__DIR__) as $file) { $relativeNamespace = $file->getRelativePath(); $builtInReporters[] = sprintf( @@ -73,7 +71,7 @@ public function registerReporter(ReporterInterface $reporter): self } /** - * @return string[] + * @return list */ public function getFormats(): array { diff --git a/src/Console/Report/FixReport/TextReporter.php b/src/Console/Report/FixReport/TextReporter.php index 19525bc9312..35b479a9c54 100644 --- a/src/Console/Report/FixReport/TextReporter.php +++ b/src/Console/Report/FixReport/TextReporter.php @@ -44,27 +44,33 @@ public function generate(ReportSummary $reportSummary): string $output .= sprintf('%4d) %s', $i, $file); if ($reportSummary->shouldAddAppliedFixers()) { - $output .= $this->getAppliedFixers($reportSummary->isDecoratedOutput(), $fixResult); + $output .= $this->getAppliedFixers( + $reportSummary->isDecoratedOutput(), + $fixResult['appliedFixers'], + ); } - $output .= $this->getDiff($reportSummary->isDecoratedOutput(), $fixResult); + $output .= $this->getDiff($reportSummary->isDecoratedOutput(), $fixResult['diff']); $output .= PHP_EOL; } return $output.$this->getFooter($reportSummary->getTime(), $reportSummary->getMemory(), $reportSummary->isDryRun()); } - private function getAppliedFixers(bool $isDecoratedOutput, array $fixResult): string + /** + * @param list $appliedFixers + */ + private function getAppliedFixers(bool $isDecoratedOutput, array $appliedFixers): string { return sprintf( $isDecoratedOutput ? ' (%s)' : ' (%s)', - implode(', ', $fixResult['appliedFixers']) + implode(', ', $appliedFixers) ); } - private function getDiff(bool $isDecoratedOutput, array $fixResult): string + private function getDiff(bool $isDecoratedOutput, string $diff): string { - if (empty($fixResult['diff'])) { + if ('' === $diff) { return ''; } @@ -74,7 +80,7 @@ private function getDiff(bool $isDecoratedOutput, array $fixResult): string PHP_EOL )); - return PHP_EOL.$diffFormatter->format($fixResult['diff']).PHP_EOL; + return PHP_EOL.$diffFormatter->format($diff).PHP_EOL; } private function getFooter(int $time, int $memory, bool $isDryRun): string diff --git a/src/Console/Report/FixReport/XmlReporter.php b/src/Console/Report/FixReport/XmlReporter.php index 16edd379003..d487a189b96 100644 --- a/src/Console/Report/FixReport/XmlReporter.php +++ b/src/Console/Report/FixReport/XmlReporter.php @@ -56,11 +56,13 @@ public function generate(ReportSummary $reportSummary): string $filesXML->appendChild($fileXML); if ($reportSummary->shouldAddAppliedFixers()) { - $fileXML->appendChild($this->createAppliedFixersElement($dom, $fixResult)); + $fileXML->appendChild( + $this->createAppliedFixersElement($dom, $fixResult['appliedFixers']), + ); } - if (!empty($fixResult['diff'])) { - $fileXML->appendChild($this->createDiffElement($dom, $fixResult)); + if ('' !== $fixResult['diff']) { + $fileXML->appendChild($this->createDiffElement($dom, $fixResult['diff'])); } } @@ -77,11 +79,14 @@ public function generate(ReportSummary $reportSummary): string return $reportSummary->isDecoratedOutput() ? OutputFormatter::escape($dom->saveXML()) : $dom->saveXML(); } - private function createAppliedFixersElement(\DOMDocument $dom, array $fixResult): \DOMElement + /** + * @param list $appliedFixers + */ + private function createAppliedFixersElement(\DOMDocument $dom, array $appliedFixers): \DOMElement { $appliedFixersXML = $dom->createElement('applied_fixers'); - foreach ($fixResult['appliedFixers'] as $appliedFixer) { + foreach ($appliedFixers as $appliedFixer) { $appliedFixerXML = $dom->createElement('applied_fixer'); $appliedFixerXML->setAttribute('name', $appliedFixer); $appliedFixersXML->appendChild($appliedFixerXML); @@ -90,10 +95,10 @@ private function createAppliedFixersElement(\DOMDocument $dom, array $fixResult) return $appliedFixersXML; } - private function createDiffElement(\DOMDocument $dom, array $fixResult): \DOMElement + private function createDiffElement(\DOMDocument $dom, string $diff): \DOMElement { $diffXML = $dom->createElement('diff'); - $diffXML->appendChild($dom->createCDATASection($fixResult['diff'])); + $diffXML->appendChild($dom->createCDATASection($diff)); return $diffXML; } diff --git a/src/Console/Report/ListSetsReport/ReportSummary.php b/src/Console/Report/ListSetsReport/ReportSummary.php index 6ca98d9a41e..c7d66e71515 100644 --- a/src/Console/Report/ListSetsReport/ReportSummary.php +++ b/src/Console/Report/ListSetsReport/ReportSummary.php @@ -24,12 +24,12 @@ final class ReportSummary { /** - * @var RuleSetDescriptionInterface[] + * @var list */ private array $sets; /** - * @param RuleSetDescriptionInterface[] $sets + * @param list $sets */ public function __construct(array $sets) { @@ -37,7 +37,7 @@ public function __construct(array $sets) } /** - * @return RuleSetDescriptionInterface[] + * @return list */ public function getSets(): array { diff --git a/src/Console/Report/ListSetsReport/ReporterFactory.php b/src/Console/Report/ListSetsReport/ReporterFactory.php index abf211e9544..cbbb7f4e8d5 100644 --- a/src/Console/Report/ListSetsReport/ReporterFactory.php +++ b/src/Console/Report/ListSetsReport/ReporterFactory.php @@ -15,7 +15,6 @@ namespace PhpCsFixer\Console\Report\ListSetsReport; use Symfony\Component\Finder\Finder as SymfonyFinder; -use Symfony\Component\Finder\SplFileInfo; /** * @author Boris Gorbylev @@ -25,19 +24,18 @@ final class ReporterFactory { /** - * @var ReporterInterface[] + * @var array */ private array $reporters = []; public function registerBuiltInReporters(): self { - /** @var null|string[] $builtInReporters */ + /** @var null|list $builtInReporters */ static $builtInReporters; if (null === $builtInReporters) { $builtInReporters = []; - /** @var SplFileInfo $file */ foreach (SymfonyFinder::create()->files()->name('*Reporter.php')->in(__DIR__) as $file) { $relativeNamespace = $file->getRelativePath(); $builtInReporters[] = sprintf( @@ -70,7 +68,7 @@ public function registerReporter(ReporterInterface $reporter): self } /** - * @return string[] + * @return list */ public function getFormats(): array { diff --git a/src/Runner/FileCachingLintingIterator.php b/src/Runner/FileCachingLintingIterator.php index 261ed56913a..c07dbbd27e3 100644 --- a/src/Runner/FileCachingLintingIterator.php +++ b/src/Runner/FileCachingLintingIterator.php @@ -21,6 +21,8 @@ * @author Dariusz Rumiński * * @internal + * + * @extends \CachingIterator> */ final class FileCachingLintingIterator extends \CachingIterator { @@ -36,6 +38,9 @@ final class FileCachingLintingIterator extends \CachingIterator */ private $nextResult; + /** + * @param \Iterator $iterator + */ public function __construct(\Iterator $iterator, LinterInterface $linter) { parent::__construct($iterator); diff --git a/src/Runner/FileFilterIterator.php b/src/Runner/FileFilterIterator.php index cf61029b324..c0f736fda5d 100644 --- a/src/Runner/FileFilterIterator.php +++ b/src/Runner/FileFilterIterator.php @@ -24,6 +24,8 @@ * @author Dariusz Rumiński * * @internal + * + * @extends \FilterIterator> */ final class FileFilterIterator extends \FilterIterator { @@ -32,7 +34,7 @@ final class FileFilterIterator extends \FilterIterator private CacheManagerInterface $cacheManager; /** - * @var array + * @var array */ private array $visitedElements = []; diff --git a/src/Runner/FileLintingIterator.php b/src/Runner/FileLintingIterator.php index 9c959372c32..09f5913e30b 100644 --- a/src/Runner/FileLintingIterator.php +++ b/src/Runner/FileLintingIterator.php @@ -33,6 +33,9 @@ final class FileLintingIterator extends \IteratorIterator private LinterInterface $linter; + /** + * @param \Iterator $iterator + */ public function __construct(\Iterator $iterator, LinterInterface $linter) { parent::__construct($iterator); diff --git a/src/Runner/Runner.php b/src/Runner/Runner.php index 472c864e88d..f25dc0ddb6c 100644 --- a/src/Runner/Runner.php +++ b/src/Runner/Runner.php @@ -57,7 +57,7 @@ final class Runner private $finder; /** - * @var FixerInterface[] + * @var list */ private array $fixers; @@ -65,6 +65,7 @@ final class Runner /** * @param \Traversable<\SplFileInfo> $finder + * @param list $fixers */ public function __construct( $finder, @@ -90,6 +91,9 @@ public function __construct( $this->stopOnViolation = $stopOnViolation; } + /** + * @return array, diff: string}> + */ public function fix(): array { $changed = []; @@ -106,7 +110,6 @@ public function fix(): array ? new FileCachingLintingIterator($fileFilteredFileIterator, $this->linter) : new FileLintingIterator($fileFilteredFileIterator, $this->linter); - /** @var \SplFileInfo $file */ foreach ($collection as $file) { $fixInfo = $this->fixFile($file, $collection->currentLintingResult()); @@ -126,6 +129,9 @@ public function fix(): array return $changed; } + /** + * @return null|array{appliedFixers: list, diff: string} + */ private function fixFile(\SplFileInfo $file, LintingResultInterface $lintingResult): ?array { $name = $file->getPathname(); diff --git a/tests/Console/Report/FixReport/AbstractReporterTestCase.php b/tests/Console/Report/FixReport/AbstractReporterTestCase.php index 898aee2b617..57371cd38e5 100644 --- a/tests/Console/Report/FixReport/AbstractReporterTestCase.php +++ b/tests/Console/Report/FixReport/AbstractReporterTestCase.php @@ -82,6 +82,7 @@ final public function provideGenerateCases(): array [ 'someFile.php' => [ 'appliedFixers' => ['some_fixer_name_here'], + 'diff' => '', ], ], 0, @@ -113,6 +114,7 @@ final public function provideGenerateCases(): array [ 'someFile.php' => [ 'appliedFixers' => ['some_fixer_name_here_1', 'some_fixer_name_here_2'], + 'diff' => '', ], ], 0, @@ -128,6 +130,7 @@ final public function provideGenerateCases(): array [ 'someFile.php' => [ 'appliedFixers' => ['some_fixer_name_here'], + 'diff' => '', ], ], 1234, diff --git a/tests/Console/Report/FixReport/ReportSummaryTest.php b/tests/Console/Report/FixReport/ReportSummaryTest.php index 4280e09c0ce..f72ccccdcc2 100644 --- a/tests/Console/Report/FixReport/ReportSummaryTest.php +++ b/tests/Console/Report/FixReport/ReportSummaryTest.php @@ -26,7 +26,12 @@ final class ReportSummaryTest extends TestCase { public function testReportSummary(): void { - $changed = ['', 5]; + $changed = [ + 'someFile.php' => [ + 'appliedFixers' => ['some_fixer_name_here'], + 'diff' => 'this text is a diff ;)', + ], + ]; $time = time(); $memory = 123456789; $addAppliedFixers = true;