From f5d8133dd33bc8896707fb597dc540005e43a2fd Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 21 Feb 2021 01:21:45 +0100 Subject: [PATCH] [Cleaning] Get rid of nullable parameters (#2977) Co-authored-by: kaizen-ci --- .gitattributes | 3 + composer.json | 2 +- .../ParamTypeDocBlockResolverTest.php | 17 ++++- .../ChangelogLinkerApplication.php | 2 +- .../src/ChangeTree/ChangeFactory.php | 6 +- .../src/ChangeTree/ChangeResolver.php | 2 +- .../src/ChangeTree/ChangeSorter.php | 15 +--- .../changelog-linker/src/ChangelogDumper.php | 16 ++--- .../src/Console/Command/DumpMergesCommand.php | 2 +- .../src/Console/Input/PriorityResolver.php | 11 +-- .../changelog-linker/src/Github/GithubApi.php | 8 +-- .../ValueObject/PackageCategoryPriority.php | 23 ++++++ .../tests/ChangeTree/ChangeSorterTest.php | 5 +- .../ChangeTree/ChangeSorterTogetherTest.php | 13 ++-- .../tests/ChangelogDumper/WithTagsTest.php | 7 +- .../Git/GitCommitDateTagResolverTest.php | 17 ++++- .../SuperfluousReturnNameMalformWorker.php | 20 ++++-- packages/easy-coding-standard/bin/ecs.php | 70 ++----------------- .../configuration/src/Configuration.php | 18 ----- .../src/Bootstrap/ConfigShifter.php | 35 ---------- .../src/Bootstrap/ECSConfigsResolver.php | 45 ++++++++++++ .../EasyCodingStandardConsoleApplication.php | 18 +---- .../Console/Output/JsonOutputFormatter.php | 13 +--- .../ECSContainerFactory.php | 49 +++++++++++++ packages/git-wrapper/src/GitWrapper.php | 2 +- .../DependencyInjection/DefinitionFinder.php | 9 +-- .../Reflection/ClassLikeExistenceChecker.php | 38 ++++++++++ .../src/ExprResolver/StringExprResolver.php | 2 +- .../src/Printer/SmartPhpConfigPrinter.php | 22 +++--- .../config/configurable-rules.neon | 3 - .../config/services/services.neon | 1 + .../ComplexityAffectingNodeFinder.php | 3 +- .../NodeAnalyzer/DependencyNodeAnalyzer.php | 4 +- .../NodeAnalyzer/Nette/NetteTypeAnalyzer.php | 3 +- .../NodeAnalyzer/PreviouslyUsedAnalyzer.php | 3 +- .../src/NodeAnalyzer/ProtectedAnalyzer.php | 4 +- .../ParentGuard/ParentClassMethodGuard.php | 51 ++++++++++++++ .../src/Rules/ForbiddenAssignInLoopRule.php | 3 +- ...rbiddenMethodOrStaticCallInForeachRule.php | 3 +- .../ForbiddenMethodOrStaticCallInIfRule.php | 34 ++++----- .../Rules/ForbiddenNullableParameterRule.php | 47 +++++++++++-- .../src/Rules/ForbiddenParentClassRule.php | 68 ++++++++++-------- .../src/Rules/ForbiddenThisArgumentRule.php | 4 +- .../src/Rules/NoArrayAccessOnObjectRule.php | 7 +- ...sWithStaticMethodWithoutStaticNameRule.php | 8 +-- .../src/Rules/NoStaticPropertyRule.php | 6 +- .../Rules/PreventDuplicateClassMethodRule.php | 2 +- .../DefaultConfigurationTest.php | 37 ++++++++++ .../Fixture/MethodWithNullableScalar.php | 12 ++++ .../Fixture/SkipParentContract.php | 14 ++++ .../ParentContractNullableInterface.php | 10 +++ .../config/default_configuration.neon | 7 ++ ...stractClassInheritingFromUnwantedClass.php | 11 --- .../ForbiddenParentClassRuleTest.php | 7 -- .../src/AbstractConfigResolver.php | 15 +--- .../Bootstrap/BootstrapConfigs.php | 47 +++++++++++++ .../SetAwareConfigResolverTest.php | 22 ++++-- .../src/Normalizer/PathNormalizer.php | 15 ++-- .../src/Controller/ControllerDumper.php | 40 +++++------ phpstan.neon | 19 +++++ rector.php | 8 --- 61 files changed, 631 insertions(+), 377 deletions(-) create mode 100644 packages/changelog-linker/src/ValueObject/PackageCategoryPriority.php delete mode 100644 packages/easy-coding-standard/src/Bootstrap/ConfigShifter.php create mode 100644 packages/easy-coding-standard/src/Bootstrap/ECSConfigsResolver.php create mode 100644 packages/easy-coding-standard/src/DependencyInjection/ECSContainerFactory.php create mode 100644 packages/phpstan-rules/src/ParentGuard/ParentClassMethodGuard.php create mode 100644 packages/phpstan-rules/tests/Rules/ForbiddenNullableParameterRule/DefaultConfigurationTest.php create mode 100644 packages/phpstan-rules/tests/Rules/ForbiddenNullableParameterRule/Fixture/MethodWithNullableScalar.php create mode 100644 packages/phpstan-rules/tests/Rules/ForbiddenNullableParameterRule/Fixture/SkipParentContract.php create mode 100644 packages/phpstan-rules/tests/Rules/ForbiddenNullableParameterRule/Source/ParentContractNullableInterface.php create mode 100644 packages/phpstan-rules/tests/Rules/ForbiddenNullableParameterRule/config/default_configuration.neon delete mode 100644 packages/phpstan-rules/tests/Rules/ForbiddenParentClassRule/Fixture/SkipAbstractClassInheritingFromUnwantedClass.php create mode 100644 packages/set-config-resolver/src/ValueObject/Bootstrap/BootstrapConfigs.php diff --git a/.gitattributes b/.gitattributes index 11b140c8a3..505cb2d1ac 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15,3 +15,6 @@ packages/*/docs/ export-ignore # highlight neon files as yaml *.neon linguist-language=YAML + +# for git-wrapper +packages/git-wrapper/tests/build/* diff --git a/composer.json b/composer.json index ae225ebcfc..3a1612b5d2 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ "nette/forms": "^3.1", "ondram/ci-detector": "^3.5", "psr/log": "^1.1", - "rector/rector": "^0.9.26", + "rector/rector": "^0.9.30", "symfony/doctrine-bridge": "^4.4|^5.2", "symfony/framework-bundle": "^4.4|^5.2", "symfony/security-bundle": "^4.4|^5.2", diff --git a/packages/autowire-array-parameter/tests/DocBlock/ParamTypeDocBlockResolverTest.php b/packages/autowire-array-parameter/tests/DocBlock/ParamTypeDocBlockResolverTest.php index fca5d0f1f2..32ec257e54 100644 --- a/packages/autowire-array-parameter/tests/DocBlock/ParamTypeDocBlockResolverTest.php +++ b/packages/autowire-array-parameter/tests/DocBlock/ParamTypeDocBlockResolverTest.php @@ -23,7 +23,7 @@ protected function setUp(): void /** * @dataProvider provideData() */ - public function test(string $docBlock, string $parameterName, ?string $expectedType): void + public function test(string $docBlock, string $parameterName, string $expectedType): void { $resolvedType = $this->paramTypeDocBlockResolver->resolve($docBlock, $parameterName); $this->assertSame($expectedType, $resolvedType); @@ -32,8 +32,21 @@ public function test(string $docBlock, string $parameterName, ?string $expectedT public function provideData(): Iterator { yield ['/** @param Type[] $name */', 'name', 'Type']; - yield ['/** @param Type[] $name */', '___not', null]; yield ['/** @param array $name */', 'name', 'Type']; yield ['/** @param iterable $name */', 'name', 'Type']; } + + /** + * @dataProvider provideDataMissmatchName() + */ + public function testMissmatchName(string $docBlock, string $parameterName): void + { + $resolvedType = $this->paramTypeDocBlockResolver->resolve($docBlock, $parameterName); + $this->assertNull($resolvedType); + } + + public function provideDataMissmatchName(): Iterator + { + yield ['/** @param Type[] $name */', '___not']; + } } diff --git a/packages/changelog-linker/src/Application/ChangelogLinkerApplication.php b/packages/changelog-linker/src/Application/ChangelogLinkerApplication.php index dff1e75956..79e03309d8 100644 --- a/packages/changelog-linker/src/Application/ChangelogLinkerApplication.php +++ b/packages/changelog-linker/src/Application/ChangelogLinkerApplication.php @@ -37,7 +37,7 @@ public function __construct( public function createContentFromPullRequestsBySortPriority( array $pullRequests, - ?string $sortPriority, + string $sortPriority, bool $inCategories, bool $inPackages ): string { diff --git a/packages/changelog-linker/src/ChangeTree/ChangeFactory.php b/packages/changelog-linker/src/ChangeTree/ChangeFactory.php index 3c89905391..8a75c85078 100644 --- a/packages/changelog-linker/src/ChangeTree/ChangeFactory.php +++ b/packages/changelog-linker/src/ChangeTree/ChangeFactory.php @@ -10,6 +10,8 @@ use Symplify\ChangelogLinker\Git\GitCommitDateTagResolver; use Symplify\ChangelogLinker\ValueObject\ChangeTree\Change; use Symplify\ChangelogLinker\ValueObject\Option; +use Symplify\ChangelogLinker\ValueObject\PackageName; +use Symplify\MonorepoBuilder\ValueObject\Package; use Symplify\PackageBuilder\Parameter\ParameterProvider; /** @@ -91,9 +93,9 @@ private function escapeMarkdown(string $content): string return Strings::replace($content, self::ASTERISK_REGEX, '\\\$1'); } - private function resolveMessageWithoutPackage(string $message, ?string $package): string + private function resolveMessageWithoutPackage(string $message, string $package): string { - if ($package === null) { + if ($package === PackageName::UNKNOWN) { return $message; } diff --git a/packages/changelog-linker/src/ChangeTree/ChangeResolver.php b/packages/changelog-linker/src/ChangeTree/ChangeResolver.php index dc7dbd3c18..cf256c9b3b 100644 --- a/packages/changelog-linker/src/ChangeTree/ChangeResolver.php +++ b/packages/changelog-linker/src/ChangeTree/ChangeResolver.php @@ -32,7 +32,7 @@ public function __construct(ChangeFactory $changeFactory, ChangeSorter $changeSo */ public function resolveSortedChangesFromPullRequestsWithSortPriority( array $pullRequests, - ?string $sortPriority + string $sortPriority ): array { $changes = []; diff --git a/packages/changelog-linker/src/ChangeTree/ChangeSorter.php b/packages/changelog-linker/src/ChangeTree/ChangeSorter.php index dc529d7856..985f5b30f1 100644 --- a/packages/changelog-linker/src/ChangeTree/ChangeSorter.php +++ b/packages/changelog-linker/src/ChangeTree/ChangeSorter.php @@ -5,22 +5,13 @@ namespace Symplify\ChangelogLinker\ChangeTree; use Symplify\ChangelogLinker\ValueObject\ChangeTree\Change; +use Symplify\ChangelogLinker\ValueObject\PackageCategoryPriority; /** * @see \Symplify\ChangelogLinker\Tests\ChangeTree\ChangeSorterTest */ final class ChangeSorter { - /** - * @var string - */ - public const PRIORITY_PACKAGES = 'packages'; - - /** - * @var string - */ - public const PRIORITY_CATEGORIES = 'categories'; - /** * Inspiration: https://stackoverflow.com/a/8598241/1348344 * @@ -29,7 +20,7 @@ final class ChangeSorter * @param Change[] $changes * @return Change[] */ - public function sort(array $changes, ?string $priority): array + public function sort(array $changes, string $priority): array { // pur newer versions to the top, and "Unreleased" first usort($changes, function (Change $firstChange, Change $secondChange) use ($priority): int { @@ -38,7 +29,7 @@ public function sort(array $changes, ?string $priority): array return $comparisonStatus; } - if ($priority === self::PRIORITY_PACKAGES) { + if ($priority === PackageCategoryPriority::PACKAGES) { return $this->comparePackagesOverCategories($firstChange, $secondChange); } diff --git a/packages/changelog-linker/src/ChangelogDumper.php b/packages/changelog-linker/src/ChangelogDumper.php index 901818c9a7..1083355f93 100644 --- a/packages/changelog-linker/src/ChangelogDumper.php +++ b/packages/changelog-linker/src/ChangelogDumper.php @@ -4,9 +4,9 @@ namespace Symplify\ChangelogLinker; -use Symplify\ChangelogLinker\ChangeTree\ChangeSorter; use Symplify\ChangelogLinker\Git\GitCommitDateTagResolver; use Symplify\ChangelogLinker\ValueObject\ChangeTree\Change; +use Symplify\ChangelogLinker\ValueObject\PackageCategoryPriority; /** * @see \Symplify\ChangelogLinker\Tests\ChangelogDumper\ChangelogDumperTest @@ -58,7 +58,7 @@ public function reportChangesWithHeadlines( array $changes, bool $withCategories, bool $withPackages, - ?string $priority + string $priority ): string { $this->content .= PHP_EOL; @@ -77,12 +77,12 @@ public function reportChangesWithHeadlines( private function displayHeadlines( bool $withCategories, bool $withPackages, - ?string $priority, + string $priority, Change $change ): void { $this->displayTag($change); - if ($priority === ChangeSorter::PRIORITY_PACKAGES) { + if ($priority === PackageCategoryPriority::PACKAGES) { $this->displayPackageIfDesired($change, $withPackages, $priority); $this->displayCategoryIfDesired($change, $withCategories, $priority); } else { @@ -101,7 +101,7 @@ private function displayTag(Change $change): void $this->previousTag = $change->getTag(); } - private function displayPackageIfDesired(Change $change, bool $withPackages, ?string $priority): void + private function displayPackageIfDesired(Change $change, bool $withPackages, string $priority): void { if (! $withPackages) { return; @@ -109,12 +109,12 @@ private function displayPackageIfDesired(Change $change, bool $withPackages, ?st if ($this->previousPackage === $change->getPackage()) { return; } - $headlineLevel = $priority === ChangeSorter::PRIORITY_CATEGORIES ? 4 : 3; + $headlineLevel = $priority === PackageCategoryPriority::CATEGORIES ? 4 : 3; $this->content .= str_repeat('#', $headlineLevel) . ' ' . $change->getPackage() . PHP_EOL; $this->previousPackage = $change->getPackage(); } - private function displayCategoryIfDesired(Change $change, bool $withCategories, ?string $priority): void + private function displayCategoryIfDesired(Change $change, bool $withCategories, string $priority): void { if (! $withCategories) { return; @@ -122,7 +122,7 @@ private function displayCategoryIfDesired(Change $change, bool $withCategories, if ($this->previousCategory === $change->getCategory()) { return; } - $headlineLevel = $priority === ChangeSorter::PRIORITY_PACKAGES ? 4 : 3; + $headlineLevel = $priority === PackageCategoryPriority::PACKAGES ? 4 : 3; $this->content .= str_repeat('#', $headlineLevel) . ' ' . $change->getCategory() . PHP_EOL; $this->previousCategory = $change->getCategory(); } diff --git a/packages/changelog-linker/src/Console/Command/DumpMergesCommand.php b/packages/changelog-linker/src/Console/Command/DumpMergesCommand.php index df9e31f64a..a2ef8d15df 100644 --- a/packages/changelog-linker/src/Console/Command/DumpMergesCommand.php +++ b/packages/changelog-linker/src/Console/Command/DumpMergesCommand.php @@ -126,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $sinceId = $this->highestMergedIdResolver->resolveFromInputAndChangelogContent($input, $content); /** @var string $baseBranch */ - $baseBranch = $input->getOption(Option::BASE_BRANCH); + $baseBranch = (string) $input->getOption(Option::BASE_BRANCH); $pullRequests = $this->githubApi->getMergedPullRequestsSinceId($sinceId, $baseBranch); if ($pullRequests === []) { diff --git a/packages/changelog-linker/src/Console/Input/PriorityResolver.php b/packages/changelog-linker/src/Console/Input/PriorityResolver.php index 06f40a4c3e..c62dee5879 100644 --- a/packages/changelog-linker/src/Console/Input/PriorityResolver.php +++ b/packages/changelog-linker/src/Console/Input/PriorityResolver.php @@ -6,6 +6,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symplify\ChangelogLinker\ValueObject\Option; +use Symplify\ChangelogLinker\ValueObject\PackageCategoryPriority; use Symplify\PackageBuilder\Reflection\PrivatesAccessor; final class PriorityResolver @@ -24,7 +25,7 @@ public function __construct() * Detects the order in which "--in-packages" and "--in-categories" are both called. * The first has a priority. */ - public function resolveFromInput(InputInterface $input): ?string + public function resolveFromInput(InputInterface $input): string { $rawOptions = $this->privatesAccessor->getPrivateProperty($input, 'options'); @@ -34,17 +35,17 @@ public function resolveFromInput(InputInterface $input): ?string $usedOptions = array_intersect($requiredOptions, $optionNames); if (count($usedOptions) !== count($requiredOptions)) { - return null; + return PackageCategoryPriority::NONE; } foreach ($optionNames as $optionName) { if ($optionName === Option::IN_PACKAGES) { - return 'packages'; + return PackageCategoryPriority::PACKAGES; } - return 'categories'; + return PackageCategoryPriority::CATEGORIES; } - return null; + return PackageCategoryPriority::NONE; } } diff --git a/packages/changelog-linker/src/Github/GithubApi.php b/packages/changelog-linker/src/Github/GithubApi.php index 77ea297cc2..54508faf26 100644 --- a/packages/changelog-linker/src/Github/GithubApi.php +++ b/packages/changelog-linker/src/Github/GithubApi.php @@ -84,7 +84,7 @@ public function __construct( /** * @return mixed[] */ - public function getMergedPullRequestsSinceId(int $id, ?string $baseBranch = null): array + public function getMergedPullRequestsSinceId(int $id, string $baseBranch): array { $pullRequests = $this->getPullRequestsSinceId($id, $baseBranch); @@ -113,15 +113,13 @@ public function isPullRequestMergedToBaseBranch(int $pullRequestId, string $base /** * @return mixed[] */ - private function getPullRequestsSinceId(int $id, ?string $baseBranch = null): array + private function getPullRequestsSinceId(int $id, string $baseBranch): array { $pullRequests = []; for ($i = 1; $i <= self::MAX_PAGE; ++$i) { $url = sprintf(self::URL_CLOSED_PULL_REQUESTS, $this->repositoryName) . '&page=' . $i; - if ($baseBranch !== null) { - $url .= '&base=' . $baseBranch; - } + $url .= '&base=' . $baseBranch; $response = $this->getResponseToUrl($url); // already no more pages → stop diff --git a/packages/changelog-linker/src/ValueObject/PackageCategoryPriority.php b/packages/changelog-linker/src/ValueObject/PackageCategoryPriority.php new file mode 100644 index 0000000000..db83b25ce9 --- /dev/null +++ b/packages/changelog-linker/src/ValueObject/PackageCategoryPriority.php @@ -0,0 +1,23 @@ +createChanges(); - $sortedChanges = $this->changeSorter->sort($changes, ChangeSorter::PRIORITY_CATEGORIES); + $sortedChanges = $this->changeSorter->sort($changes, PackageCategoryPriority::CATEGORIES); $this->assertNotSame($changes, $sortedChanges); /** @var Change $firstChange */ @@ -42,7 +43,7 @@ public function testSortWithPackagePriority(): void { $changes = $this->createChanges(); - $sortedChanges = $this->changeSorter->sort($changes, ChangeSorter::PRIORITY_PACKAGES); + $sortedChanges = $this->changeSorter->sort($changes, PackageCategoryPriority::PACKAGES); $this->assertNotSame($changes, $sortedChanges); /** @var Change $firstChange */ diff --git a/packages/changelog-linker/tests/ChangeTree/ChangeSorterTogetherTest.php b/packages/changelog-linker/tests/ChangeTree/ChangeSorterTogetherTest.php index 17c60eb005..5c57f0622d 100644 --- a/packages/changelog-linker/tests/ChangeTree/ChangeSorterTogetherTest.php +++ b/packages/changelog-linker/tests/ChangeTree/ChangeSorterTogetherTest.php @@ -7,6 +7,7 @@ use Iterator; use PHPUnit\Framework\TestCase; use Symplify\ChangelogLinker\ChangeTree\ChangeSorter; +use Symplify\ChangelogLinker\ValueObject\PackageCategoryPriority; final class ChangeSorterTogetherTest extends TestCase { @@ -30,7 +31,7 @@ protected function setUp(): void * Tags should keep the same order for whatever priority * @dataProvider provideDataForTags() */ - public function testTags(?string $priority): void + public function testTags(string $priority): void { $changes = $this->dummyChangesFactory->create(); $sortedChanges = $this->changeSorter->sort($changes, $priority); @@ -53,16 +54,16 @@ public function testTags(?string $priority): void public function provideDataForTags(): Iterator { - yield [ChangeSorter::PRIORITY_CATEGORIES]; - yield [ChangeSorter::PRIORITY_PACKAGES]; - yield [null]; + yield [PackageCategoryPriority::CATEGORIES]; + yield [PackageCategoryPriority::PACKAGES]; + yield [PackageCategoryPriority::NONE]; } public function testSortWithCategoryPriority(): void { $changes = $this->dummyChangesFactory->create(); - $sortedChanges = $this->changeSorter->sort($changes, ChangeSorter::PRIORITY_CATEGORIES); + $sortedChanges = $this->changeSorter->sort($changes, PackageCategoryPriority::CATEGORIES); $categoriesByTags = []; foreach ($sortedChanges as $sortedChange) { @@ -117,7 +118,7 @@ public function testSortWithCategoryPriority(): void public function testSortWithPackagePriority(): void { $changes = $this->dummyChangesFactory->create(); - $sortedChanges = $this->changeSorter->sort($changes, ChangeSorter::PRIORITY_PACKAGES); + $sortedChanges = $this->changeSorter->sort($changes, PackageCategoryPriority::PACKAGES); $packagesByTags = []; foreach ($sortedChanges as $sortedChange) { diff --git a/packages/changelog-linker/tests/ChangelogDumper/WithTagsTest.php b/packages/changelog-linker/tests/ChangelogDumper/WithTagsTest.php index d52fe60aa2..22d4a3ae2d 100644 --- a/packages/changelog-linker/tests/ChangelogDumper/WithTagsTest.php +++ b/packages/changelog-linker/tests/ChangelogDumper/WithTagsTest.php @@ -8,6 +8,7 @@ use Symplify\ChangelogLinker\ChangelogDumper; use Symplify\ChangelogLinker\HttpKernel\ChangelogLinkerKernel; use Symplify\ChangelogLinker\ValueObject\ChangeTree\Change; +use Symplify\ChangelogLinker\ValueObject\PackageCategoryPriority; use Symplify\PackageBuilder\Testing\AbstractKernelTestCase; final class WithTagsTest extends AbstractKernelTestCase @@ -46,7 +47,7 @@ public function testReportChanges(): void public function testReportBothWithCategoriesPriority( bool $withCategories, bool $withPackages, - ?string $priority, + string $priority, string $expectedOutputFile ): void { $this->markTestSkipped('Random false positives on Github Actions'); @@ -63,7 +64,7 @@ public function testReportBothWithCategoriesPriority( public function provideDataForReportChangesWithHeadlines(): Iterator { - yield [true, false, null, __DIR__ . '/WithTagsSource/expected2.md']; - yield [false, true, null, __DIR__ . '/WithTagsSource/expected3.md']; + yield [true, false, PackageCategoryPriority::NONE, __DIR__ . '/WithTagsSource/expected2.md']; + yield [false, true, PackageCategoryPriority::NONE, __DIR__ . '/WithTagsSource/expected3.md']; } } diff --git a/packages/changelog-linker/tests/Git/GitCommitDateTagResolverTest.php b/packages/changelog-linker/tests/Git/GitCommitDateTagResolverTest.php index 81152f407b..f200a8acf1 100644 --- a/packages/changelog-linker/tests/Git/GitCommitDateTagResolverTest.php +++ b/packages/changelog-linker/tests/Git/GitCommitDateTagResolverTest.php @@ -44,7 +44,7 @@ public function provideData(): Iterator /** * @dataProvider provideDataResolveDateForTag() */ - public function testResolveDateForTag(string $tag, ?string $expectedDate): void + public function testResolveDateForTag(string $tag, string $expectedDate): void { $resvoledDate = $this->gitCommitDateTagResolver->resolveDateForTag($tag); $this->assertSame($expectedDate, $resvoledDate); @@ -54,6 +54,19 @@ public function provideDataResolveDateForTag(): Iterator { yield ['v4.4.1', '2018-06-07']; yield ['v4.4.2', '2018-06-10']; - yield ['Unreleased', null]; + } + + /** + * @dataProvider provideDataResolveDateForUnknownTag() + */ + public function testResolveDateForUnknownTag(string $tag): void + { + $resvoledDate = $this->gitCommitDateTagResolver->resolveDateForTag($tag); + $this->assertNull($resvoledDate); + } + + public function provideDataResolveDateForUnknownTag(): Iterator + { + yield ['Unreleased']; } } diff --git a/packages/coding-standard/src/TokenRunner/DocBlock/MalformWorker/SuperfluousReturnNameMalformWorker.php b/packages/coding-standard/src/TokenRunner/DocBlock/MalformWorker/SuperfluousReturnNameMalformWorker.php index 7a8984bc23..4c697aaa87 100644 --- a/packages/coding-standard/src/TokenRunner/DocBlock/MalformWorker/SuperfluousReturnNameMalformWorker.php +++ b/packages/coding-standard/src/TokenRunner/DocBlock/MalformWorker/SuperfluousReturnNameMalformWorker.php @@ -14,7 +14,7 @@ final class SuperfluousReturnNameMalformWorker extends AbstractMalformWorker * @var string * @see https://regex101.com/r/26Wy7Y/1 */ - private const RETURN_VARIABLE_NAME_REGEX = '#(@return)(?\s+[|\\\\\w]+)?(\s+)(?\$[\w]+)#'; + private const RETURN_VARIABLE_NAME_REGEX = '#(@return)(?\s+[|\\\\\w]+)?(\s+)(?<' . self::VARIABLE_NAME_PART . '>\$[\w]+)#'; /** * @var string[] @@ -27,6 +27,11 @@ final class SuperfluousReturnNameMalformWorker extends AbstractMalformWorker */ private const VARIABLE_NAME_REGEX = '#\$\w+#'; + /** + * @var string + */ + private const VARIABLE_NAME_PART = 'variableName'; + public function work(string $docContent, Tokens $tokens, int $position): string { $docBlock = new DocBlock($docContent); @@ -34,6 +39,10 @@ public function work(string $docContent, Tokens $tokens, int $position): string $lines = $docBlock->getLines(); foreach ($lines as $line) { $match = Strings::match($line->getContent(), self::RETURN_VARIABLE_NAME_REGEX); + if ($match === null) { + continue; + } + if ($this->shouldSkip($match, $line->getContent())) { continue; } @@ -58,17 +67,14 @@ function (array $match) { } /** - * @param mixed[]|null $match + * @param array $match */ - private function shouldSkip(?array $match, string $content): bool + private function shouldSkip(array $match, string $content): bool { - if ($match === null) { + if (in_array($match[self::VARIABLE_NAME_PART], self::ALLOWED_VARIABLE_NAMES, true)) { return true; } - if (in_array($match['variableName'], self::ALLOWED_VARIABLE_NAMES, true)) { - return true; - } // has multiple return values? "@return array $one, $two" return count(Strings::matchAll($content, self::VARIABLE_NAME_REGEX)) >= 2; } diff --git a/packages/easy-coding-standard/bin/ecs.php b/packages/easy-coding-standard/bin/ecs.php index c7a6546f3e..298b138b43 100755 --- a/packages/easy-coding-standard/bin/ecs.php +++ b/packages/easy-coding-standard/bin/ecs.php @@ -6,20 +6,12 @@ use PHP_CodeSniffer\Util\Tokens; use Symfony\Component\Console\Input\ArgvInput; -use Symplify\EasyCodingStandard\Bootstrap\ConfigHasher; -use Symplify\EasyCodingStandard\Bootstrap\ConfigShifter; -use Symplify\EasyCodingStandard\ChangedFilesDetector\ChangedFilesDetector; -use Symplify\EasyCodingStandard\Configuration\Configuration; use Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication; -use Symplify\EasyCodingStandard\HttpKernel\EasyCodingStandardKernel; -use Symplify\EasyCodingStandard\Set\ConstantReflectionSetFactory; -use Symplify\EasyCodingStandard\Set\EasyCodingStandardSetProvider; -use Symplify\PackageBuilder\Console\Input\StaticInputDetector; +use Symplify\EasyCodingStandard\DependencyInjection\ECSContainerFactory; use Symplify\PackageBuilder\Console\ShellCode; use Symplify\PackageBuilder\Console\Style\SymfonyStyleFactory; use Symplify\SetConfigResolver\Bootstrap\InvalidSetReporter; use Symplify\SetConfigResolver\Exception\SetNotFoundException; -use Symplify\SetConfigResolver\SetAwareConfigResolver; // performance boost gc_disable(); @@ -31,72 +23,22 @@ $autoloadIncluder->includeDependencyOrRepositoryVendorAutoloadIfExists(); $autoloadIncluder->includePhpCodeSnifferAutoloadIfNotInPharAndInitliazeTokens(); -$symfonyStyleFactory = new SymfonyStyleFactory(); -$symfonyStyle = $symfonyStyleFactory->create(); - -# 2. create container try { - $configFileInfos = []; - - // 1. --config CLI option or default - $configResolver = new SetAwareConfigResolver( - new EasyCodingStandardSetProvider(new ConstantReflectionSetFactory()) - ); - $input = new ArgvInput(); - $inputConfigFileInfo = $configResolver->resolveFromInputWithFallback($input, ['ecs.php']); - - if ($inputConfigFileInfo !== null) { - $configFileInfos[] = $inputConfigFileInfo; - } - - // 2. --set CLI option - $setInputConfig = $configResolver->resolveSetFromInput($input); - if ($setInputConfig !== null) { - $configFileInfos[] = $setInputConfig; - } - - // 3. "parameters > set" in provided yaml files - $parameterSetsConfigs = $configResolver->resolveFromParameterSetsFromConfigFiles($configFileInfos); - if ($parameterSetsConfigs !== []) { - $configFileInfos = array_merge($configFileInfos, $parameterSetsConfigs); - } - - $configHasher = new ConfigHasher(); - $environment = 'prod' . md5($configHasher->computeFileInfosHash($configFileInfos) . random_int(1, 100000)); - - $configShifter = new ConfigShifter(); - $configFileInfosWithInputAsLast = $configShifter->shiftInputConfigAsLast( - $configFileInfos, - $inputConfigFileInfo - ); - - $easyCodingStandardKernel = new EasyCodingStandardKernel($environment, StaticInputDetector::isDebug()); - if ($configFileInfos !== []) { - $easyCodingStandardKernel->setConfigs($configFileInfosWithInputAsLast); - } - - $easyCodingStandardKernel->boot(); - $container = $easyCodingStandardKernel->getContainer(); + $ecsContainerFactory = new ECSContainerFactory(); + $container = $ecsContainerFactory->createFromFromInput($input); } catch (SetNotFoundException $setNotFoundException) { $invalidSetReporter = new InvalidSetReporter(); $invalidSetReporter->report($setNotFoundException); exit(ShellCode::ERROR); } catch (Throwable $throwable) { + $symfonyStyleFactory = new SymfonyStyleFactory(); + $symfonyStyle = $symfonyStyleFactory->create(); + $symfonyStyle->error($throwable->getMessage()); exit(ShellCode::ERROR); } -// for cache invalidation on config change -/** @var ChangedFilesDetector $changedFilesDetector */ -$changedFilesDetector = $container->get(ChangedFilesDetector::class); -$changedFilesDetector->setUsedConfigs($configFileInfos); - -/** @var Configuration $configuration */ -$configuration = $container->get(Configuration::class); -$configuration->setFirstResolvedConfigFileInfo($configResolver->getFirstResolvedConfigFileInfo()); - -# 3. run $application = $container->get(EasyCodingStandardConsoleApplication::class); exit($application->run()); diff --git a/packages/easy-coding-standard/packages/configuration/src/Configuration.php b/packages/easy-coding-standard/packages/configuration/src/Configuration.php index d4760f652d..b029c3ddfa 100644 --- a/packages/easy-coding-standard/packages/configuration/src/Configuration.php +++ b/packages/easy-coding-standard/packages/configuration/src/Configuration.php @@ -34,11 +34,6 @@ final class Configuration */ private $showErrorTable = true; - /** - * @var SmartFileInfo|null - */ - private $firstResolvedConfigFileInfo; - /** * @var string[] */ @@ -115,19 +110,6 @@ public function shouldShowErrorTable(): bool return $this->showErrorTable; } - /** - * @api - */ - public function setFirstResolvedConfigFileInfo(?SmartFileInfo $firstResolverConfigFileInfo): void - { - $this->firstResolvedConfigFileInfo = $firstResolverConfigFileInfo; - } - - public function getFirstResolvedConfigFileInfo(): ?SmartFileInfo - { - return $this->firstResolvedConfigFileInfo; - } - /** * @param string[] $sources */ diff --git a/packages/easy-coding-standard/src/Bootstrap/ConfigShifter.php b/packages/easy-coding-standard/src/Bootstrap/ConfigShifter.php deleted file mode 100644 index 9e933ed7f5..0000000000 --- a/packages/easy-coding-standard/src/Bootstrap/ConfigShifter.php +++ /dev/null @@ -1,35 +0,0 @@ - - */ - public function shiftInputConfigAsLast(array $configFileInfos, ?SmartFileInfo $inputConfigFileInfo): array - { - if ($inputConfigFileInfo === null) { - return $configFileInfos; - } - - $mainConfigShiftedAsLast = []; - foreach ($configFileInfos as $configFileInfo) { - if ($configFileInfo !== $inputConfigFileInfo) { - $mainConfigShiftedAsLast[] = $configFileInfo; - } - } - - $mainConfigShiftedAsLast[] = $inputConfigFileInfo; - - return $mainConfigShiftedAsLast; - } -} diff --git a/packages/easy-coding-standard/src/Bootstrap/ECSConfigsResolver.php b/packages/easy-coding-standard/src/Bootstrap/ECSConfigsResolver.php new file mode 100644 index 0000000000..ffe4c21e70 --- /dev/null +++ b/packages/easy-coding-standard/src/Bootstrap/ECSConfigsResolver.php @@ -0,0 +1,45 @@ +setAwareConfigResolver = new SetAwareConfigResolver($easyCodingStandardSetProvider); + } + + public function resolveFromInput(InputInterface $input): BootstrapConfigs + { + $configFileInfos = []; + + $mainConfigFileInfo = $this->setAwareConfigResolver->resolveFromInputWithFallback($input, ['ecs.php']); + + if ($mainConfigFileInfo !== null) { + // 2. "parameters > set" in provided yaml files + $parameterSetsConfigs = $this->setAwareConfigResolver->resolveFromParameterSetsFromConfigFiles( + $configFileInfos + ); + if ($parameterSetsConfigs !== []) { + $configFileInfos = array_merge($configFileInfos, $parameterSetsConfigs); + } + } + + return new BootstrapConfigs($mainConfigFileInfo, $configFileInfos); + } +} diff --git a/packages/easy-coding-standard/src/Console/EasyCodingStandardConsoleApplication.php b/packages/easy-coding-standard/src/Console/EasyCodingStandardConsoleApplication.php index 40b563fb9b..b334a752c3 100644 --- a/packages/easy-coding-standard/src/Console/EasyCodingStandardConsoleApplication.php +++ b/packages/easy-coding-standard/src/Console/EasyCodingStandardConsoleApplication.php @@ -21,11 +21,6 @@ final class EasyCodingStandardConsoleApplication extends AbstractSymplifyConsoleApplication { - /** - * @var Configuration - */ - private $configuration; - /** * @var NoCheckersLoaderReporter */ @@ -34,16 +29,10 @@ final class EasyCodingStandardConsoleApplication extends AbstractSymplifyConsole /** * @param Command[] $commands */ - public function __construct( - Configuration $configuration, - NoCheckersLoaderReporter $noCheckersLoaderReporter, - array $commands - ) { + public function __construct(NoCheckersLoaderReporter $noCheckersLoaderReporter, array $commands) { $version = PrettyVersions::getVersion('symplify/easy-coding-standard'); parent::__construct($commands, 'EasyCodingStandard', $version->getPrettyVersion()); - - $this->configuration = $configuration; $this->noCheckersLoaderReporter = $noCheckersLoaderReporter; } @@ -62,11 +51,6 @@ public function doRun(InputInterface $input, OutputInterface $output): int $output->writeln($this->getLongVersion()); } - $firstResolvedConfigFileInfo = $this->configuration->getFirstResolvedConfigFileInfo(); - if ($firstResolvedConfigFileInfo !== null && $this->shouldPrintMetaInformation($input)) { - $output->writeln('Config file: ' . $firstResolvedConfigFileInfo->getRelativeFilePathFromCwd()); - } - return parent::doRun($input, $output); } diff --git a/packages/easy-coding-standard/src/Console/Output/JsonOutputFormatter.php b/packages/easy-coding-standard/src/Console/Output/JsonOutputFormatter.php index a3a479d1de..54e8721246 100644 --- a/packages/easy-coding-standard/src/Console/Output/JsonOutputFormatter.php +++ b/packages/easy-coding-standard/src/Console/Output/JsonOutputFormatter.php @@ -27,19 +27,13 @@ final class JsonOutputFormatter implements OutputFormatterInterface */ private const FILES = 'files'; - /** - * @var Configuration - */ - private $configuration; - /** * @var EasyCodingStandardStyle */ private $easyCodingStandardStyle; - public function __construct(Configuration $configuration, EasyCodingStandardStyle $easyCodingStandardStyle) + public function __construct(EasyCodingStandardStyle $easyCodingStandardStyle) { - $this->configuration = $configuration; $this->easyCodingStandardStyle = $easyCodingStandardStyle; } @@ -61,11 +55,6 @@ public function createJsonContent(ErrorAndDiffResult $errorAndDiffResult): strin { $errorsArray = $this->createBaseErrorsArray($errorAndDiffResult); - $firstResolvedConfigFileInfo = $this->configuration->getFirstResolvedConfigFileInfo(); - if ($firstResolvedConfigFileInfo !== null) { - $errorsArray['meta']['config'] = $firstResolvedConfigFileInfo->getRealPath(); - } - $codingStandardErrors = $errorAndDiffResult->getErrors(); foreach ($codingStandardErrors as $codingStandardError) { $errorsArray[self::FILES][$codingStandardError->getRelativeFilePathFromCwd()]['errors'][] = [ diff --git a/packages/easy-coding-standard/src/DependencyInjection/ECSContainerFactory.php b/packages/easy-coding-standard/src/DependencyInjection/ECSContainerFactory.php new file mode 100644 index 0000000000..dad8d3b200 --- /dev/null +++ b/packages/easy-coding-standard/src/DependencyInjection/ECSContainerFactory.php @@ -0,0 +1,49 @@ +resolveFromInput($input); + + return $this->createFromFromBootstrapConfigs($bootstrapConfigs); + } + + public function createFromFromBootstrapConfigs(BootstrapConfigs $bootstrapConfigs): ContainerInterface + { + $environment = 'prod' . random_int(1, 100000); + $easyCodingStandardKernel = new EasyCodingStandardKernel($environment, StaticInputDetector::isDebug()); + + $configFileInfos = $bootstrapConfigs->getConfigFileInfos(); + if ($configFileInfos !== []) { + $easyCodingStandardKernel->setConfigs($configFileInfos); + } + + $easyCodingStandardKernel->boot(); + + $container = $easyCodingStandardKernel->getContainer(); + + if ($configFileInfos !== []) { + // for cache invalidation on config change + /** @var ChangedFilesDetector $changedFilesDetector */ + $changedFilesDetector = $container->get(ChangedFilesDetector::class); + $changedFilesDetector->setUsedConfigs($configFileInfos); + } + + return $container; + } +} diff --git a/packages/git-wrapper/src/GitWrapper.php b/packages/git-wrapper/src/GitWrapper.php index 45b685a776..ffbc5ca75d 100644 --- a/packages/git-wrapper/src/GitWrapper.php +++ b/packages/git-wrapper/src/GitWrapper.php @@ -61,7 +61,7 @@ public function __construct(?string $gitBinary = null) if ($gitBinary === null) { $executableFinder = new ExecutableFinder(); $gitBinary = $executableFinder->find('git'); - if (! $gitBinary) { + if ($gitBinary === null) { throw new GitException('Unable to find the Git executable.'); } } diff --git a/packages/package-builder/src/DependencyInjection/DefinitionFinder.php b/packages/package-builder/src/DependencyInjection/DefinitionFinder.php index 90c7ec0958..88ea02386c 100644 --- a/packages/package-builder/src/DependencyInjection/DefinitionFinder.php +++ b/packages/package-builder/src/DependencyInjection/DefinitionFinder.php @@ -23,7 +23,7 @@ public function findAllByType(ContainerBuilder $containerBuilder, string $type): $containerBuilderDefinitions = $containerBuilder->getDefinitions(); foreach ($containerBuilderDefinitions as $name => $definition) { $class = $definition->getClass() ?: $name; - if (! $this->isClassExists($class)) { + if (! $this->doesClassExists($class)) { continue; } @@ -50,7 +50,7 @@ private function getByTypeIfExists(ContainerBuilder $containerBuilder, string $t $containerBuilderDefinitions = $containerBuilder->getDefinitions(); foreach ($containerBuilderDefinitions as $name => $definition) { $class = $definition->getClass() ?: $name; - if (! $this->isClassExists($class)) { + if (! $this->doesClassExists($class)) { continue; } @@ -62,12 +62,9 @@ private function getByTypeIfExists(ContainerBuilder $containerBuilder, string $t return null; } - private function isClassExists(?string $class): bool + private function doesClassExists(string $class): bool { try { - if (! is_string($class)) { - return false; - } return class_exists($class); } catch (Throwable $throwable) { return false; diff --git a/packages/package-builder/src/Reflection/ClassLikeExistenceChecker.php b/packages/package-builder/src/Reflection/ClassLikeExistenceChecker.php index 8daf932181..cb5f071d77 100644 --- a/packages/package-builder/src/Reflection/ClassLikeExistenceChecker.php +++ b/packages/package-builder/src/Reflection/ClassLikeExistenceChecker.php @@ -4,8 +4,20 @@ namespace Symplify\PackageBuilder\Reflection; +use ReflectionClass; + final class ClassLikeExistenceChecker { + /** + * @var string[] + */ + private $sensitiveExistingClasses = []; + + /** + * @var string[] + */ + private $sensitiveNonExistingClasses = []; + public function doesClassLikeExist(string $classLike): bool { if (class_exists($classLike)) { @@ -18,4 +30,30 @@ public function doesClassLikeExist(string $classLike): bool return trait_exists($classLike); } + + public function doesClassLikeInensitiveExists(string $classLikeName): bool + { + if (!$this->doesClassLikeExist($classLikeName)) { + return false; + } + + // already known values + if (in_array($classLikeName, $this->sensitiveExistingClasses, true)) { + return true; + } + + if (in_array($classLikeName, $this->sensitiveNonExistingClasses, true)) { + return false; + } + + $reflectionClass = new ReflectionClass($classLikeName); + if ($classLikeName !== $reflectionClass->getName()) { + $this->sensitiveNonExistingClasses[] = $classLikeName; + return false; + } + + $this->sensitiveExistingClasses[] = $classLikeName; + return true; + } } + diff --git a/packages/php-config-printer/src/ExprResolver/StringExprResolver.php b/packages/php-config-printer/src/ExprResolver/StringExprResolver.php index 549acf7ce5..d3a8061234 100644 --- a/packages/php-config-printer/src/ExprResolver/StringExprResolver.php +++ b/packages/php-config-printer/src/ExprResolver/StringExprResolver.php @@ -108,7 +108,7 @@ private function isFilePath(string $value): bool /** * @return String_|ClassConstFetch */ - private function resolveClassType(bool $skipClassesToConstantReference, string $value) + private function resolveClassType(bool $skipClassesToConstantReference, string $value): Expr { if ($skipClassesToConstantReference) { return new String_($value); diff --git a/packages/php-config-printer/src/Printer/SmartPhpConfigPrinter.php b/packages/php-config-printer/src/Printer/SmartPhpConfigPrinter.php index d7d94391ea..881f1d7e8d 100644 --- a/packages/php-config-printer/src/Printer/SmartPhpConfigPrinter.php +++ b/packages/php-config-printer/src/Printer/SmartPhpConfigPrinter.php @@ -44,29 +44,29 @@ public function printConfiguredServices(array $configuredServices): string { $servicesWithConfigureCalls = []; foreach ($configuredServices as $service => $configuration) { - $servicesWithConfigureCalls[$service] = $this->createServiceConfiguration($configuration, $service); + if ($configuration === null) { + $servicesWithConfigureCalls[$service] = null; + } else { + $servicesWithConfigureCalls[$service] = $this->createServiceConfiguration($configuration, $service); + } } - $return = $this->configuratorReturnClosureFactory->createFromYamlArray( - [ - 'services' => $servicesWithConfigureCalls, - ] - ); + $return = $this->configuratorReturnClosureFactory->createFromYamlArray([ + 'services' => $servicesWithConfigureCalls, + ]); return $this->phpParserPhpConfigPrinter->prettyPrintFile([$return]); } /** - * @param mixed[]|null $configuration + * @param mixed[] $configuration */ - private function createServiceConfiguration(?array $configuration, string $class): ?array + private function createServiceConfiguration(array $configuration, string $class): ?array { - if ($configuration === null) { - return null; - } if ($configuration === []) { return null; } + $configuration = $this->serviceConfigurationDecorator->decorate($configuration, $class); return [ diff --git a/packages/phpstan-rules/config/configurable-rules.neon b/packages/phpstan-rules/config/configurable-rules.neon index 9754d4cda1..6ee4a4a886 100644 --- a/packages/phpstan-rules/config/configurable-rules.neon +++ b/packages/phpstan-rules/config/configurable-rules.neon @@ -8,9 +8,6 @@ services: - class: Symplify\PHPStanRules\Rules\ForbiddenNullableParameterRule tags: [phpstan.rules.rule] - arguments: - forbiddenTypes: - - PhpParser\Node - class: \Symplify\PHPStanRules\Rules\IfNewTypeThenImplementInterfaceRule diff --git a/packages/phpstan-rules/config/services/services.neon b/packages/phpstan-rules/config/services/services.neon index ad76aa782c..de734bcc0f 100644 --- a/packages/phpstan-rules/config/services/services.neon +++ b/packages/phpstan-rules/config/services/services.neon @@ -14,6 +14,7 @@ services: - Symplify\PHPStanRules\NodeAnalyzer\ProtectedAnalyzer - Symplify\PHPStanRules\NodeAnalyzer\DependencyNodeAnalyzer - Symplify\PHPStanRules\NodeAnalyzer\TypeNodeAnalyzer + - Symplify\PHPStanRules\ParentGuard\ParentClassMethodGuard - Symplify\PHPStanRules\PhpDoc\BarePhpDocParser - Symplify\PHPStanRules\PhpDoc\ClassAnnotationResolver diff --git a/packages/phpstan-rules/packages/cognitive-complexity/src/NodeAnalyzer/ComplexityAffectingNodeFinder.php b/packages/phpstan-rules/packages/cognitive-complexity/src/NodeAnalyzer/ComplexityAffectingNodeFinder.php index 8725862430..300d8f7a91 100644 --- a/packages/phpstan-rules/packages/cognitive-complexity/src/NodeAnalyzer/ComplexityAffectingNodeFinder.php +++ b/packages/phpstan-rules/packages/cognitive-complexity/src/NodeAnalyzer/ComplexityAffectingNodeFinder.php @@ -4,6 +4,7 @@ namespace Symplify\PHPStanRules\CognitiveComplexity\NodeAnalyzer; +use PhpParser\Node\Stmt; use PhpParser\Node; use PhpParser\Node\Expr\BinaryOp\BooleanAnd; use PhpParser\Node\Expr\Ternary; @@ -25,7 +26,7 @@ final class ComplexityAffectingNodeFinder { /** * B1. Increments - * @var string[] + * @var array> */ private const BREAKING_NODE_TYPES = [Continue_::class, Goto_::class, Break_::class]; diff --git a/packages/phpstan-rules/src/NodeAnalyzer/DependencyNodeAnalyzer.php b/packages/phpstan-rules/src/NodeAnalyzer/DependencyNodeAnalyzer.php index 2c0db59b25..15f24b3985 100644 --- a/packages/phpstan-rules/src/NodeAnalyzer/DependencyNodeAnalyzer.php +++ b/packages/phpstan-rules/src/NodeAnalyzer/DependencyNodeAnalyzer.php @@ -52,7 +52,7 @@ public function __construct( $this->parentNodeFinder = $parentNodeFinder; } - public function isInsideAbstractClassAndPassedAsDependencyViaConstructorOrSetUp(Property $property): bool + public function isInsideAbstractClassAndPassedAsDependency(Property $property): bool { $classLike = $this->parentNodeFinder->getFirstParentByType($property, Class_::class); if (! $classLike instanceof Class_) { @@ -77,7 +77,7 @@ public function isInsideAbstractClassAndPassedAsDependencyViaConstructorOrSetUp( return $this->isBeeingAssignedInAssigns($property, $assigns); } - public function isInsideClassAndPassedAsDependencyViaAutowireMethod(Property $property): bool + public function isInsideClassAndAutowiredMethod(Property $property): bool { $classLike = $this->parentNodeFinder->getFirstParentByType($property, ClassLike::class); if (! $classLike instanceof Class_ && ! $classLike instanceof Trait_) { diff --git a/packages/phpstan-rules/src/NodeAnalyzer/Nette/NetteTypeAnalyzer.php b/packages/phpstan-rules/src/NodeAnalyzer/Nette/NetteTypeAnalyzer.php index 42807c035e..96bfcd733b 100644 --- a/packages/phpstan-rules/src/NodeAnalyzer/Nette/NetteTypeAnalyzer.php +++ b/packages/phpstan-rules/src/NodeAnalyzer/Nette/NetteTypeAnalyzer.php @@ -4,6 +4,7 @@ namespace Symplify\PHPStanRules\NodeAnalyzer\Nette; +use Nette\Application\UI\Template; use PhpParser\Node\Expr; use PHPStan\Analyser\Scope; use Symplify\Astral\Naming\SimpleNameResolver; @@ -12,7 +13,7 @@ final class NetteTypeAnalyzer { /** - * @var array + * @var class-string