From c31ab784a23e7902c1d5ef8a077ee91d49b2f466 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 8 Jun 2023 17:33:28 +0200 Subject: [PATCH 1/6] Add AddConstructorParentCallRector to code-quality set --- config/set/code-quality.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/set/code-quality.php b/config/set/code-quality.php index 9a43aafe5b1..3aad188ec18 100644 --- a/config/set/code-quality.php +++ b/config/set/code-quality.php @@ -80,6 +80,7 @@ use Rector\Php52\Rector\Property\VarToPublicPropertyRector; use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; use Rector\Renaming\Rector\FuncCall\RenameFunctionRector; +use Rector\Strict\Rector\ClassMethod\AddConstructorParentCallRector; use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; return static function (RectorConfig $rectorConfig): void { @@ -188,5 +189,6 @@ CleanupUnneededNullsafeOperatorRector::class, DisallowedEmptyRuleFixerRector::class, ConvertStaticPrivateConstantToSelfRector::class, + AddConstructorParentCallRector::class, ]); }; From 2fa3d243b7d5ee8de82af6b908ddce17fcf560e6 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 8 Jun 2023 17:36:26 +0200 Subject: [PATCH 2/6] Add new STRICT_BOOLEANS set --- config/set/code-quality.php | 2 -- config/set/strict-booleans.php | 22 ++++++++++++++++++++++ packages/Set/ValueObject/SetList.php | 5 +++++ rector.php | 1 + utils/Command/MissingInSetCommand.php | 1 + 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 config/set/strict-booleans.php diff --git a/config/set/code-quality.php b/config/set/code-quality.php index 3aad188ec18..9a43aafe5b1 100644 --- a/config/set/code-quality.php +++ b/config/set/code-quality.php @@ -80,7 +80,6 @@ use Rector\Php52\Rector\Property\VarToPublicPropertyRector; use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; use Rector\Renaming\Rector\FuncCall\RenameFunctionRector; -use Rector\Strict\Rector\ClassMethod\AddConstructorParentCallRector; use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; return static function (RectorConfig $rectorConfig): void { @@ -189,6 +188,5 @@ CleanupUnneededNullsafeOperatorRector::class, DisallowedEmptyRuleFixerRector::class, ConvertStaticPrivateConstantToSelfRector::class, - AddConstructorParentCallRector::class, ]); }; diff --git a/config/set/strict-booleans.php b/config/set/strict-booleans.php new file mode 100644 index 00000000000..3dfeb40176c --- /dev/null +++ b/config/set/strict-booleans.php @@ -0,0 +1,22 @@ +rules([ + BooleanInBooleanNotRuleFixerRector::class, + AddConstructorParentCallRector::class, + DisallowedEmptyRuleFixerRector::class, + BooleanInIfConditionRuleFixerRector::class, + BooleanInTernaryOperatorRuleFixerRector::class, + DisallowedShortTernaryRuleFixerRector::class, + ]); +}; diff --git a/packages/Set/ValueObject/SetList.php b/packages/Set/ValueObject/SetList.php index 5625ff29779..04425f4f451 100644 --- a/packages/Set/ValueObject/SetList.php +++ b/packages/Set/ValueObject/SetList.php @@ -26,6 +26,11 @@ final class SetList implements SetListInterface */ public const DEAD_CODE = __DIR__ . '/../../../config/set/dead-code.php'; + /** + * @var string + */ + public const STRICT_BOOLEANS = __DIR__ . '/../../../config/set/strict-booleans.php'; + /** * @var string */ diff --git a/rector.php b/rector.php index 3157fb2986b..afebcde67b4 100644 --- a/rector.php +++ b/rector.php @@ -28,6 +28,7 @@ SetList::EARLY_RETURN, PHPUnitSetList::PHPUNIT_CODE_QUALITY, SetList::CODING_STYLE, + SetList::STRICT_BOOLEANS, ]); $rectorConfig->rules([DeclareStrictTypesRector::class]); diff --git a/utils/Command/MissingInSetCommand.php b/utils/Command/MissingInSetCommand.php index 998f59d1bab..a5832a33ccb 100644 --- a/utils/Command/MissingInSetCommand.php +++ b/utils/Command/MissingInSetCommand.php @@ -46,6 +46,7 @@ final class MissingInSetCommand extends Command __DIR__ . '/../../rules/Php80/Rector' => __DIR__ . '/../../config/set/php80.php', __DIR__ . '/../../rules/Php81/Rector' => __DIR__ . '/../../config/set/php81.php', __DIR__ . '/../../rules/Php82/Rector' => __DIR__ . '/../../config/set/php82.php', + __DIR__ . '/../../rules/Strict/Rector' => __DIR__ . '/../../config/set/strict-booleans.php', ]; /** From 26b0c6182137fbae81e895912b8eadb370077886 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 8 Jun 2023 17:41:02 +0200 Subject: [PATCH 3/6] check downgrade sets too --- utils/Command/MissingInSetCommand.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/Command/MissingInSetCommand.php b/utils/Command/MissingInSetCommand.php index a5832a33ccb..285a2924b06 100644 --- a/utils/Command/MissingInSetCommand.php +++ b/utils/Command/MissingInSetCommand.php @@ -47,6 +47,13 @@ final class MissingInSetCommand extends Command __DIR__ . '/../../rules/Php81/Rector' => __DIR__ . '/../../config/set/php81.php', __DIR__ . '/../../rules/Php82/Rector' => __DIR__ . '/../../config/set/php82.php', __DIR__ . '/../../rules/Strict/Rector' => __DIR__ . '/../../config/set/strict-booleans.php', + __DIR__ . '/../../vendor/rector/rector-downgrade-php/rules/DowngradePhp70' => __DIR__ . '/../../vendor/rector/rector-downgrade-php/config/set/downgrade-php70.php', + __DIR__ . '/../../vendor/rector/rector-downgrade-php/rules/DowngradePhp71' => __DIR__ . '/../../vendor/rector/rector-downgrade-php/config/set/downgrade-php71.php', + __DIR__ . '/../../vendor/rector/rector-downgrade-php/rules/DowngradePhp72' => __DIR__ . '/../../vendor/rector/rector-downgrade-php/config/set/downgrade-php72.php', + __DIR__ . '/../../vendor/rector/rector-downgrade-php/rules/DowngradePhp73' => __DIR__ . '/../../vendor/rector/rector-downgrade-php/config/set/downgrade-php73.php', + __DIR__ . '/../../vendor/rector/rector-downgrade-php/rules/DowngradePhp74' => __DIR__ . '/../../vendor/rector/rector-downgrade-php/config/set/downgrade-php74.php', + __DIR__ . '/../../vendor/rector/rector-downgrade-php/rules/DowngradePhp80' => __DIR__ . '/../../vendor/rector/rector-downgrade-php/config/set/downgrade-php80.php', + __DIR__ . '/../../vendor/rector/rector-downgrade-php/rules/DowngradePhp81' => __DIR__ . '/../../vendor/rector/rector-downgrade-php/config/set/downgrade-php81.php', ]; /** From 9b615c13a181d9f7a3837e5680392b7564b86364 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 8 Jun 2023 17:43:50 +0200 Subject: [PATCH 4/6] skip boolean type in BooleanInBooleanNotRuleFixerRector --- .../CommentRemovingNodeTraverser.php | 2 ++ phpstan.neon | 1 + rector.php | 17 ++++++------ .../Fixture/skip_negated_boolean.php.inc | 16 +++++++++++ rules/Naming/Naming/PropertyNaming.php | 6 +++-- .../BooleanInBooleanNotRuleFixerRector.php | 3 +++ .../AddConstructorParentCallRector.php | 27 ++++++++++++------- .../StaticCall/StaticCallToFuncCallRector.php | 5 +--- .../AutowireArrayParameterCompilerPass.php | 7 +++-- src/DependencyInjection/DefinitionFinder.php | 1 + .../FileWithoutNamespaceNodeTraverser.php | 1 + .../NodeTraverser/RectorNodeTraverser.php | 1 + 12 files changed, 61 insertions(+), 26 deletions(-) create mode 100644 rules-tests/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector/Fixture/skip_negated_boolean.php.inc diff --git a/packages/Comments/NodeTraverser/CommentRemovingNodeTraverser.php b/packages/Comments/NodeTraverser/CommentRemovingNodeTraverser.php index fecfb3aee34..214c711d8dd 100644 --- a/packages/Comments/NodeTraverser/CommentRemovingNodeTraverser.php +++ b/packages/Comments/NodeTraverser/CommentRemovingNodeTraverser.php @@ -12,5 +12,7 @@ final class CommentRemovingNodeTraverser extends NodeTraverser public function __construct(CommentRemovingNodeVisitor $commentRemovingNodeVisitor) { $this->addVisitor($commentRemovingNodeVisitor); + + parent::__construct(); } } diff --git a/phpstan.neon b/phpstan.neon index 0a9162ffd06..accf02ede67 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -731,3 +731,4 @@ parameters: # resolve before Rector 1.0 - '#Call to deprecated method findParentType#' - '#Call to deprecated method findParentByTypes#' + - '#Instantiation of deprecated class Rector\\Core\\DependencyInjection\\CompilerPass\\AutowireArrayParameterCompilerPass#' diff --git a/rector.php b/rector.php index afebcde67b4..e952bb13e69 100644 --- a/rector.php +++ b/rector.php @@ -8,7 +8,6 @@ use Rector\CodingStyle\Rector\String_\UseClassKeywordForClassNameResolutionRector; use Rector\CodingStyle\ValueObject\ReturnArrayClassMethodToYield; use Rector\Config\RectorConfig; -use Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchExprVariableRector; use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Set\ValueObject\LevelSetList; @@ -72,17 +71,13 @@ '**/Source/*', '**/Expected/*', '**/Expected*', - __DIR__ . '/tests/PhpUnit/MultipleFilesChangedTrait/MultipleFilesChangedTraitTest.php', - // to keep original API from PHPStan untouched - __DIR__ . '/packages/Caching/ValueObject/Storage/FileCacheStorage.php', + \Rector\Strict\Rector\ClassMethod\AddConstructorParentCallRector::class => [ + __DIR__ . '/packages/StaticTypeMapper/ValueObject/Type/SimpleStaticType.php', + ], // keep configs untouched, as the classes are just strings - UseClassKeywordForClassNameResolutionRector::class => [__DIR__ . '/config', '*/config/*'], - RenameForeachValueVariableToMatchExprVariableRector::class => [ - // false positive on plurals - __DIR__ . '/packages/Testing/PHPUnit/Behavior/MovingFilesTrait.php', - ], + UseClassKeywordForClassNameResolutionRector::class => [__DIR__ . '/config'], // avoid simplifying itself \Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector::class => [ @@ -93,6 +88,10 @@ \Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector::class => [ __DIR__ . '/rules/DeadCode/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php', ], + + \Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector::class => [ + __DIR__ . '/src/DependencyInjection', + ], ]); $rectorConfig->phpstanConfig(__DIR__ . '/phpstan-for-rector.neon'); diff --git a/rules-tests/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector/Fixture/skip_negated_boolean.php.inc b/rules-tests/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector/Fixture/skip_negated_boolean.php.inc new file mode 100644 index 00000000000..f2fbfc2a9f3 --- /dev/null +++ b/rules-tests/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector/Fixture/skip_negated_boolean.php.inc @@ -0,0 +1,16 @@ +getClass(), PostRectorInterface::class, true); + } +} diff --git a/rules/Naming/Naming/PropertyNaming.php b/rules/Naming/Naming/PropertyNaming.php index 0b6adefb86a..3b43d92ae7e 100644 --- a/rules/Naming/Naming/PropertyNaming.php +++ b/rules/Naming/Naming/PropertyNaming.php @@ -210,12 +210,14 @@ private function fqnToShortName(string $fqn): string private function removeInterfaceSuffixPrefix(string $className, string $category): string { // suffix - if (Strings::match($className, '#' . $category . '$#i')) { + $iSuffixMatch = Strings::match($className, '#' . $category . '$#i'); + if ($iSuffixMatch !== null) { return Strings::substring($className, 0, -strlen($category)); } // prefix - if (Strings::match($className, '#^' . $category . '#i')) { + $iPrefixMatch = Strings::match($className, '#^' . $category . '#i'); + if ($iPrefixMatch !== null) { return Strings::substring($className, strlen($category)); } diff --git a/rules/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector.php b/rules/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector.php index e735fe5e4ed..02ff84eaec2 100644 --- a/rules/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector.php +++ b/rules/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector.php @@ -83,6 +83,9 @@ public function getNodeTypes(): array public function refactorWithScope(Node $node, Scope $scope): ?Expr { $exprType = $scope->getType($node->expr); + if ($exprType->isBoolean()->yes()) { + return null; + } return $this->exactCompareFactory->createIdenticalFalsyCompare($exprType, $node->expr, $this->treatAsNonEmpty); } diff --git a/rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php b/rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php index 6dca9609b19..1d72bfa7990 100644 --- a/rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php +++ b/rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php @@ -7,7 +7,6 @@ use PhpParser\Node; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Stmt\Class_; -use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Analyser\Scope; use Rector\Core\Enum\ObjectReference; @@ -71,28 +70,38 @@ public function __construct(ParentDependency $parentDependency) */ public function getNodeTypes(): array { - return [ClassMethod::class]; + return [Class_::class]; } /** - * @param ClassMethod $node + * @param Class_ $node */ - public function refactorWithScope(Node $node, Scope $scope): ?Node + public function refactorWithScope(Node $node, Scope $scope): ?Class_ { - if (! $this->isName($node, MethodName::CONSTRUCT)) { + // no parent? skip it + if (! $node->extends instanceof Node) { return null; } - $classLike = $this->betterNodeFinder->findParentType($node, ClassLike::class); - if (! $classLike instanceof Class_) { + $constructorClassMethod = $node->getMethod(MethodName::CONSTRUCT); + + if (! $constructorClassMethod instanceof ClassMethod) { return null; } - if ($this->hasParentCallOfMethod($node)) { + if (! $this->isName($node, MethodName::CONSTRUCT)) { return null; } - $this->dependencyClassMethodDecorator->decorateConstructorWithParentDependencies($classLike, $node, $scope); + if ($this->hasParentCallOfMethod($constructorClassMethod)) { + return null; + } + + $this->dependencyClassMethodDecorator->decorateConstructorWithParentDependencies( + $node, + $constructorClassMethod, + $scope + ); return $node; } diff --git a/rules/Transform/Rector/StaticCall/StaticCallToFuncCallRector.php b/rules/Transform/Rector/StaticCall/StaticCallToFuncCallRector.php index c125f9e62f6..54c8a25869c 100644 --- a/rules/Transform/Rector/StaticCall/StaticCallToFuncCallRector.php +++ b/rules/Transform/Rector/StaticCall/StaticCallToFuncCallRector.php @@ -23,10 +23,7 @@ final class StaticCallToFuncCallRector extends AbstractRector implements Configu /** * @param StaticCallToFuncCall[] $staticCallsToFunctions */ - public function __construct( - private array $staticCallsToFunctions = [] - ) { - } + private array $staticCallsToFunctions = []; public function getRuleDefinition(): RuleDefinition { diff --git a/src/DependencyInjection/CompilerPass/AutowireArrayParameterCompilerPass.php b/src/DependencyInjection/CompilerPass/AutowireArrayParameterCompilerPass.php index 519bc3cf9aa..44acf032d51 100644 --- a/src/DependencyInjection/CompilerPass/AutowireArrayParameterCompilerPass.php +++ b/src/DependencyInjection/CompilerPass/AutowireArrayParameterCompilerPass.php @@ -101,7 +101,9 @@ private function shouldSkipDefinition(ContainerBuilder $containerBuilder, Defini // skip 3rd party classes, they're autowired by own config $excludedNamespacePattern = '#^(' . implode('|', self::EXCLUDED_NAMESPACES) . ')\\\\#'; - if (Strings::match($resolvedClassName, $excludedNamespacePattern)) { + $excludedNamespaceMatch = Strings::match($resolvedClassName, $excludedNamespacePattern); + + if ($excludedNamespaceMatch !== null) { return true; } @@ -128,7 +130,8 @@ private function shouldSkipDefinition(ContainerBuilder $containerBuilder, Defini /** @var ReflectionMethod $constructorReflectionMethod */ $constructorReflectionMethod = $reflectionClass->getConstructor(); - return ! $constructorReflectionMethod->getParameters(); + + return $constructorReflectionMethod->getParameters() === []; } private function processParameters( diff --git a/src/DependencyInjection/DefinitionFinder.php b/src/DependencyInjection/DefinitionFinder.php index 68f71d89c99..577958332ef 100644 --- a/src/DependencyInjection/DefinitionFinder.php +++ b/src/DependencyInjection/DefinitionFinder.php @@ -23,6 +23,7 @@ public function findAllByType(ContainerBuilder $containerBuilder, string $type): $definitions = []; $containerBuilderDefinitions = $containerBuilder->getDefinitions(); foreach ($containerBuilderDefinitions as $name => $definition) { + /** @var Definition $definition */ $class = $definition->getClass() ?: $name; if (! $this->doesClassExists($class)) { continue; diff --git a/src/PhpParser/NodeTraverser/FileWithoutNamespaceNodeTraverser.php b/src/PhpParser/NodeTraverser/FileWithoutNamespaceNodeTraverser.php index dda16f37349..78291923fa7 100644 --- a/src/PhpParser/NodeTraverser/FileWithoutNamespaceNodeTraverser.php +++ b/src/PhpParser/NodeTraverser/FileWithoutNamespaceNodeTraverser.php @@ -16,6 +16,7 @@ final class FileWithoutNamespaceNodeTraverser extends NodeTraverser public function __construct( private readonly NodeFinder $nodeFinder, ) { + parent::__construct(); } /** diff --git a/src/PhpParser/NodeTraverser/RectorNodeTraverser.php b/src/PhpParser/NodeTraverser/RectorNodeTraverser.php index 16931657948..df0d033f0db 100644 --- a/src/PhpParser/NodeTraverser/RectorNodeTraverser.php +++ b/src/PhpParser/NodeTraverser/RectorNodeTraverser.php @@ -20,6 +20,7 @@ public function __construct( private readonly array $phpRectors, private readonly PhpVersionedFilter $phpVersionedFilter ) { + parent::__construct(); } /** From a3cfc4aab4b6ab40320bf4519a39ed41ece38c9d Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 8 Jun 2023 18:00:43 +0200 Subject: [PATCH 5/6] Remove AddConstructorParentCallRector as risky --- config/set/strict-booleans.php | 2 - rector.php | 6 +- .../AddConstructorParentCallRectorTest.php | 28 ---- .../Fixture/fixture.php.inc | 32 ----- .../Fixture/fixture2.php.inc | 32 ----- .../Fixture/fixture3.php.inc | 32 ----- .../Fixture/skip_already_has.php.inc | 15 --- .../Source/ParentClassWithConstructor.php | 18 --- .../config/configured_rule.php | 10 -- .../AddConstructorParentCallRector.php | 126 ------------------ .../StaticCall/StaticCallToFuncCallRector.php | 2 +- .../AutowireArrayParameterCompilerPass.php | 2 + 12 files changed, 4 insertions(+), 301 deletions(-) delete mode 100644 rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/AddConstructorParentCallRectorTest.php delete mode 100644 rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/fixture.php.inc delete mode 100644 rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/fixture2.php.inc delete mode 100644 rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/fixture3.php.inc delete mode 100644 rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/skip_already_has.php.inc delete mode 100644 rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Source/ParentClassWithConstructor.php delete mode 100644 rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/config/configured_rule.php delete mode 100644 rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php diff --git a/config/set/strict-booleans.php b/config/set/strict-booleans.php index 3dfeb40176c..921427a90cc 100644 --- a/config/set/strict-booleans.php +++ b/config/set/strict-booleans.php @@ -4,7 +4,6 @@ use Rector\Config\RectorConfig; use Rector\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector; -use Rector\Strict\Rector\ClassMethod\AddConstructorParentCallRector; use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector; use Rector\Strict\Rector\Ternary\BooleanInTernaryOperatorRuleFixerRector; @@ -13,7 +12,6 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->rules([ BooleanInBooleanNotRuleFixerRector::class, - AddConstructorParentCallRector::class, DisallowedEmptyRuleFixerRector::class, BooleanInIfConditionRuleFixerRector::class, BooleanInTernaryOperatorRuleFixerRector::class, diff --git a/rector.php b/rector.php index e952bb13e69..16ef534a33c 100644 --- a/rector.php +++ b/rector.php @@ -72,12 +72,8 @@ '**/Expected/*', '**/Expected*', - \Rector\Strict\Rector\ClassMethod\AddConstructorParentCallRector::class => [ - __DIR__ . '/packages/StaticTypeMapper/ValueObject/Type/SimpleStaticType.php', - ], - // keep configs untouched, as the classes are just strings - UseClassKeywordForClassNameResolutionRector::class => [__DIR__ . '/config'], + UseClassKeywordForClassNameResolutionRector::class => [__DIR__ . '/config', '*/config/*'], // avoid simplifying itself \Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector::class => [ diff --git a/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/AddConstructorParentCallRectorTest.php b/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/AddConstructorParentCallRectorTest.php deleted file mode 100644 index 32039279e0c..00000000000 --- a/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/AddConstructorParentCallRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/fixture.php.inc b/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/fixture.php.inc deleted file mode 100644 index ed6cf12a864..00000000000 --- a/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,32 +0,0 @@ - ------ - diff --git a/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/fixture2.php.inc b/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/fixture2.php.inc deleted file mode 100644 index e9eeaa3330d..00000000000 --- a/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/fixture2.php.inc +++ /dev/null @@ -1,32 +0,0 @@ - ------ - diff --git a/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/fixture3.php.inc b/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/fixture3.php.inc deleted file mode 100644 index 1d0c43e999c..00000000000 --- a/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/fixture3.php.inc +++ /dev/null @@ -1,32 +0,0 @@ - ------ - diff --git a/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/skip_already_has.php.inc b/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/skip_already_has.php.inc deleted file mode 100644 index 3a643d67269..00000000000 --- a/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/Fixture/skip_already_has.php.inc +++ /dev/null @@ -1,15 +0,0 @@ -defaultValue = 5; - } -} diff --git a/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/config/configured_rule.php b/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/config/configured_rule.php deleted file mode 100644 index 9b607786848..00000000000 --- a/rules-tests/Strict/Rector/ClassMethod/AddConstructorParentCallRector/config/configured_rule.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(AddConstructorParentCallRector::class); -}; diff --git a/rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php b/rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php deleted file mode 100644 index 1d72bfa7990..00000000000 --- a/rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php +++ /dev/null @@ -1,126 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [Class_::class]; - } - - /** - * @param Class_ $node - */ - public function refactorWithScope(Node $node, Scope $scope): ?Class_ - { - // no parent? skip it - if (! $node->extends instanceof Node) { - return null; - } - - $constructorClassMethod = $node->getMethod(MethodName::CONSTRUCT); - - if (! $constructorClassMethod instanceof ClassMethod) { - return null; - } - - if (! $this->isName($node, MethodName::CONSTRUCT)) { - return null; - } - - if ($this->hasParentCallOfMethod($constructorClassMethod)) { - return null; - } - - $this->dependencyClassMethodDecorator->decorateConstructorWithParentDependencies( - $node, - $constructorClassMethod, - $scope - ); - - return $node; - } - - /** - * Looks for "parent::__construct" - */ - private function hasParentCallOfMethod(ClassMethod $classMethod): bool - { - return (bool) $this->betterNodeFinder->findFirst((array) $classMethod->stmts, function (Node $node): bool { - if (! $node instanceof StaticCall) { - return false; - } - - if (! $this->isName($node->class, ObjectReference::PARENT)) { - return false; - } - - return $this->isName($node->name, MethodName::CONSTRUCT); - }); - } -} diff --git a/rules/Transform/Rector/StaticCall/StaticCallToFuncCallRector.php b/rules/Transform/Rector/StaticCall/StaticCallToFuncCallRector.php index 54c8a25869c..acf49e9474c 100644 --- a/rules/Transform/Rector/StaticCall/StaticCallToFuncCallRector.php +++ b/rules/Transform/Rector/StaticCall/StaticCallToFuncCallRector.php @@ -21,7 +21,7 @@ final class StaticCallToFuncCallRector extends AbstractRector implements ConfigurableRectorInterface { /** - * @param StaticCallToFuncCall[] $staticCallsToFunctions + * @var StaticCallToFuncCall[] */ private array $staticCallsToFunctions = []; diff --git a/src/DependencyInjection/CompilerPass/AutowireArrayParameterCompilerPass.php b/src/DependencyInjection/CompilerPass/AutowireArrayParameterCompilerPass.php index 44acf032d51..9fdbfeb1223 100644 --- a/src/DependencyInjection/CompilerPass/AutowireArrayParameterCompilerPass.php +++ b/src/DependencyInjection/CompilerPass/AutowireArrayParameterCompilerPass.php @@ -18,6 +18,8 @@ use Symfony\Component\DependencyInjection\Reference; /** + * @deprecated Make the required services explicit, for faster autowire + * * @inspiration https://github.com/nette/di/pull/178 * @see \Rector\Core\Tests\DependencyInjection\CompilerPass\AutowireArrayParameterCompilerPassTest */ From 91a5b8624576e7e1986def10c7af99079621d608 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 8 Jun 2023 18:12:34 +0200 Subject: [PATCH 6/6] misc --- .../Caching/ValueObject/Storage/FileCacheStorage.php | 12 ++++++------ .../Testing/PHPUnit/Behavior/MovingFilesTrait.php | 12 ++++++------ phpstan.neon | 2 +- rector.php | 3 +++ 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/Caching/ValueObject/Storage/FileCacheStorage.php b/packages/Caching/ValueObject/Storage/FileCacheStorage.php index a5c0787b2ab..d49f17ba998 100644 --- a/packages/Caching/ValueObject/Storage/FileCacheStorage.php +++ b/packages/Caching/ValueObject/Storage/FileCacheStorage.php @@ -19,8 +19,8 @@ final class FileCacheStorage implements CacheStorageInterface { public function __construct( - private string $directory, - private \Symfony\Component\Filesystem\Filesystem $filesystem + private readonly string $directory, + private readonly \Symfony\Component\Filesystem\Filesystem $filesystem ) { } @@ -53,7 +53,7 @@ public function save(string $key, string $variableKey, mixed $data): void $this->filesystem-> mkdir($cacheFilePaths->getFirstDirectory()); $this->filesystem->mkdir($cacheFilePaths->getSecondDirectory()); - $path = $cacheFilePaths->getFilePath(); + $filePath = $cacheFilePaths->getFilePath(); $tmpPath = \sprintf('%s/%s.tmp', $this->directory, Random::generate()); $errorBefore = \error_get_last(); @@ -70,14 +70,14 @@ public function save(string $key, string $variableKey, mixed $data): void // for performance reasons we don't use SmartFileSystem FileSystem::write($tmpPath, \sprintf("getFilePath() !== $expectedFilePath) { + foreach ($addedFilePathsWithContents as $addedFilePathWithContent) { + if ($addedFilePathWithContent->getFilePath() !== $expectedFilePath) { continue; } - $this->assertSame($expectedFileContents, $addedFilePathsWithContent->getFileContent()); + $this->assertSame($expectedFileContents, $addedFilePathWithContent->getFileContent()); $wasFound = true; } @@ -46,9 +46,9 @@ private function resolveAddedFilePathsWithContents(): array return $addedFilePathsWithContents; } - foreach ($addedFilesWithNodes as $addedFileWithNodes) { - $fileContent = $nodesWithFileDestinationPrinter->printNodesWithFileDestination($addedFileWithNodes); - $addedFilePathsWithContents[] = new AddedFileWithContent($addedFileWithNodes->getFilePath(), $fileContent); + foreach ($addedFilesWithNodes as $addedFileWithNode) { + $fileContent = $nodesWithFileDestinationPrinter->printNodesWithFileDestination($addedFileWithNode); + $addedFilePathsWithContents[] = new AddedFileWithContent($addedFileWithNode->getFilePath(), $fileContent); } return $addedFilePathsWithContents; diff --git a/phpstan.neon b/phpstan.neon index accf02ede67..416d1e4c2b6 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -158,7 +158,7 @@ parameters: paths: - packages/Caching/ValueObject/Storage/FileCacheStorage.php - - message: '#"@\\rename\(\$tmpPath, \$path\)" is forbidden to use#' + message: '#"@\\rename(.*?)" is forbidden to use#' paths: - packages/Caching/ValueObject/Storage/FileCacheStorage.php - diff --git a/rector.php b/rector.php index 16ef534a33c..e814b006735 100644 --- a/rector.php +++ b/rector.php @@ -88,6 +88,9 @@ \Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector::class => [ __DIR__ . '/src/DependencyInjection', ], + \Rector\Strict\Rector\Ternary\DisallowedShortTernaryRuleFixerRector::class => [ + __DIR__ . '/src/DependencyInjection', + ], ]); $rectorConfig->phpstanConfig(__DIR__ . '/phpstan-for-rector.neon');