From 3f6600ac2d69f0406c2414169f1424a5d13dd757 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 28 Nov 2025 19:25:36 +0700 Subject: [PATCH 1/3] [stmts-aware] Use NodeGroup::STMTS_AWARE over StmtsAwareInterface --- composer.json | 2 +- phpstan.neon | 16 ++++++++++++++-- .../ExecuteQueryParamsToBindValueRector.php | 13 +++++++++---- .../SetParametersArrayToCollectionRector.php | 2 +- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 7e1d90e1..d1d068ba 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,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/type-perfect": "^2.1", "symplify/phpstan-extensions": "^12.0", "symplify/phpstan-rules": "^14.6.9", diff --git a/phpstan.neon b/phpstan.neon index 8c19526f..ab458377 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,6 +6,10 @@ parameters: level: 8 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_ + treatPhpDocTypesAsCertain: false paths: @@ -72,5 +76,13 @@ parameters: identifier: property.notFound - # stmts aware interface - - '#Access to an undefined property Rector\\Contract\\PhpParser\\Node\\StmtsAwareInterface::\$stmts#' + # should be fixed in rector-src:dev-tv-stmts-interface itself + # see https://github.com/rectorphp/rector-src/pull/7679#pullrequestreview-3518768962 + - + message: '#getNodeTypes\(\) should return array> but returns array>#' + paths: + - rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php + + - + message: '#Function "property_exists\(\)" cannot be used/left in the code#' + path: rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php diff --git a/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php b/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php index 60770cab..99e4c69e 100644 --- a/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php +++ b/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php @@ -16,6 +16,7 @@ use PhpParser\NodeFinder; use PHPStan\Type\ObjectType; use Rector\Contract\PhpParser\Node\StmtsAwareInterface; +use Rector\PhpParser\Enum\NodeGroup; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -62,19 +63,23 @@ public function run(Statement $statement, array $params): void */ public function getNodeTypes(): array { - return [StmtsAwareInterface::class]; + return [NodeGroup::STMTS_AWARE]; } /** - * @param StmtsAwareInterface $node + * @param StmtsAware $node */ - public function refactor(Node $node): ?StmtsAwareInterface + public function refactor(Node $node): ?Node { + if ($node->stmts === null) { + return null; + } + $nodeFinder = new NodeFinder(); $hasChanged = false; $objectType = new ObjectType('Doctrine\DBAL\Statement'); - foreach ((array) $node->stmts as $key => $stmt) { + foreach ($node->stmts as $key => $stmt) { if (! $stmt instanceof Expression) { continue; } diff --git a/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php b/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php index 7626be51..4df4e227 100644 --- a/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php +++ b/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php @@ -92,7 +92,7 @@ public function changeArrayToCollection(array $stmts, Variable $variable): bool { $hasChanges = false; foreach ($stmts as $stmt) { - if ($stmt instanceof StmtsAwareInterface) { + if (property_exists($stmt, 'stmts')) { if ($this->changeArrayToCollection($stmt->stmts ?? [], $variable)) { $hasChanges = true; } From 15bbe0f28397e26ea677ed4f22e3a89cdb7556aa Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 28 Nov 2025 12:26:37 +0000 Subject: [PATCH 2/3] [rector] Rector fixes --- .../StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php | 1 - .../Rector/MethodCall/SetParametersArrayToCollectionRector.php | 1 - 2 files changed, 2 deletions(-) diff --git a/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php b/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php index 99e4c69e..4f3275cc 100644 --- a/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php +++ b/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php @@ -15,7 +15,6 @@ use PhpParser\Node\Stmt\Foreach_; use PhpParser\NodeFinder; use PHPStan\Type\ObjectType; -use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\PhpParser\Enum\NodeGroup; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; diff --git a/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php b/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php index 4df4e227..33dc3a01 100644 --- a/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php +++ b/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php @@ -20,7 +20,6 @@ use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; use PHPStan\Type\ObjectType; -use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; From 876fdb69a36d45d5a98456138c2878869d19b7e5 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 28 Nov 2025 19:31:38 +0700 Subject: [PATCH 3/3] fix test --- phpstan.neon | 8 -------- .../ExecuteQueryParamsToBindValueRector.php | 5 ++++- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index ab458377..e07330da 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -75,14 +75,6 @@ parameters: path: rules/TypedCollections/DocBlockProcessor/UnionCollectionTagValueNodeNarrower.php identifier: property.notFound - - # should be fixed in rector-src:dev-tv-stmts-interface itself - # see https://github.com/rectorphp/rector-src/pull/7679#pullrequestreview-3518768962 - - - message: '#getNodeTypes\(\) should return array> but returns array>#' - paths: - - rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php - - message: '#Function "property_exists\(\)" cannot be used/left in the code#' path: rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php diff --git a/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php b/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php index 4f3275cc..4e8b4db4 100644 --- a/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php +++ b/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php @@ -20,6 +20,9 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; +/** + * @see \Rector\Doctrine\Tests\Dbal40\Rector\StmtsAwareInterface\ExecuteQueryParamsToBindValueRector\ExecuteQueryParamsToBindValueRectorTest + */ final class ExecuteQueryParamsToBindValueRector extends AbstractRector { public function getRuleDefinition(): RuleDefinition @@ -62,7 +65,7 @@ public function run(Statement $statement, array $params): void */ public function getNodeTypes(): array { - return [NodeGroup::STMTS_AWARE]; + return NodeGroup::STMTS_AWARE; } /**