Skip to content

Commit

Permalink
Drop AttributeKey::SCOPE in FuncCallStaticCallToMethodCallAnalyzer (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed May 11, 2023
1 parent dd970ac commit 18af399
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Analyser\Scope;
use PHPStan\Type\ObjectType;
use Rector\Core\PhpParser\Node\NodeFactory;
use Rector\Naming\Naming\PropertyNaming;
Expand All @@ -35,12 +36,14 @@ public function __construct(
public function matchTypeProvidingExpr(
Class_ $class,
ClassMethod $classMethod,
ObjectType $objectType
ObjectType $objectType,
Scope $scope
): MethodCall | PropertyFetch | Variable {
$expr = $this->typeProvidingExprFromClassResolver->resolveTypeProvidingExprFromClass(
$class,
$classMethod,
$objectType
$objectType,
$scope
);

if ($expr instanceof Expr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public function __construct(
public function resolveTypeProvidingExprFromClass(
Class_ $class,
ClassMethod $classMethod,
ObjectType $objectType
ObjectType $objectType,
Scope $scope
): ?Expr {
$className = (string) $this->nodeNameResolver->getName($class);

Expand All @@ -53,11 +54,6 @@ public function resolveTypeProvidingExprFromClass(
}

// B. match existing property
$scope = $class->getAttribute(AttributeKey::SCOPE);
if (! $scope instanceof Scope) {
return null;
}

$propertyFetch = $this->resolvePropertyFetchProvidingType($classReflection, $scope, $objectType);
if ($propertyFetch instanceof PropertyFetch) {
return $propertyFetch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Transform\NodeAnalyzer\FuncCallStaticCallToMethodCallAnalyzer;
use Rector\Transform\ValueObject\FuncCallToMethodCall;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
Expand All @@ -19,7 +21,7 @@
/**
* @see \Rector\Tests\Transform\Rector\FuncCall\FuncCallToMethodCallRector\FuncCallToMethodCallRectorTest
*/
final class FuncCallToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
final class FuncCallToMethodCallRector extends AbstractScopeAwareRector implements ConfigurableRectorInterface
{
/**
* @var FuncCallToMethodCall[]
Expand Down Expand Up @@ -81,7 +83,7 @@ public function getNodeTypes(): array
/**
* @param FuncCall $node
*/
public function refactor(Node $node): ?Node
public function refactorWithScope(Node $node, Scope $scope): ?Node
{
$classLike = $this->betterNodeFinder->findParentType($node, Class_::class);
if (! $classLike instanceof Class_) {
Expand All @@ -105,7 +107,8 @@ public function refactor(Node $node): ?Node
$expr = $this->funcCallStaticCallToMethodCallAnalyzer->matchTypeProvidingExpr(
$classLike,
$classMethod,
$funcNameToMethodCallName->getNewObjectType()
$funcNameToMethodCallName->getNewObjectType(),
$scope
);

return $this->nodeFactory->createMethodCall(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Transform\NodeAnalyzer\FuncCallStaticCallToMethodCallAnalyzer;
use Rector\Transform\ValueObject\StaticCallToMethodCall;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
Expand All @@ -23,7 +25,7 @@
/**
* @see \Rector\Tests\Transform\Rector\StaticCall\StaticCallToMethodCallRector\StaticCallToMethodCallRectorTest
*/
final class StaticCallToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
final class StaticCallToMethodCallRector extends AbstractScopeAwareRector implements ConfigurableRectorInterface
{
/**
* @var StaticCallToMethodCall[]
Expand Down Expand Up @@ -96,7 +98,7 @@ public function getNodeTypes(): array
/**
* @param StaticCall $node
*/
public function refactor(Node $node): ?Node
public function refactorWithScope(Node $node, Scope $scope): ?Node
{
$classLike = $this->betterNodeFinder->findParentType($node, Class_::class);
if (! $classLike instanceof Class_) {
Expand All @@ -120,7 +122,8 @@ public function refactor(Node $node): ?Node
$expr = $this->funcCallStaticCallToMethodCallAnalyzer->matchTypeProvidingExpr(
$classLike,
$classMethod,
$staticCallToMethodCall->getClassObjectType()
$staticCallToMethodCall->getClassObjectType(),
$scope
);

if ($staticCallToMethodCall->getMethodName() === '*') {
Expand Down

0 comments on commit 18af399

Please sign in to comment.