From 346533064e079bbe3b4bc706e598d934e292a9d9 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 28 Nov 2025 19:43:32 +0700 Subject: [PATCH 1/3] [stmts-aware] Use NodeGroup::STMTS_AWARE over StmtsAwareInterface --- composer.json | 2 +- phpstan.neon | 5 ++++- rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php | 5 +++-- .../StmtsAwareInterface/DeclareStrictTypesTestsRector.php | 5 +++-- .../Rector/MethodCall/DelegateExceptionArgumentsRector.php | 5 +++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 10ca68c7..843ccd45 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "phpstan/phpstan-deprecation-rules": "^2.0", "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "^11.5", - "rector/rector-src": "dev-main", + "rector/rector-src": "dev-tv-stmts-interface", "rector/swiss-knife": "^1.0", "rector/type-perfect": "^2.1", "symplify/phpstan-extensions": "^12.0", diff --git a/phpstan.neon b/phpstan.neon index 6fe15a7a..477e7bdb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,6 +11,10 @@ parameters: reportUnmatchedIgnoredErrors: false errorFormat: symplify + # see https://phpstan.org/writing-php-code/phpdoc-types#global-type-aliases + typeAliases: + StmtsAware: \PhpParser\Node\Expr\Closure | \PhpParser\Node\Stmt\Case_ | \PhpParser\Node\Stmt\Catch_ | \PhpParser\Node\Stmt\ClassMethod | \PhpParser\Node\Stmt\Do_ | \PhpParser\Node\Stmt\Else_ | \PhpParser\Node\Stmt\ElseIf_ | \PhpParser\Node\Stmt\Finally_ | \PhpParser\Node\Stmt\For_ | \PhpParser\Node\Stmt\Foreach_ | \PhpParser\Node\Stmt\Function_ | \PhpParser\Node\Stmt\If_ | \PhpParser\Node\Stmt\Namespace_ | \PhpParser\Node\Stmt\TryCatch | \PhpParser\Node\Stmt\While_ + scanDirectories: - stubs @@ -48,4 +52,3 @@ parameters: - message: '#Parameter \#1 \$value of static method Webmozart\\Assert\\Assert\:\:isAOf\(\) expects object\|string, PhpParser\\Node\\Stmt\\Class_\|null given#' path: rules/AnnotationsToAttributes/Rector/Class_/AnnotationWithValueToAttributeRector.php - diff --git a/rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php b/rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php index 81beee1a..c1b93d3a 100644 --- a/rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php +++ b/rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php @@ -17,6 +17,7 @@ use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Exception\ShouldNotHappenException; use Rector\NodeManipulator\StmtsManipulator; +use Rector\PhpParser\Enum\NodeGroup; use Rector\PhpParser\Node\Value\ValueResolver; use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\Rector\AbstractRector; @@ -77,11 +78,11 @@ public function getRuleDefinition(): RuleDefinition */ public function getNodeTypes(): array { - return [StmtsAwareInterface::class]; + return NodeGroup::STMTS_AWARE; } /** - * @param StmtsAwareInterface $node + * @param StmtsAware $node */ public function refactor(Node $node): ?Node { diff --git a/rules/CodeQuality/Rector/StmtsAwareInterface/DeclareStrictTypesTestsRector.php b/rules/CodeQuality/Rector/StmtsAwareInterface/DeclareStrictTypesTestsRector.php index 6a2706e0..782ac740 100644 --- a/rules/CodeQuality/Rector/StmtsAwareInterface/DeclareStrictTypesTestsRector.php +++ b/rules/CodeQuality/Rector/StmtsAwareInterface/DeclareStrictTypesTestsRector.php @@ -12,6 +12,7 @@ use Rector\ChangesReporting\ValueObject\RectorWithLineChange; use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Contract\Rector\HTMLAverseRectorInterface; +use Rector\PhpParser\Enum\NodeGroup; use Rector\PhpParser\Node\BetterNodeFinder; use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace; use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; @@ -121,11 +122,11 @@ public function beforeTraverse(array $nodes): ?array */ public function getNodeTypes(): array { - return [StmtsAwareInterface::class]; + return NodeGroup::STMTS_AWARE; } /** - * @param StmtsAwareInterface $node + * @param StmtsAware $node */ public function refactor(Node $node): int { diff --git a/rules/PHPUnit60/Rector/MethodCall/DelegateExceptionArgumentsRector.php b/rules/PHPUnit60/Rector/MethodCall/DelegateExceptionArgumentsRector.php index 5d94a434..b54fb0f5 100644 --- a/rules/PHPUnit60/Rector/MethodCall/DelegateExceptionArgumentsRector.php +++ b/rules/PHPUnit60/Rector/MethodCall/DelegateExceptionArgumentsRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Stmt\Expression; use Rector\Contract\PhpParser\Node\StmtsAwareInterface; +use Rector\PhpParser\Enum\NodeGroup; use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\PHPUnit\NodeFactory\AssertCallFactory; use Rector\Rector\AbstractRector; @@ -76,11 +77,11 @@ public function test() */ public function getNodeTypes(): array { - return [StmtsAwareInterface::class]; + return NodeGroup::STMTS_AWARE; } /** - * @param StmtsAwareInterface $node + * @param StmtsAware $node */ public function refactor(Node $node): ?Node { From d3bb8ed4a5a2c85312abf27abcadc2acccc59c9e Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 28 Nov 2025 12:44:42 +0000 Subject: [PATCH 2/3] [ci-review] Rector Rectify --- rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php | 1 - .../Rector/StmtsAwareInterface/DeclareStrictTypesTestsRector.php | 1 - .../Rector/MethodCall/DelegateExceptionArgumentsRector.php | 1 - 3 files changed, 3 deletions(-) diff --git a/rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php b/rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php index c1b93d3a..87d45b0d 100644 --- a/rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php +++ b/rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php @@ -14,7 +14,6 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt\Expression; -use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Exception\ShouldNotHappenException; use Rector\NodeManipulator\StmtsManipulator; use Rector\PhpParser\Enum\NodeGroup; diff --git a/rules/CodeQuality/Rector/StmtsAwareInterface/DeclareStrictTypesTestsRector.php b/rules/CodeQuality/Rector/StmtsAwareInterface/DeclareStrictTypesTestsRector.php index 782ac740..19eae113 100644 --- a/rules/CodeQuality/Rector/StmtsAwareInterface/DeclareStrictTypesTestsRector.php +++ b/rules/CodeQuality/Rector/StmtsAwareInterface/DeclareStrictTypesTestsRector.php @@ -10,7 +10,6 @@ use PhpParser\Node\Stmt\Nop; use PhpParser\NodeVisitor; use Rector\ChangesReporting\ValueObject\RectorWithLineChange; -use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\PhpParser\Enum\NodeGroup; use Rector\PhpParser\Node\BetterNodeFinder; diff --git a/rules/PHPUnit60/Rector/MethodCall/DelegateExceptionArgumentsRector.php b/rules/PHPUnit60/Rector/MethodCall/DelegateExceptionArgumentsRector.php index b54fb0f5..a9dcbe9f 100644 --- a/rules/PHPUnit60/Rector/MethodCall/DelegateExceptionArgumentsRector.php +++ b/rules/PHPUnit60/Rector/MethodCall/DelegateExceptionArgumentsRector.php @@ -9,7 +9,6 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Identifier; use PhpParser\Node\Stmt\Expression; -use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\PhpParser\Enum\NodeGroup; use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\PHPUnit\NodeFactory\AssertCallFactory; From ecb6770631aa4687b9a931a89628dc46158cc6d4 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 28 Nov 2025 19:46:47 +0700 Subject: [PATCH 3/3] clean up phpstan ignore notice --- phpstan.neon | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 477e7bdb..c89f87c9 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -35,20 +35,9 @@ parameters: # phpstan false positive - '#Parameter \#1 \$className of method Rector\\PhpParser\\AstResolver\:\:resolveClassMethod\(\) expects class\-string, string given#' - # false positive - - '#Access to an undefined property Rector\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts#' - # more advanced usage, but not always working # see https://github.com/rectorphp/rector-src/actions/runs/11798721617/job/32865546672?pr=6422#step:5:110 - '#Doing instanceof PHPStan\\Type\\.+ is error\-prone and deprecated#' - identifier: instanceof.alwaysTrue - identifier: assign.propertyType - - # not relevant - - '#Method (.*?)provideMinPhpVersion\(\) never returns \d+ so it can be removed from the return type#' - - # chicken-egg false positive - - - message: '#Parameter \#1 \$value of static method Webmozart\\Assert\\Assert\:\:isAOf\(\) expects object\|string, PhpParser\\Node\\Stmt\\Class_\|null given#' - path: rules/AnnotationsToAttributes/Rector/Class_/AnnotationWithValueToAttributeRector.php