From 7ca5096c12deb3d0619bfcf3ed61b0b6e6737b35 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 29 Jul 2022 23:24:58 +0700 Subject: [PATCH] [Php56] Skip already initialized on next Stmt on AddDefaultValueForUndefinedVariableRector (#2721) * [Php56] Skip already initialized on next Stmt on AddDefaultValueForUndefinedVariableRector * Fixed :tada: * [ci-review] Rector Rectify * clean up * phpstan Co-authored-by: GitHub Action --- .../DoctrineAnnotationDecorator.php | 2 +- .../TypeAnalyzer/MethodTypeAnalyzer.php | 4 +-- .../Rector/ClassRenamingPostRector.php | 2 +- .../Rector/NameImportingPostRector.php | 2 +- .../Rector/NodeRemovingPostRector.php | 2 +- .../Rector/PropertyAddingPostRector.php | 2 +- .../PostRector/Rector/UseAddingPostRector.php | 2 +- .../skip_already_initialized_next.php.inc | 23 +++++++++++++ ...tionArgumentDefaultValueReplacerRector.php | 2 +- .../RemoveMethodCallParamRector.php | 4 +-- .../SplitListAssignToSeparateLineRector.php | 2 +- .../Expression/InlineIfToExplicitIfRector.php | 2 +- .../ForRepeatedCountToOwnVariableRector.php | 2 +- .../UnusedForeachValueToArrayKeysRector.php | 2 +- .../FuncCall/AddPregQuoteDelimiterRector.php | 2 +- ...ayKeysAndInArrayToArrayKeyExistsRector.php | 2 +- ...rayMergeOfNonArraysToSimpleArrayRector.php | 2 +- .../ChangeArrayPushToArrayAssignRector.php | 2 +- .../FuncCall/IntvalToTypeCastRector.php | 2 +- ...OnPropertyObjectToPropertyExistsRector.php | 2 +- ...istsTernaryThenValueToCoalescingRector.php | 2 +- .../ConsistentPregDelimiterRector.php | 2 +- ...CountArrayToEmptyArrayComparisonRector.php | 2 +- .../AddFalseDefaultToBoolPropertyRector.php | 2 +- .../InlineSimplePropertyAnnotationRector.php | 2 +- .../Use_/SeparateMultiUseImportsRector.php | 2 +- .../Rector/RemovePackageComposerRector.php | 4 +-- .../RemoveUnusedVariableAssignRector.php | 2 +- ...RemoveUnusedPrivateClassConstantRector.php | 2 +- .../ClassLike/RemoveAnnotationRector.php | 4 +-- .../RemovePhpVersionIdCheckRector.php | 4 +-- .../RemoveDuplicatedIfReturnRector.php | 2 +- ...UnusedNonEmptyArrayBeforeForeachRector.php | 2 +- ...wrapFutureCompatibleIfPhpVersionRector.php | 2 +- .../RemoveUnusedPrivatePropertyRector.php | 2 +- ...naryToBooleanOrFalseToBooleanAndRector.php | 2 +- .../TryCatch/RemoveDeadTryCatchRector.php | 2 +- ...eNestedForeachIfsToEarlyContinueRector.php | 2 +- ...geIfElseValueAssignToEarlyReturnRector.php | 2 +- .../Rector/If_/RemoveAlwaysElseRector.php | 2 +- .../MysqlQueryMysqlErrorWithLinkRector.php | 2 +- ...iableToMatchMethodCallReturnTypeRector.php | 2 +- .../RenameParamToMatchTypeRector.php | 2 +- .../RenameVariableToMatchNewTypeRector.php | 2 +- .../StringClassNameToClassConstantRector.php | 2 +- ...DefaultValueForUndefinedVariableRector.php | 34 ++++++++++++++++--- .../Rector/Name/ReservedObjectRector.php | 4 +-- ...eReflectionTypeToStringToGetNameRector.php | 2 +- ...efaultNullToNullableTypePropertyRector.php | 2 +- .../Rector/Property/TypedPropertyRector.php | 2 +- .../RemoveUnusedVariableInCatchRector.php | 2 +- ...AddParamBasedOnParentClassMethodRector.php | 2 +- .../FinalPrivateToPrivateVisibilityRector.php | 2 +- .../ClassMethod/SetStateToStaticRector.php | 2 +- ...ertyAssignToConstructorPromotionRector.php | 2 +- .../Class_/StringableForToStringRector.php | 2 +- .../Rector/FuncCall/ClassOnObjectRector.php | 2 +- .../Php8ResourceReturnToObjectRector.php | 2 +- .../FuncCall/TokenGetAllToObjectRector.php | 2 +- .../Rector/FunctionLike/MixedTypeRector.php | 2 +- .../Rector/FunctionLike/UnionTypesRector.php | 2 +- .../Rector/Identical/StrEndsWithRector.php | 2 +- .../Rector/Identical/StrStartsWithRector.php | 2 +- .../Rector/NotIdentical/StrContainsRector.php | 2 +- .../Rector/Ternary/GetDebugTypeRector.php | 2 +- .../NullToStrictStringFuncCallArgRector.php | 2 +- .../Php81ResourceReturnToObjectRector.php | 2 +- .../PrivatizeFinalClassMethodRector.php | 2 +- ...hangeGlobalVariablesToPropertiesRector.php | 2 +- ...riableWithDefaultValueToConstantRector.php | 2 +- .../PrivatizeLocalGetterToPropertyRector.php | 2 +- .../ReplaceStringWithClassConstantRector.php | 4 +-- ...opertyWithDefaultValueToConstantRector.php | 2 +- .../PrivatizeFinalClassPropertyRector.php | 2 +- .../Rector/Class_/RemoveTraitUseRector.php | 2 +- .../Rector/String_/RenameStringRector.php | 4 +-- .../Class_/RemoveFinalFromEntityRector.php | 2 +- ...keTypedPropertyNullableIfCheckedRector.php | 2 +- .../BooleanInBooleanNotRuleFixerRector.php | 2 +- .../Empty_/DisallowedEmptyRuleFixerRector.php | 2 +- .../BooleanInIfConditionRuleFixerRector.php | 2 +- ...ooleanInTernaryOperatorRuleFixerRector.php | 4 +-- .../DisallowedShortTernaryRuleFixerRector.php | 2 +- .../DimFetchAssignToMethodCallRector.php | 4 +-- .../AttributeKeyToClassConstFetchRector.php | 4 +-- .../ReturnTypeWillChangeRector.php | 4 +-- ...dAllowDynamicPropertiesAttributeRector.php | 4 +-- .../Class_/AddInterfaceByTraitRector.php | 4 +-- ...eAllowDynamicPropertiesAttributeRector.php | 4 +-- .../Rector/FuncCall/FuncCallToNewRector.php | 2 +- ...ontentsAndJsonDecodeToStaticCallRector.php | 4 +-- .../MethodCallToStaticCallRector.php | 4 +-- .../Rector/New_/NewArgToMethodCallRector.php | 4 +-- .../StaticCallToMethodCallRector.php | 4 +-- .../StaticCall/StaticCallToNewRector.php | 4 +-- .../AddParamTypeDeclarationRector.php | 4 +-- ...larationBasedOnParentClassMethodRector.php | 2 +- ...rrayShapeFromConstantArrayReturnRector.php | 2 +- .../ParamTypeByMethodCallTypeRector.php | 2 +- .../AddPropertyTypeDeclarationRector.php | 2 +- .../TypedPropertyFromAssignsRector.php | 2 +- .../ChangeConstantVisibilityRector.php | 4 +-- .../ChangeMethodVisibilityRector.php | 2 +- .../Rector/RenameClassNonPhpRector.php | 4 +-- 104 files changed, 177 insertions(+), 130 deletions(-) create mode 100644 rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/Fixture/skip_already_initialized_next.php.inc diff --git a/packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php b/packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php index b8b784ded9c..a44af153d2d 100644 --- a/packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php +++ b/packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php @@ -227,7 +227,7 @@ private function isClosedContent(string $composedContent): bool $composedTokenIterator->isCurrentTokenType( Lexer::TOKEN_CLOSE_CURLY_BRACKET, Lexer::TOKEN_CLOSE_PARENTHESES - // sometimes it gets mixed int ") + // sometimes it gets mixed int ") ) || \str_contains($composedTokenIterator->currentTokenValue(), ')')) { ++$closeBracketCount; } diff --git a/packages/NodeTypeResolver/TypeAnalyzer/MethodTypeAnalyzer.php b/packages/NodeTypeResolver/TypeAnalyzer/MethodTypeAnalyzer.php index 8913b8502cf..b068582c555 100644 --- a/packages/NodeTypeResolver/TypeAnalyzer/MethodTypeAnalyzer.php +++ b/packages/NodeTypeResolver/TypeAnalyzer/MethodTypeAnalyzer.php @@ -37,8 +37,8 @@ public function isCallTo(MethodCall $methodCall, string $expectedClass, string $ private function isMethodName(MethodCall $methodCall, string $expectedName): bool { if ( - $methodCall->name instanceof Identifier - && $this->areMethodNamesEqual($methodCall->name->toString(), $expectedName) + $methodCall->name instanceof Identifier + && $this->areMethodNamesEqual($methodCall->name->toString(), $expectedName) ) { return true; } diff --git a/packages/PostRector/Rector/ClassRenamingPostRector.php b/packages/PostRector/Rector/ClassRenamingPostRector.php index e585eada4bf..ae45428c468 100644 --- a/packages/PostRector/Rector/ClassRenamingPostRector.php +++ b/packages/PostRector/Rector/ClassRenamingPostRector.php @@ -43,7 +43,7 @@ function (OriginalClass $someClass) { } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' function (RenamedClass $someClass) { diff --git a/packages/PostRector/Rector/NameImportingPostRector.php b/packages/PostRector/Rector/NameImportingPostRector.php index 270e4281609..2434f88308b 100644 --- a/packages/PostRector/Rector/NameImportingPostRector.php +++ b/packages/PostRector/Rector/NameImportingPostRector.php @@ -79,7 +79,7 @@ public function run(App\AnotherClass $anotherClass) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' use App\AnotherClass; diff --git a/packages/PostRector/Rector/NodeRemovingPostRector.php b/packages/PostRector/Rector/NodeRemovingPostRector.php index 5364f6112f3..f5533da225b 100644 --- a/packages/PostRector/Rector/NodeRemovingPostRector.php +++ b/packages/PostRector/Rector/NodeRemovingPostRector.php @@ -103,7 +103,7 @@ public function run($value) } } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/packages/PostRector/Rector/PropertyAddingPostRector.php b/packages/PostRector/Rector/PropertyAddingPostRector.php index bca19f3627d..2c28db07bb5 100644 --- a/packages/PostRector/Rector/PropertyAddingPostRector.php +++ b/packages/PostRector/Rector/PropertyAddingPostRector.php @@ -65,7 +65,7 @@ public function run() } } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/packages/PostRector/Rector/UseAddingPostRector.php b/packages/PostRector/Rector/UseAddingPostRector.php index 22e4a0c2f3e..3ca2ed6ca99 100644 --- a/packages/PostRector/Rector/UseAddingPostRector.php +++ b/packages/PostRector/Rector/UseAddingPostRector.php @@ -105,7 +105,7 @@ public function run(AnotherClass $anotherClass) } } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' use App\AnotherClass; diff --git a/rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/Fixture/skip_already_initialized_next.php.inc b/rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/Fixture/skip_already_initialized_next.php.inc new file mode 100644 index 00000000000..73ab351f298 --- /dev/null +++ b/rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/Fixture/skip_already_initialized_next.php.inc @@ -0,0 +1,23 @@ + '#', ] diff --git a/rules/CodingStyle/Rector/FuncCall/CountArrayToEmptyArrayComparisonRector.php b/rules/CodingStyle/Rector/FuncCall/CountArrayToEmptyArrayComparisonRector.php index 8fadf07cefc..05e8b688643 100644 --- a/rules/CodingStyle/Rector/FuncCall/CountArrayToEmptyArrayComparisonRector.php +++ b/rules/CodingStyle/Rector/FuncCall/CountArrayToEmptyArrayComparisonRector.php @@ -39,7 +39,7 @@ public function getRuleDefinition(): RuleDefinition count($array) > 0; ! count($array); CODE_SAMPLE -, + , <<<'CODE_SAMPLE' $array === []; $array !== []; diff --git a/rules/CodingStyle/Rector/Property/AddFalseDefaultToBoolPropertyRector.php b/rules/CodingStyle/Rector/Property/AddFalseDefaultToBoolPropertyRector.php index 5f0eeb773f5..688dc3abd6f 100644 --- a/rules/CodingStyle/Rector/Property/AddFalseDefaultToBoolPropertyRector.php +++ b/rules/CodingStyle/Rector/Property/AddFalseDefaultToBoolPropertyRector.php @@ -39,7 +39,7 @@ class SomeClass private $isDisabled; } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector.php b/rules/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector.php index a1741a842a9..fbe2d3ed2df 100644 --- a/rules/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector.php +++ b/rules/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector.php @@ -62,7 +62,7 @@ final class SomeClass private ?array $dateTimes; } CODE_SAMPLE -, + , ['var', 'phpstan-var'], ), ] diff --git a/rules/CodingStyle/Rector/Use_/SeparateMultiUseImportsRector.php b/rules/CodingStyle/Rector/Use_/SeparateMultiUseImportsRector.php index 8c7e8048aef..33020bcbf07 100644 --- a/rules/CodingStyle/Rector/Use_/SeparateMultiUseImportsRector.php +++ b/rules/CodingStyle/Rector/Use_/SeparateMultiUseImportsRector.php @@ -30,7 +30,7 @@ class SomeClass use SomeTrait, AnotherTrait; } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' use A; use B; diff --git a/rules/Composer/Rector/RemovePackageComposerRector.php b/rules/Composer/Rector/RemovePackageComposerRector.php index 3a03c08c514..c066c22d828 100644 --- a/rules/Composer/Rector/RemovePackageComposerRector.php +++ b/rules/Composer/Rector/RemovePackageComposerRector.php @@ -38,12 +38,12 @@ public function getRuleDefinition(): RuleDefinition } } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' { } CODE_SAMPLE - , + , ['symfony/console'] ), ]); diff --git a/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php b/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php index c32207569c3..60ee07769c8 100644 --- a/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php +++ b/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php @@ -58,7 +58,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/DeadCode/Rector/ClassConst/RemoveUnusedPrivateClassConstantRector.php b/rules/DeadCode/Rector/ClassConst/RemoveUnusedPrivateClassConstantRector.php index c633b4839aa..d19a5494e27 100644 --- a/rules/DeadCode/Rector/ClassConst/RemoveUnusedPrivateClassConstantRector.php +++ b/rules/DeadCode/Rector/ClassConst/RemoveUnusedPrivateClassConstantRector.php @@ -40,7 +40,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/DeadCode/Rector/ClassLike/RemoveAnnotationRector.php b/rules/DeadCode/Rector/ClassLike/RemoveAnnotationRector.php index ce9655795ac..421f573f53b 100644 --- a/rules/DeadCode/Rector/ClassLike/RemoveAnnotationRector.php +++ b/rules/DeadCode/Rector/ClassLike/RemoveAnnotationRector.php @@ -44,13 +44,13 @@ final class SomeClass { } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' final class SomeClass { } CODE_SAMPLE -, + , ['method'], ), ]); diff --git a/rules/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector.php b/rules/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector.php index 3cc35f27b40..bb990749e98 100644 --- a/rules/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector.php +++ b/rules/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector.php @@ -76,7 +76,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { @@ -86,7 +86,7 @@ public function run() } } CODE_SAMPLE -, + , [PhpVersion::PHP_80] ), ], diff --git a/rules/DeadCode/Rector/FunctionLike/RemoveDuplicatedIfReturnRector.php b/rules/DeadCode/Rector/FunctionLike/RemoveDuplicatedIfReturnRector.php index ea72dcc5368..12ebd7b9171 100644 --- a/rules/DeadCode/Rector/FunctionLike/RemoveDuplicatedIfReturnRector.php +++ b/rules/DeadCode/Rector/FunctionLike/RemoveDuplicatedIfReturnRector.php @@ -63,7 +63,7 @@ public function run($value) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/DeadCode/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php b/rules/DeadCode/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php index 9ad3a1cdc43..202f3c5ca7e 100644 --- a/rules/DeadCode/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php +++ b/rules/DeadCode/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php @@ -51,7 +51,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/DeadCode/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php b/rules/DeadCode/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php index 750b769da17..6895dec79ae 100644 --- a/rules/DeadCode/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php +++ b/rules/DeadCode/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php @@ -41,7 +41,7 @@ public function getRuleDefinition(): RuleDefinition return 'is PHP 7.2+'; } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' // current PHP: 7.2 return 'is PHP 7.2+'; diff --git a/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php b/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php index 3d305237a1c..ad4bfb681d0 100644 --- a/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php +++ b/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php @@ -63,7 +63,7 @@ class SomeClass { } CODE_SAMPLE -, + , [ self::REMOVE_ASSIGN_SIDE_EFFECT => true, ] diff --git a/rules/DeadCode/Rector/Ternary/TernaryToBooleanOrFalseToBooleanAndRector.php b/rules/DeadCode/Rector/Ternary/TernaryToBooleanOrFalseToBooleanAndRector.php index 9c6c486b37f..2f3859b5626 100644 --- a/rules/DeadCode/Rector/Ternary/TernaryToBooleanOrFalseToBooleanAndRector.php +++ b/rules/DeadCode/Rector/Ternary/TernaryToBooleanOrFalseToBooleanAndRector.php @@ -35,7 +35,7 @@ private function getBool(): bool } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/DeadCode/Rector/TryCatch/RemoveDeadTryCatchRector.php b/rules/DeadCode/Rector/TryCatch/RemoveDeadTryCatchRector.php index 2738ce8ce3c..15f36d24ef8 100644 --- a/rules/DeadCode/Rector/TryCatch/RemoveDeadTryCatchRector.php +++ b/rules/DeadCode/Rector/TryCatch/RemoveDeadTryCatchRector.php @@ -37,7 +37,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/EarlyReturn/Rector/Foreach_/ChangeNestedForeachIfsToEarlyContinueRector.php b/rules/EarlyReturn/Rector/Foreach_/ChangeNestedForeachIfsToEarlyContinueRector.php index 24b0b32d7fb..fb114521b7b 100644 --- a/rules/EarlyReturn/Rector/Foreach_/ChangeNestedForeachIfsToEarlyContinueRector.php +++ b/rules/EarlyReturn/Rector/Foreach_/ChangeNestedForeachIfsToEarlyContinueRector.php @@ -53,7 +53,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/EarlyReturn/Rector/If_/ChangeIfElseValueAssignToEarlyReturnRector.php b/rules/EarlyReturn/Rector/If_/ChangeIfElseValueAssignToEarlyReturnRector.php index 479ac3b5405..0f1186b20d0 100644 --- a/rules/EarlyReturn/Rector/If_/ChangeIfElseValueAssignToEarlyReturnRector.php +++ b/rules/EarlyReturn/Rector/If_/ChangeIfElseValueAssignToEarlyReturnRector.php @@ -50,7 +50,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/EarlyReturn/Rector/If_/RemoveAlwaysElseRector.php b/rules/EarlyReturn/Rector/If_/RemoveAlwaysElseRector.php index c2249a70a5d..52fbbc5521f 100644 --- a/rules/EarlyReturn/Rector/If_/RemoveAlwaysElseRector.php +++ b/rules/EarlyReturn/Rector/If_/RemoveAlwaysElseRector.php @@ -41,7 +41,7 @@ public function run($value) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/MysqlToMysqli/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php b/rules/MysqlToMysqli/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php index f48ca1250eb..cce1d1b38b4 100644 --- a/rules/MysqlToMysqli/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php +++ b/rules/MysqlToMysqli/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php @@ -93,7 +93,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector.php b/rules/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector.php index 7242905c4bb..24405c60449 100644 --- a/rules/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector.php +++ b/rules/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector.php @@ -61,7 +61,7 @@ public function getRunner(): Runner } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector.php b/rules/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector.php index 482b4ace4a4..eb84fd9cdd0 100644 --- a/rules/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector.php +++ b/rules/Naming/Rector/ClassMethod/RenameParamToMatchTypeRector.php @@ -49,7 +49,7 @@ public function run(Apple $pie) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' final class SomeClass { diff --git a/rules/Naming/Rector/ClassMethod/RenameVariableToMatchNewTypeRector.php b/rules/Naming/Rector/ClassMethod/RenameVariableToMatchNewTypeRector.php index 6022556824f..0c1a364457f 100644 --- a/rules/Naming/Rector/ClassMethod/RenameVariableToMatchNewTypeRector.php +++ b/rules/Naming/Rector/ClassMethod/RenameVariableToMatchNewTypeRector.php @@ -42,7 +42,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' final class SomeClass { diff --git a/rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php b/rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php index 57f76994da2..77ec3af1721 100644 --- a/rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php +++ b/rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php @@ -73,7 +73,7 @@ public function run() } } CODE_SAMPLE -, + , ['ClassName', 'AnotherClassName'], ), ]); diff --git a/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php b/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php index 640de2c174c..70934c5e33d 100644 --- a/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php +++ b/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php @@ -92,25 +92,49 @@ public function refactor(Node $node): ?Node return null; } + if ($node->stmts === null) { + return null; + } + $undefinedVariableNames = $this->undefinedVariableResolver->resolve($node); if ($undefinedVariableNames === []) { return null; } + $variablesInitiation = $this->collectVariablesInitiation($undefinedVariableNames, $node->stmts); + $node->stmts = array_merge($variablesInitiation, $node->stmts); + + return $node; + } + + /** + * @param string[] $undefinedVariableNames + * @param Stmt[] $stmts + * @return Expression[] + */ + private function collectVariablesInitiation(array $undefinedVariableNames, array $stmts): array + { $variablesInitiation = []; + foreach ($undefinedVariableNames as $undefinedVariableName) { - $value = $this->isArray($undefinedVariableName, (array) $node->stmts) + $value = $this->isArray($undefinedVariableName, $stmts) ? new Array_([]) : $this->nodeFactory->createNull(); $assign = new Assign(new Variable($undefinedVariableName), $value); - $variablesInitiation[] = new Expression($assign); - } + $expresssion = new Expression($assign); - $node->stmts = array_merge($variablesInitiation, (array) $node->stmts); + foreach ($stmts as $stmt) { + if ($this->nodeComparator->areNodesEqual($expresssion, $stmt)) { + continue 2; + } + } - return $node; + $variablesInitiation[] = $expresssion; + } + + return $variablesInitiation; } /** diff --git a/rules/Php71/Rector/Name/ReservedObjectRector.php b/rules/Php71/Rector/Name/ReservedObjectRector.php index d4eb8dbf8c5..39a550ceed2 100644 --- a/rules/Php71/Rector/Name/ReservedObjectRector.php +++ b/rules/Php71/Rector/Name/ReservedObjectRector.php @@ -45,13 +45,13 @@ class Object { } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' class SmartObject { } CODE_SAMPLE - , + , [ 'ReservedObject' => 'SmartObject', 'Object' => 'AnotherSmartObject', diff --git a/rules/Php74/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector.php b/rules/Php74/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector.php index 3ef1dbf38cd..0762e1e0d18 100644 --- a/rules/Php74/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector.php +++ b/rules/Php74/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector.php @@ -66,7 +66,7 @@ public function go(ReflectionFunction $reflectionFunction) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php74/Rector/Property/RestoreDefaultNullToNullableTypePropertyRector.php b/rules/Php74/Rector/Property/RestoreDefaultNullToNullableTypePropertyRector.php index 3ad1dba620a..e0541c194f1 100644 --- a/rules/Php74/Rector/Property/RestoreDefaultNullToNullableTypePropertyRector.php +++ b/rules/Php74/Rector/Property/RestoreDefaultNullToNullableTypePropertyRector.php @@ -35,7 +35,7 @@ class SomeClass public ?string $name; } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php74/Rector/Property/TypedPropertyRector.php b/rules/Php74/Rector/Property/TypedPropertyRector.php index 0c62042aa3b..dc0aed68c38 100644 --- a/rules/Php74/Rector/Property/TypedPropertyRector.php +++ b/rules/Php74/Rector/Property/TypedPropertyRector.php @@ -95,7 +95,7 @@ final class SomeClass private bool $isDone = false; } CODE_SAMPLE - , + , [ self::INLINE_PUBLIC => false, ] diff --git a/rules/Php80/Rector/Catch_/RemoveUnusedVariableInCatchRector.php b/rules/Php80/Rector/Catch_/RemoveUnusedVariableInCatchRector.php index 563d3748f90..8aa50da541a 100644 --- a/rules/Php80/Rector/Catch_/RemoveUnusedVariableInCatchRector.php +++ b/rules/Php80/Rector/Catch_/RemoveUnusedVariableInCatchRector.php @@ -41,7 +41,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' final class SomeClass { diff --git a/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php b/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php index 6ade3c27052..082f99f435f 100644 --- a/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php +++ b/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php @@ -61,7 +61,7 @@ public function execute() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class A { diff --git a/rules/Php80/Rector/ClassMethod/FinalPrivateToPrivateVisibilityRector.php b/rules/Php80/Rector/ClassMethod/FinalPrivateToPrivateVisibilityRector.php index 7a9efe0ed39..c2c544e17aa 100644 --- a/rules/Php80/Rector/ClassMethod/FinalPrivateToPrivateVisibilityRector.php +++ b/rules/Php80/Rector/ClassMethod/FinalPrivateToPrivateVisibilityRector.php @@ -41,7 +41,7 @@ final private function getter() { } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php80/Rector/ClassMethod/SetStateToStaticRector.php b/rules/Php80/Rector/ClassMethod/SetStateToStaticRector.php index 2c2a66a9d89..ee4b7677875 100644 --- a/rules/Php80/Rector/ClassMethod/SetStateToStaticRector.php +++ b/rules/Php80/Rector/ClassMethod/SetStateToStaticRector.php @@ -41,7 +41,7 @@ public function __set_state($properties) { } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php b/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php index e1818115d7e..dce30f65410 100644 --- a/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php +++ b/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php @@ -65,7 +65,7 @@ public function __construct( } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php80/Rector/Class_/StringableForToStringRector.php b/rules/Php80/Rector/Class_/StringableForToStringRector.php index 352be288fc2..1edbc5da0df 100644 --- a/rules/Php80/Rector/Class_/StringableForToStringRector.php +++ b/rules/Php80/Rector/Class_/StringableForToStringRector.php @@ -63,7 +63,7 @@ public function __toString() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass implements Stringable { diff --git a/rules/Php80/Rector/FuncCall/ClassOnObjectRector.php b/rules/Php80/Rector/FuncCall/ClassOnObjectRector.php index a6d520d13ab..c54ae55f424 100644 --- a/rules/Php80/Rector/FuncCall/ClassOnObjectRector.php +++ b/rules/Php80/Rector/FuncCall/ClassOnObjectRector.php @@ -37,7 +37,7 @@ public function run($object) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php80/Rector/FuncCall/Php8ResourceReturnToObjectRector.php b/rules/Php80/Rector/FuncCall/Php8ResourceReturnToObjectRector.php index c5411fd7198..756e8878ee2 100644 --- a/rules/Php80/Rector/FuncCall/Php8ResourceReturnToObjectRector.php +++ b/rules/Php80/Rector/FuncCall/Php8ResourceReturnToObjectRector.php @@ -111,7 +111,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php80/Rector/FuncCall/TokenGetAllToObjectRector.php b/rules/Php80/Rector/FuncCall/TokenGetAllToObjectRector.php index a05c83a0027..c06d36070e8 100644 --- a/rules/Php80/Rector/FuncCall/TokenGetAllToObjectRector.php +++ b/rules/Php80/Rector/FuncCall/TokenGetAllToObjectRector.php @@ -65,7 +65,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' final class SomeClass { diff --git a/rules/Php80/Rector/FunctionLike/MixedTypeRector.php b/rules/Php80/Rector/FunctionLike/MixedTypeRector.php index 6e6807cfa77..a7cf5a26b66 100644 --- a/rules/Php80/Rector/FunctionLike/MixedTypeRector.php +++ b/rules/Php80/Rector/FunctionLike/MixedTypeRector.php @@ -54,7 +54,7 @@ public function run($param) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php80/Rector/FunctionLike/UnionTypesRector.php b/rules/Php80/Rector/FunctionLike/UnionTypesRector.php index 194092450b9..4dff7f785d9 100644 --- a/rules/Php80/Rector/FunctionLike/UnionTypesRector.php +++ b/rules/Php80/Rector/FunctionLike/UnionTypesRector.php @@ -68,7 +68,7 @@ public function go($number) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php80/Rector/Identical/StrEndsWithRector.php b/rules/Php80/Rector/Identical/StrEndsWithRector.php index d4a6911e271..06614eca340 100644 --- a/rules/Php80/Rector/Identical/StrEndsWithRector.php +++ b/rules/Php80/Rector/Identical/StrEndsWithRector.php @@ -57,7 +57,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php80/Rector/Identical/StrStartsWithRector.php b/rules/Php80/Rector/Identical/StrStartsWithRector.php index 89b74fe57dd..3d03d3c8948 100644 --- a/rules/Php80/Rector/Identical/StrStartsWithRector.php +++ b/rules/Php80/Rector/Identical/StrStartsWithRector.php @@ -55,7 +55,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php80/Rector/NotIdentical/StrContainsRector.php b/rules/Php80/Rector/NotIdentical/StrContainsRector.php index 8d82dc3e1d6..2a1b6519852 100644 --- a/rules/Php80/Rector/NotIdentical/StrContainsRector.php +++ b/rules/Php80/Rector/NotIdentical/StrContainsRector.php @@ -48,7 +48,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php80/Rector/Ternary/GetDebugTypeRector.php b/rules/Php80/Rector/Ternary/GetDebugTypeRector.php index b498f951719..09812bbce5b 100644 --- a/rules/Php80/Rector/Ternary/GetDebugTypeRector.php +++ b/rules/Php80/Rector/Ternary/GetDebugTypeRector.php @@ -41,7 +41,7 @@ public function run($value) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php b/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php index 54bec9cbe4a..0d1f3e5273e 100644 --- a/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php +++ b/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php @@ -295,7 +295,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Php81/Rector/FuncCall/Php81ResourceReturnToObjectRector.php b/rules/Php81/Rector/FuncCall/Php81ResourceReturnToObjectRector.php index 44718cfc70a..bdbefb16fe1 100644 --- a/rules/Php81/Rector/FuncCall/Php81ResourceReturnToObjectRector.php +++ b/rules/Php81/Rector/FuncCall/Php81ResourceReturnToObjectRector.php @@ -76,7 +76,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Privatization/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php b/rules/Privatization/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php index 21e1211f97c..4afa8224224 100644 --- a/rules/Privatization/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php +++ b/rules/Privatization/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php @@ -40,7 +40,7 @@ protected function someMethod() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' final class SomeClass { diff --git a/rules/Privatization/Rector/Class_/ChangeGlobalVariablesToPropertiesRector.php b/rules/Privatization/Rector/Class_/ChangeGlobalVariablesToPropertiesRector.php index 018721b3f76..7c8c4a61c74 100644 --- a/rules/Privatization/Rector/Class_/ChangeGlobalVariablesToPropertiesRector.php +++ b/rules/Privatization/Rector/Class_/ChangeGlobalVariablesToPropertiesRector.php @@ -57,7 +57,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Privatization/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php b/rules/Privatization/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php index 5f9fd61f5ac..91c138f1ddd 100644 --- a/rules/Privatization/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php +++ b/rules/Privatization/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php @@ -58,7 +58,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php b/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php index 7a6635c6bb0..831bf9c1f2c 100644 --- a/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php +++ b/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php @@ -42,7 +42,7 @@ private function getSome() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Privatization/Rector/MethodCall/ReplaceStringWithClassConstantRector.php b/rules/Privatization/Rector/MethodCall/ReplaceStringWithClassConstantRector.php index 81ffbcbafc1..842ffc6471b 100644 --- a/rules/Privatization/Rector/MethodCall/ReplaceStringWithClassConstantRector.php +++ b/rules/Privatization/Rector/MethodCall/ReplaceStringWithClassConstantRector.php @@ -44,7 +44,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { @@ -54,7 +54,7 @@ public function run() } } CODE_SAMPLE -, + , [new ReplaceStringWithClassConstant('SomeClass', 'call', 0, 'Placeholder')] ), ]); diff --git a/rules/Privatization/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector.php b/rules/Privatization/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector.php index 44b39c8b413..e24a3bb02fc 100644 --- a/rules/Privatization/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector.php +++ b/rules/Privatization/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector.php @@ -53,7 +53,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Privatization/Rector/Property/PrivatizeFinalClassPropertyRector.php b/rules/Privatization/Rector/Property/PrivatizeFinalClassPropertyRector.php index 79b78a1d809..d8349739d34 100644 --- a/rules/Privatization/Rector/Property/PrivatizeFinalClassPropertyRector.php +++ b/rules/Privatization/Rector/Property/PrivatizeFinalClassPropertyRector.php @@ -34,7 +34,7 @@ final class SomeClass protected $value; } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' final class SomeClass { diff --git a/rules/Removing/Rector/Class_/RemoveTraitUseRector.php b/rules/Removing/Rector/Class_/RemoveTraitUseRector.php index 7f635d86248..5c8a5e92ccf 100644 --- a/rules/Removing/Rector/Class_/RemoveTraitUseRector.php +++ b/rules/Removing/Rector/Class_/RemoveTraitUseRector.php @@ -42,7 +42,7 @@ class SomeClass { } CODE_SAMPLE -, + , ['TraitNameToRemove'] ), ]); diff --git a/rules/Renaming/Rector/String_/RenameStringRector.php b/rules/Renaming/Rector/String_/RenameStringRector.php index 428251d5fb7..c7e363bd36f 100644 --- a/rules/Renaming/Rector/String_/RenameStringRector.php +++ b/rules/Renaming/Rector/String_/RenameStringRector.php @@ -37,7 +37,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { @@ -47,7 +47,7 @@ public function run() } } CODE_SAMPLE -, + , [ 'ROLE_PREVIOUS_ADMIN' => 'IS_IMPERSONATOR', ] diff --git a/rules/Restoration/Rector/Class_/RemoveFinalFromEntityRector.php b/rules/Restoration/Rector/Class_/RemoveFinalFromEntityRector.php index 572a56883a6..a8da8af6125 100644 --- a/rules/Restoration/Rector/Class_/RemoveFinalFromEntityRector.php +++ b/rules/Restoration/Rector/Class_/RemoveFinalFromEntityRector.php @@ -35,7 +35,7 @@ final class SomeClass { } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' use Doctrine\ORM\Mapping as ORM; diff --git a/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php b/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php index 72177a0e9d2..d1c5f578d6c 100644 --- a/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php +++ b/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php @@ -40,7 +40,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' final class SomeClass { diff --git a/rules/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector.php b/rules/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector.php index 54e49fe83d3..5436da7bee2 100644 --- a/rules/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector.php +++ b/rules/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector.php @@ -48,7 +48,7 @@ public function run(string|null $name) } } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' class SomeClass { diff --git a/rules/Strict/Rector/Empty_/DisallowedEmptyRuleFixerRector.php b/rules/Strict/Rector/Empty_/DisallowedEmptyRuleFixerRector.php index 558cd6fe664..bcbb29f4e6f 100644 --- a/rules/Strict/Rector/Empty_/DisallowedEmptyRuleFixerRector.php +++ b/rules/Strict/Rector/Empty_/DisallowedEmptyRuleFixerRector.php @@ -43,7 +43,7 @@ public function run(array $items) } } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' final class SomeEmptyArray { diff --git a/rules/Strict/Rector/If_/BooleanInIfConditionRuleFixerRector.php b/rules/Strict/Rector/If_/BooleanInIfConditionRuleFixerRector.php index d5b3907b2b1..92ef8ef81b8 100644 --- a/rules/Strict/Rector/If_/BooleanInIfConditionRuleFixerRector.php +++ b/rules/Strict/Rector/If_/BooleanInIfConditionRuleFixerRector.php @@ -49,7 +49,7 @@ public function run(string $name) } } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' final class NegatedString { diff --git a/rules/Strict/Rector/Ternary/BooleanInTernaryOperatorRuleFixerRector.php b/rules/Strict/Rector/Ternary/BooleanInTernaryOperatorRuleFixerRector.php index 58ad5df102b..4041a6113f6 100644 --- a/rules/Strict/Rector/Ternary/BooleanInTernaryOperatorRuleFixerRector.php +++ b/rules/Strict/Rector/Ternary/BooleanInTernaryOperatorRuleFixerRector.php @@ -44,7 +44,7 @@ public function run(array $data) } } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' final class ArrayCompare { @@ -54,7 +54,7 @@ public function run(array $data) } } CODE_SAMPLE - , + , [ self::TREAT_AS_NON_EMPTY => false, ] diff --git a/rules/Strict/Rector/Ternary/DisallowedShortTernaryRuleFixerRector.php b/rules/Strict/Rector/Ternary/DisallowedShortTernaryRuleFixerRector.php index b0b36b8648f..f89bfe3227a 100644 --- a/rules/Strict/Rector/Ternary/DisallowedShortTernaryRuleFixerRector.php +++ b/rules/Strict/Rector/Ternary/DisallowedShortTernaryRuleFixerRector.php @@ -45,7 +45,7 @@ public function run(array $array) } } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' final class ShortTernaryArray { diff --git a/rules/Transform/Rector/Assign/DimFetchAssignToMethodCallRector.php b/rules/Transform/Rector/Assign/DimFetchAssignToMethodCallRector.php index e805c533cef..2375e6f9469 100644 --- a/rules/Transform/Rector/Assign/DimFetchAssignToMethodCallRector.php +++ b/rules/Transform/Rector/Assign/DimFetchAssignToMethodCallRector.php @@ -46,7 +46,7 @@ public static function createRouter() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' use Nette\Application\Routers\RouteList; @@ -59,7 +59,7 @@ public static function createRouter() } } CODE_SAMPLE -, + , [ new DimFetchAssignToMethodCall( 'Nette\Application\Routers\RouteList', diff --git a/rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php b/rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php index 26fc2b38c81..bcd1ada29dd 100644 --- a/rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php +++ b/rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php @@ -39,7 +39,7 @@ class SomeClass public $name; } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' use Doctrine\ORM\Mapping\Column; use Doctrine\DBAL\Types\Types; @@ -50,7 +50,7 @@ class SomeClass public $name; } CODE_SAMPLE -, + , [ new AttributeKeyToClassConstFetch('Doctrine\ORM\Mapping\Column', 'type', 'Doctrine\DBAL\Types\Types', [ 'string' => 'STRING', diff --git a/rules/Transform/Rector/ClassMethod/ReturnTypeWillChangeRector.php b/rules/Transform/Rector/ClassMethod/ReturnTypeWillChangeRector.php index f8231991331..c9bf2e88c98 100644 --- a/rules/Transform/Rector/ClassMethod/ReturnTypeWillChangeRector.php +++ b/rules/Transform/Rector/ClassMethod/ReturnTypeWillChangeRector.php @@ -48,7 +48,7 @@ public function offsetGet($offset) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass implements ArrayAccess { @@ -58,7 +58,7 @@ public function offsetGet($offset) } } CODE_SAMPLE - , + , [ 'ArrayAccess' => ['offsetGet'], ] diff --git a/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php b/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php index db75a652364..b6c2d6eb5cc 100644 --- a/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php +++ b/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php @@ -56,7 +56,7 @@ class SomeObject { public string $someProperty = 'hello world'; } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' namespace Example\Domain; @@ -65,7 +65,7 @@ class SomeObject { public string $someProperty = 'hello world'; } CODE_SAMPLE -, + , ['Example\*'], ), ]); diff --git a/rules/Transform/Rector/Class_/AddInterfaceByTraitRector.php b/rules/Transform/Rector/Class_/AddInterfaceByTraitRector.php index 2fcc33c2be7..eb132ca2f73 100644 --- a/rules/Transform/Rector/Class_/AddInterfaceByTraitRector.php +++ b/rules/Transform/Rector/Class_/AddInterfaceByTraitRector.php @@ -39,14 +39,14 @@ class SomeClass use SomeTrait; } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass implements SomeInterface { use SomeTrait; } CODE_SAMPLE - , + , [ 'SomeTrait' => 'SomeInterface', ] diff --git a/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php b/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php index 9250ac64932..cf8c58f42a2 100644 --- a/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php +++ b/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php @@ -47,7 +47,7 @@ class SomeObject { public string $someProperty = 'hello world'; } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' namespace Example\Domain; @@ -55,7 +55,7 @@ class SomeObject { public string $someProperty = 'hello world'; } CODE_SAMPLE -, + , ['Example\*'] ), ]); diff --git a/rules/Transform/Rector/FuncCall/FuncCallToNewRector.php b/rules/Transform/Rector/FuncCall/FuncCallToNewRector.php index 30bb2374b21..b59f3fee3ef 100644 --- a/rules/Transform/Rector/FuncCall/FuncCallToNewRector.php +++ b/rules/Transform/Rector/FuncCall/FuncCallToNewRector.php @@ -47,7 +47,7 @@ public function run() } } CODE_SAMPLE -, + , [ 'collection' => ['Collection'], ] diff --git a/rules/Transform/Rector/FunctionLike/FileGetContentsAndJsonDecodeToStaticCallRector.php b/rules/Transform/Rector/FunctionLike/FileGetContentsAndJsonDecodeToStaticCallRector.php index a58227f2a4d..9b3ae5eb806 100644 --- a/rules/Transform/Rector/FunctionLike/FileGetContentsAndJsonDecodeToStaticCallRector.php +++ b/rules/Transform/Rector/FunctionLike/FileGetContentsAndJsonDecodeToStaticCallRector.php @@ -41,7 +41,7 @@ public function load($filePath) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' final class SomeClass { @@ -51,7 +51,7 @@ public function load($filePath) } } CODE_SAMPLE -, + , [new StaticCallRecipe('FileLoader', 'loadJson')] ), ]); diff --git a/rules/Transform/Rector/MethodCall/MethodCallToStaticCallRector.php b/rules/Transform/Rector/MethodCall/MethodCallToStaticCallRector.php index da923d28bbc..feb0cffce16 100644 --- a/rules/Transform/Rector/MethodCall/MethodCallToStaticCallRector.php +++ b/rules/Transform/Rector/MethodCall/MethodCallToStaticCallRector.php @@ -43,7 +43,7 @@ public function loadConfiguration() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' final class SomeClass { @@ -60,7 +60,7 @@ public function loadConfiguration() } } CODE_SAMPLE -, + , [new MethodCallToStaticCall('AnotherDependency', 'process', 'StaticCaller', 'anotherMethod')] ), ]); diff --git a/rules/Transform/Rector/New_/NewArgToMethodCallRector.php b/rules/Transform/Rector/New_/NewArgToMethodCallRector.php index 663e424f31f..a104c3722d5 100644 --- a/rules/Transform/Rector/New_/NewArgToMethodCallRector.php +++ b/rules/Transform/Rector/New_/NewArgToMethodCallRector.php @@ -40,7 +40,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { @@ -51,7 +51,7 @@ public function run() } } CODE_SAMPLE -, + , [new NewArgToMethodCall('Dotenv', true, 'usePutenv')] ), ]); diff --git a/rules/Transform/Rector/StaticCall/StaticCallToMethodCallRector.php b/rules/Transform/Rector/StaticCall/StaticCallToMethodCallRector.php index 63b4510d6a8..8c942f3ff1a 100644 --- a/rules/Transform/Rector/StaticCall/StaticCallToMethodCallRector.php +++ b/rules/Transform/Rector/StaticCall/StaticCallToMethodCallRector.php @@ -50,7 +50,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' use Symplify\SmartFileSystem\SmartFileSystem; @@ -72,7 +72,7 @@ public function run() } } CODE_SAMPLE - , + , [ new StaticCallToMethodCall( 'Nette\Utils\FileSystem', diff --git a/rules/Transform/Rector/StaticCall/StaticCallToNewRector.php b/rules/Transform/Rector/StaticCall/StaticCallToNewRector.php index 054cd680916..b10b039bd3b 100644 --- a/rules/Transform/Rector/StaticCall/StaticCallToNewRector.php +++ b/rules/Transform/Rector/StaticCall/StaticCallToNewRector.php @@ -40,7 +40,7 @@ public function run() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { @@ -50,7 +50,7 @@ public function run() } } CODE_SAMPLE -, + , [new StaticCallToNew('JsonResponse', 'create')] ), ]); diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php index d53ee0acef7..8a334001885 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php @@ -54,7 +54,7 @@ public function process($name) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeClass { @@ -63,7 +63,7 @@ public function process(string $name) } } CODE_SAMPLE - , + , [new AddParamTypeDeclaration('SomeClass', 'process', 0, new StringType())] ), ]); diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationBasedOnParentClassMethodRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationBasedOnParentClassMethodRector.php index 4741dc1fc3a..750933a23dc 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationBasedOnParentClassMethodRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationBasedOnParentClassMethodRector.php @@ -59,7 +59,7 @@ public function execute() } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class A { diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ArrayShapeFromConstantArrayReturnRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ArrayShapeFromConstantArrayReturnRector.php index e93d4595b58..d29f0e63b07 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ArrayShapeFromConstantArrayReturnRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ArrayShapeFromConstantArrayReturnRector.php @@ -55,7 +55,7 @@ public function run(string $name) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' final class SomeClass { diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector.php index 2ed434ab8af..8eeb3bd1395 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector.php @@ -66,7 +66,7 @@ public function go($value) } } CODE_SAMPLE -, + , <<<'CODE_SAMPLE' class SomeTypedService { diff --git a/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php b/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php index 03368ce928c..109c0bc5153 100644 --- a/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php +++ b/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php @@ -52,7 +52,7 @@ class SomeClass extends ParentClass public string $name; } CODE_SAMPLE -, + , $configuration ), ]); diff --git a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php index a5e8b26a73f..84fa24b4584 100644 --- a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php +++ b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php @@ -88,7 +88,7 @@ public function run() } } CODE_SAMPLE -, + , [ self::INLINE_PUBLIC => false, ] diff --git a/rules/Visibility/Rector/ClassConst/ChangeConstantVisibilityRector.php b/rules/Visibility/Rector/ClassConst/ChangeConstantVisibilityRector.php index b6aedefce1c..0a25021a5d8 100644 --- a/rules/Visibility/Rector/ClassConst/ChangeConstantVisibilityRector.php +++ b/rules/Visibility/Rector/ClassConst/ChangeConstantVisibilityRector.php @@ -47,7 +47,7 @@ class MyClass extends FrameworkClass public const SOME_CONSTANT = 1; } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' class FrameworkClass { @@ -59,7 +59,7 @@ class MyClass extends FrameworkClass protected const SOME_CONSTANT = 1; } CODE_SAMPLE - , + , [new ChangeConstantVisibility('ParentObject', 'SOME_CONSTANT', Visibility::PROTECTED)] ), ] diff --git a/rules/Visibility/Rector/ClassMethod/ChangeMethodVisibilityRector.php b/rules/Visibility/Rector/ClassMethod/ChangeMethodVisibilityRector.php index f8c5cf64fe5..d35c9a0630a 100644 --- a/rules/Visibility/Rector/ClassMethod/ChangeMethodVisibilityRector.php +++ b/rules/Visibility/Rector/ClassMethod/ChangeMethodVisibilityRector.php @@ -54,7 +54,7 @@ public function someMethod() } } CODE_SAMPLE - , + , <<<'CODE_SAMPLE' class FrameworkClass { diff --git a/src/NonPhpFile/Rector/RenameClassNonPhpRector.php b/src/NonPhpFile/Rector/RenameClassNonPhpRector.php index 48cdd53200a..69d4e662a83 100644 --- a/src/NonPhpFile/Rector/RenameClassNonPhpRector.php +++ b/src/NonPhpFile/Rector/RenameClassNonPhpRector.php @@ -50,12 +50,12 @@ public function getRuleDefinition(): RuleDefinition services: - SomeOldClass CODE_SAMPLE - , + , <<<'CODE_SAMPLE' services: - SomeNewClass CODE_SAMPLE - , + , [ 'SomeOldClass' => 'SomeNewClass', ]