From 68dd40a6407e543f38234a8df9ac1aa431d21b54 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 22 Aug 2025 21:45:33 +0700 Subject: [PATCH 1/3] Deprecate StaticToSelfStaticMethodCallOnFinalClassRector and ConvertStaticPrivateConstantToSelfRector --- .../ConvertStaticPrivateConstantToSelfRector.php | 12 ++++++------ ...taticToSelfStaticMethodCallOnFinalClassRector.php | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php b/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php index 79c4453bae6..6bf66a1d284 100644 --- a/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php +++ b/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use Rector\CodeQuality\Rector\Class_\ConvertStaticToSelfRector; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -16,11 +17,6 @@ */ final class ConvertStaticPrivateConstantToSelfRector extends AbstractRector { - public function __construct( - private readonly ConvertStaticToSelfRector $convertStaticToSelfRector - ) { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -72,6 +68,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Class_ { - return $this->convertStaticToSelfRector->refactor($node); + throw new ShouldNotHappenException(sprintf( + 'The % rule is deprecated. Use %s instead', + self::class, + ConvertStaticToSelfRector::class, + )); } } diff --git a/rules/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector.php b/rules/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector.php index 3ddc1df0b35..d708cce0838 100644 --- a/rules/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector.php +++ b/rules/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -15,11 +16,6 @@ */ final class StaticToSelfStaticMethodCallOnFinalClassRector extends AbstractRector { - public function __construct( - private readonly ConvertStaticToSelfRector $convertStaticToSelfRector - ) { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Change `static::methodCall()` to `self::methodCall()` on final class', [ @@ -70,6 +66,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Class_ { - return $this->convertStaticToSelfRector->refactor($node); + throw new ShouldNotHappenException(sprintf( + 'The % rule is deprecated. Use %s instead', + self::class, + ConvertStaticToSelfRector::class, + )); } } From 7bd031bd8cbf98a4f39412911cb82c3f63a2f44a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 22 Aug 2025 21:48:07 +0700 Subject: [PATCH 2/3] Deprecate StaticToSelfStaticMethodCallOnFinalClassRector and ConvertStaticPrivateConstantToSelfRector --- .../ConvertStaticPrivateConstantToSelfRector.php | 2 +- .../Class_/StaticToSelfStaticMethodCallOnFinalClassRector.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php b/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php index 6bf66a1d284..781587db8f3 100644 --- a/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php +++ b/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php @@ -69,7 +69,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Class_ { throw new ShouldNotHappenException(sprintf( - 'The % rule is deprecated. Use %s instead', + 'The %s rule is deprecated. Use %s instead', self::class, ConvertStaticToSelfRector::class, )); diff --git a/rules/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector.php b/rules/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector.php index d708cce0838..560a6e7b42a 100644 --- a/rules/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector.php +++ b/rules/CodeQuality/Rector/Class_/StaticToSelfStaticMethodCallOnFinalClassRector.php @@ -67,7 +67,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Class_ { throw new ShouldNotHappenException(sprintf( - 'The % rule is deprecated. Use %s instead', + 'The %s rule is deprecated. Use %s instead', self::class, ConvertStaticToSelfRector::class, )); From 3bb2180cd8bea5c2d90cca4b9f77cc700f448513 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 22 Aug 2025 14:48:42 +0000 Subject: [PATCH 3/3] [ci-review] Rector Rectify --- .../Rector/Class_/ConvertStaticToSelfRector.php | 1 - ...ReturnDocblockForScalarArrayFromAssignsRector.php | 12 +++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php b/rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php index 57ac9b1ad89..01af812c262 100644 --- a/rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php +++ b/rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php @@ -6,7 +6,6 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassConstantReflection; -use PHPStan\TrinaryLogic; use PhpParser\Node; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\StaticCall; diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddReturnDocblockForScalarArrayFromAssignsRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddReturnDocblockForScalarArrayFromAssignsRector.php index 35eb4803c8a..86d7438c6f0 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddReturnDocblockForScalarArrayFromAssignsRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddReturnDocblockForScalarArrayFromAssignsRector.php @@ -134,8 +134,8 @@ public function refactor(Node $node): ?Node } $scalarArrayTypes = []; - foreach ($returnedVariableNames as $variableName) { - $scalarType = $this->resolveScalarArrayTypeForVariable($node, $variableName); + foreach ($returnedVariableNames as $returnedVariableName) { + $scalarType = $this->resolveScalarArrayTypeForVariable($node, $returnedVariableName); if ($scalarType instanceof Type) { $scalarArrayTypes[] = $scalarType; } else { @@ -191,11 +191,9 @@ private function resolveScalarArrayTypeForVariable(ClassMethod|Function_ $node, $arrayHasDimAssigns = false; foreach ($assigns as $assign) { - if ($assign->var instanceof Variable && $this->isName($assign->var, $variableName)) { - if ($assign->expr instanceof Array_ && $assign->expr->items === []) { - $arrayHasInitialized = true; - continue; - } + if ($assign->var instanceof Variable && $this->isName($assign->var, $variableName) && ($assign->expr instanceof Array_ && $assign->expr->items === [])) { + $arrayHasInitialized = true; + continue; } if (! $assign->var instanceof ArrayDimFetch) {