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..e07330da 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: @@ -71,6 +75,6 @@ parameters: path: rules/TypedCollections/DocBlockProcessor/UnionCollectionTagValueNodeNarrower.php identifier: property.notFound - - # stmts aware interface - - '#Access to an undefined property Rector\\Contract\\PhpParser\\Node\\StmtsAwareInterface::\$stmts#' + - + 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..4e8b4db4 100644 --- a/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php +++ b/rules/Dbal40/Rector/StmtsAwareInterface/ExecuteQueryParamsToBindValueRector.php @@ -15,11 +15,14 @@ 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; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; +/** + * @see \Rector\Doctrine\Tests\Dbal40\Rector\StmtsAwareInterface\ExecuteQueryParamsToBindValueRector\ExecuteQueryParamsToBindValueRectorTest + */ final class ExecuteQueryParamsToBindValueRector extends AbstractRector { public function getRuleDefinition(): RuleDefinition @@ -62,19 +65,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..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; @@ -92,7 +91,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; }