mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 08:20:53 +00:00
[Core] Move isPropertyFetch() to PropertyFetchAnalyzer (#563)
This commit is contained in:
parent
00015a4390
commit
205e7a5bd0
|
@ -22,7 +22,6 @@ use Rector\Core\Rector\AbstractRector;
|
|||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Php80\NodeAnalyzer\PromotedPropertyResolver;
|
||||
use Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector;
|
||||
use Rector\TypeDeclaration\Matcher\PropertyAssignMatcher;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
|
@ -35,8 +34,7 @@ final class RemoveDeadInstanceOfRector extends AbstractRector
|
|||
private IfManipulator $ifManipulator,
|
||||
private PropertyFetchAnalyzer $propertyFetchAnalyzer,
|
||||
private ConstructorAssignDetector $constructorAssignDetector,
|
||||
private PromotedPropertyResolver $promotedPropertyResolver,
|
||||
private PropertyAssignMatcher $propertyAssignMatcher
|
||||
private PromotedPropertyResolver $promotedPropertyResolver
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -138,7 +136,7 @@ CODE_SAMPLE
|
|||
|
||||
private function isSkippedPropertyFetch(Expr $expr): bool
|
||||
{
|
||||
if (! $this->propertyAssignMatcher->isPropertyFetch($expr)) {
|
||||
if (! $this->propertyFetchAnalyzer->isPropertyFetch($expr)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,18 +4,17 @@ declare(strict_types=1);
|
|||
|
||||
namespace Rector\TypeDeclaration\Matcher;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
|
||||
final class PropertyAssignMatcher
|
||||
{
|
||||
public function __construct(
|
||||
private NodeNameResolver $nodeNameResolver
|
||||
private NodeNameResolver $nodeNameResolver,
|
||||
private PropertyFetchAnalyzer $propertyFetchAnalyzer
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -26,7 +25,7 @@ final class PropertyAssignMatcher
|
|||
*/
|
||||
public function matchPropertyAssignExpr(Assign $assign, string $propertyName): ?Expr
|
||||
{
|
||||
if ($this->isPropertyFetch($assign->var)) {
|
||||
if ($this->propertyFetchAnalyzer->isPropertyFetch($assign->var)) {
|
||||
if (! $this->nodeNameResolver->isName($assign->var, $propertyName)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -34,7 +33,7 @@ final class PropertyAssignMatcher
|
|||
return $assign->expr;
|
||||
}
|
||||
|
||||
if ($assign->var instanceof ArrayDimFetch && $this->isPropertyFetch($assign->var->var)) {
|
||||
if ($assign->var instanceof ArrayDimFetch && $this->propertyFetchAnalyzer->isPropertyFetch($assign->var->var)) {
|
||||
if (! $this->nodeNameResolver->isName($assign->var->var, $propertyName)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -44,13 +43,4 @@ final class PropertyAssignMatcher
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function isPropertyFetch(Node $node): bool
|
||||
{
|
||||
if ($node instanceof PropertyFetch) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $node instanceof StaticPropertyFetch;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,6 +94,15 @@ final class PropertyFetchAnalyzer
|
|||
return false;
|
||||
}
|
||||
|
||||
public function isPropertyFetch(Node $node): bool
|
||||
{
|
||||
if ($node instanceof PropertyFetch) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $node instanceof StaticPropertyFetch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches:
|
||||
* "$this->someValue = $<variableName>;"
|
||||
|
|
Loading…
Reference in New Issue
Block a user