Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down