Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeDeclaration] Skip assign in construct with method call property same name on RestoreDefaultNullToNullableTypePropertyRector #5556

Merged
merged 1 commit into from
Feb 4, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace PhpMyAdmin\Bookmarks;

use PhpMyAdmin\ConfigStorage\Features\BookmarkFeature;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\DatabaseInterface;

class SkipAssignWithMethodCallPropertySameName
{
private BookmarkFeature|null $bookmarkFeature;

public function __construct(private DatabaseInterface $dbi, Relation $relation)
{
$this->bookmarkFeature = $relation->getRelationParameters()->bookmarkFeature;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Rector\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
use Rector\PhpParser\Comparing\NodeComparator;
use Rector\TypeDeclaration\Matcher\PropertyAssignMatcher;
use Rector\TypeDeclaration\NodeAnalyzer\AutowiredClassMethodOrPropertyAnalyzer;
use Rector\ValueObject\MethodName;
Expand All @@ -38,6 +39,7 @@ public function __construct(
private SimpleCallableNodeTraverser $simpleCallableNodeTraverser,
private AutowiredClassMethodOrPropertyAnalyzer $autowiredClassMethodOrPropertyAnalyzer,
private PropertyFetchAnalyzer $propertyFetchAnalyzer,
private NodeComparator $nodeComparator
) {
}

Expand Down Expand Up @@ -192,7 +194,8 @@ private function matchInitializeClassMethod(ClassLike $classLike): array
private function isPropertyUsedInAssign(Assign $assign, string $propertyName): bool
{
$nodeFinder = new NodeFinder();
return (bool) $nodeFinder->findFirst($assign->expr, static function (Node $node) use ($propertyName): ?bool {
$var = $assign->var;
return (bool) $nodeFinder->findFirst($assign->expr, function (Node $node) use ($propertyName, $var): ?bool {
if (! $node instanceof PropertyFetch) {
return null;
}
Expand All @@ -201,7 +204,11 @@ private function isPropertyUsedInAssign(Assign $assign, string $propertyName): b
return null;
}

return $node->name->toString() === $propertyName;
if ($node->name->toString() !== $propertyName) {
return null;
}

return $this->nodeComparator->areNodesEqual($node, $var);
});
}
}
Loading