diff --git a/src/NodeAnalyzer/ApplicationAnalyzer.php b/src/NodeAnalyzer/ApplicationAnalyzer.php index 8ca69b9b2..5331e7da8 100644 --- a/src/NodeAnalyzer/ApplicationAnalyzer.php +++ b/src/NodeAnalyzer/ApplicationAnalyzer.php @@ -9,6 +9,9 @@ class ApplicationAnalyzer { private ?string $version = null; + /** + * @param class-string $applicationClass + */ public function __construct( private string $applicationClass = 'Illuminate\Foundation\Application', ) {} @@ -20,6 +23,9 @@ public function setVersion(?string $version): static return $this; } + /** + * @param class-string $applicationClass + */ public function setApplicationClass(string $applicationClass): static { $this->applicationClass = $applicationClass; @@ -27,6 +33,9 @@ public function setApplicationClass(string $applicationClass): static return $this; } + /** + * @return class-string $applicationClass + */ public function getApplicationClass(): string { return $this->applicationClass; diff --git a/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php b/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php index 4964c295f..f882cde10 100644 --- a/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php +++ b/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php @@ -115,6 +115,7 @@ public function refactor(Node $node): ?Node $parentStaticCallExpression = new Expression($staticCall); $node->stmts = array_merge([$parentStaticCallExpression], (array) $node->stmts); + $node->stmts = array_values($node->stmts); return $node; } diff --git a/src/Rector/ClassMethod/AddParentRegisterToEventServiceProviderRector.php b/src/Rector/ClassMethod/AddParentRegisterToEventServiceProviderRector.php index 77f64a925..1e1e55337 100644 --- a/src/Rector/ClassMethod/AddParentRegisterToEventServiceProviderRector.php +++ b/src/Rector/ClassMethod/AddParentRegisterToEventServiceProviderRector.php @@ -111,6 +111,7 @@ public function refactor(Node $node): ?Node $parentStaticCallExpression = new Expression($staticCall); $node->stmts = array_merge([$parentStaticCallExpression], (array) $node->stmts); + $node->stmts = array_values($node->stmts); return $node; } diff --git a/src/Rector/ClassMethod/MigrateToSimplifiedAttributeRector.php b/src/Rector/ClassMethod/MigrateToSimplifiedAttributeRector.php index fce75542b..ec939dba7 100644 --- a/src/Rector/ClassMethod/MigrateToSimplifiedAttributeRector.php +++ b/src/Rector/ClassMethod/MigrateToSimplifiedAttributeRector.php @@ -77,10 +77,13 @@ public function refactor(Node $node): ?Node } } - return $hasChanged - ? $node - : null; + if ($hasChanged) { + $node->stmts = array_values($node->stmts); + return $node; + } + + return null; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rector/Class_/ModelCastsPropertyToCastsMethodRector.php b/src/Rector/Class_/ModelCastsPropertyToCastsMethodRector.php index eae705cac..036dbe490 100644 --- a/src/Rector/Class_/ModelCastsPropertyToCastsMethodRector.php +++ b/src/Rector/Class_/ModelCastsPropertyToCastsMethodRector.php @@ -100,6 +100,7 @@ public function refactor(Node $node): ?Class_ $method->addStmt(new Return_($stmt->props[0]->default)); $methodNode = $method->getNode(); $node->stmts[] = $methodNode; + $node->stmts = array_values($node->stmts); $this->restorePhpDoc($methodNode); diff --git a/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php b/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php index d34d7c472..806476afd 100644 --- a/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php +++ b/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php @@ -80,6 +80,7 @@ public function refactor(Node $node): ?Node } unset($node->stmts[array_search($deferProperty, $node->stmts, true)]); + $node->stmts = array_values($node->stmts); $node->implements[] = new FullyQualified('Illuminate\Contracts\Support\DeferrableProvider'); diff --git a/src/Rector/Class_/RemoveModelPropertyFromFactoriesRector.php b/src/Rector/Class_/RemoveModelPropertyFromFactoriesRector.php index 4822cff21..866c20a4f 100644 --- a/src/Rector/Class_/RemoveModelPropertyFromFactoriesRector.php +++ b/src/Rector/Class_/RemoveModelPropertyFromFactoriesRector.php @@ -71,6 +71,7 @@ public function refactor(Node $node): ?Node } unset($node->stmts[$index]); + $node->stmts = array_values($node->stmts); break; } diff --git a/src/Rector/Class_/UnifyModelDatesWithCastsRector.php b/src/Rector/Class_/UnifyModelDatesWithCastsRector.php index c8db04e6e..dec12a53e 100644 --- a/src/Rector/Class_/UnifyModelDatesWithCastsRector.php +++ b/src/Rector/Class_/UnifyModelDatesWithCastsRector.php @@ -76,7 +76,7 @@ public function getNodeTypes(): array /** * @param Class_ $node */ - public function refactor(Node $node) + public function refactor(Node $node): ?Node { if (! $this->isObjectType($node, new ObjectType('Illuminate\Database\Eloquent\Model'))) { return null; @@ -128,8 +128,9 @@ public function refactor(Node $node) } unset($node->stmts[array_search($datesProperty, $node->stmts, true)]); + $node->stmts = array_values($node->stmts); - return null; + return $node; } private function createCastsProperty(): Property diff --git a/src/Rector/MethodCall/WhereToWhereLikeRector.php b/src/Rector/MethodCall/WhereToWhereLikeRector.php index 6dc4f33f2..11af6efa9 100644 --- a/src/Rector/MethodCall/WhereToWhereLikeRector.php +++ b/src/Rector/MethodCall/WhereToWhereLikeRector.php @@ -125,6 +125,7 @@ public function refactor(Node $node): ?Node // Remove the second argument (the 'like' operator) unset($node->args[1]); + $node->args = array_values($node->args); return $node; } diff --git a/src/Rector/Namespace_/FactoryDefinitionRector.php b/src/Rector/Namespace_/FactoryDefinitionRector.php index 20cf92b52..1ccc32a41 100644 --- a/src/Rector/Namespace_/FactoryDefinitionRector.php +++ b/src/Rector/Namespace_/FactoryDefinitionRector.php @@ -141,6 +141,7 @@ public function refactor(Node $node): ?Node } $node->stmts = array_merge($node->stmts, $factories); + $node->stmts = array_values($node->stmts); return $node; } diff --git a/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php b/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php index 8b45699d5..37997636a 100644 --- a/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php +++ b/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php @@ -96,6 +96,7 @@ public function refactor(Node $node): ?Node } unset($node->args[2]); + $node->args = array_values($node->args); $node->name = new Identifier('permanentRedirect');