Skip to content

Commit

Permalink
[DX] Remove CurrentFileProvider dependency on ChangedNodeScopeRefresh…
Browse files Browse the repository at this point in the history
…er (#5087)
  • Loading branch information
samsonasik committed Sep 27, 2023
1 parent 16ba249 commit 4f78220
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
13 changes: 2 additions & 11 deletions src/Application/ChangedNodeScopeRefresher.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
use PHPStan\Analyser\MutatingScope;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\NodeAnalyzer\ScopeAnalyzer;
use Rector\Core\Provider\CurrentFileProvider;
use Rector\Core\ValueObject\Application\File;
use Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver;

/**
Expand All @@ -38,24 +36,17 @@ final class ChangedNodeScopeRefresher
{
public function __construct(
private readonly PHPStanNodeScopeResolver $phpStanNodeScopeResolver,
private readonly ScopeAnalyzer $scopeAnalyzer,
private readonly CurrentFileProvider $currentFileProvider
private readonly ScopeAnalyzer $scopeAnalyzer
) {
}

public function refresh(Node $node, ?MutatingScope $mutatingScope, ?string $filePath = null): void
public function refresh(Node $node, string $filePath, ?MutatingScope $mutatingScope): void
{
// nothing to refresh
if (! $this->scopeAnalyzer->isRefreshable($node)) {
return;
}

if (! is_string($filePath)) {
/** @var File $file */
$file = $this->currentFileProvider->getFile();
$filePath = $file->getFilePath();
}

$mutatingScope = $mutatingScope instanceof MutatingScope
? $mutatingScope
: $this->scopeAnalyzer->resolveScope($node, $filePath);
Expand Down
2 changes: 1 addition & 1 deletion src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ private function refreshScopeNodes(array | Node $node, string $filePath, ?Mutati
$nodes = $node instanceof Node ? [$node] : $node;

foreach ($nodes as $node) {
$this->changedNodeScopeRefresher->refresh($node, $mutatingScope, $filePath);
$this->changedNodeScopeRefresher->refresh($node, $filePath, $mutatingScope);
}
}

Expand Down

0 comments on commit 4f78220

Please sign in to comment.