[NodeCollector] Remove CurrentStmtResolver service (#2143)

* [NodeCollector] Remove CurrentStmtResolver service

* remove from constructor injection

* [ci-review] Rector Rectify

* clean up

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Abdul Malik Ikhsan 2022-04-24 05:14:43 +07:00 committed by GitHub
parent 469f0eed63
commit 31656ed51d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 40 deletions

View File

@ -1,19 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\NodeCollector\NodeResolver;
use PhpParser\Node\Stmt;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class CurrentStmtResolver
{
public function resolve(Stmt $stmt): Stmt
{
$currentStatement = $stmt->getAttribute(AttributeKey::CURRENT_STATEMENT);
return $currentStatement instanceof Stmt
? $currentStatement
: $stmt;
}
}

View File

@ -18,7 +18,6 @@ use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Provider\CurrentFileProvider;
use Rector\NodeCollector\NodeResolver\CurrentStmtResolver;
use Rector\NodeRemoval\BreakingRemovalGuard;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PostRector\Contract\Collector\NodeCollectorInterface;
@ -36,8 +35,7 @@ final class NodesToRemoveCollector implements NodeCollectorInterface
private readonly BreakingRemovalGuard $breakingRemovalGuard,
private readonly BetterNodeFinder $betterNodeFinder,
private readonly NodeComparator $nodeComparator,
private readonly CurrentFileProvider $currentFileProvider,
private readonly CurrentStmtResolver $currentStmtResolver
private readonly CurrentFileProvider $currentFileProvider
) {
}
@ -72,16 +70,7 @@ final class NodesToRemoveCollector implements NodeCollectorInterface
public function isNodeRemoved(Node $node): bool
{
if (in_array($node, $this->nodesToRemove, true)) {
return true;
}
if ($node instanceof Stmt) {
$currentStatement = $this->currentStmtResolver->resolve($node);
return in_array($currentStatement, $this->nodesToRemove, true);
}
return false;
return in_array($node, $this->nodesToRemove, true);
}
public function isActive(): bool

View File

@ -28,7 +28,6 @@ use PhpParser\Node\Stmt\Trait_;
use PhpParser\Node\Stmt\TryCatch;
use PhpParser\Node\Stmt\While_;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeCollector\NodeResolver\CurrentStmtResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -64,11 +63,6 @@ final class NewlineAfterStatementRector extends AbstractRector
*/
private array $stmtsHashed = [];
public function __construct(
private readonly CurrentStmtResolver $currentStmtResolver
) {
}
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
@ -117,8 +111,6 @@ CODE_SAMPLE
*/
public function refactor(Node $node): ?Node
{
$node = $this->currentStmtResolver->resolve($node);
if (! in_array($node::class, self::STMTS_TO_HAVE_NEXT_NEWLINE, true)) {
return null;
}