Skip to content

Commit

Permalink
remove FileNodeVisitor, available in AbstractRector
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Nov 4, 2021
1 parent f8e0477 commit 9b9ee9a
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 54 deletions.
1 change: 0 additions & 1 deletion config/services-packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
__DIR__ . '/../packages/BetterPhpDocParser/PhpDoc',
__DIR__ . '/../packages/PHPStanStaticTypeMapper/Enum',
__DIR__ . '/../packages/Caching/Cache.php',
__DIR__ . '/../packages/NodeTypeResolver/NodeVisitor/FileNodeVisitor.php',

// used in PHPStan
__DIR__ . '/../packages/NodeTypeResolver/Reflection/BetterReflection/RectorBetterReflectionSourceLocatorFactory.php',
Expand Down
4 changes: 0 additions & 4 deletions packages/NodeTypeResolver/NodeScopeAndMetadataDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\NodeVisitor\NodeConnectingVisitor;
use Rector\Core\ValueObject\Application\File;
use Rector\NodeTypeResolver\NodeVisitor\FileNodeVisitor;
use Rector\NodeTypeResolver\NodeVisitor\FunctionLikeParamArgPositionNodeVisitor;
use Rector\NodeTypeResolver\NodeVisitor\FunctionMethodAndClassNodeVisitor;
use Rector\NodeTypeResolver\NodeVisitor\NamespaceNodeVisitor;
Expand Down Expand Up @@ -79,9 +78,6 @@ public function decorateNodesFromFile(File $file, array $stmts): array
$nodeTraverserForFormatPreservePrinting->addVisitor($this->namespaceNodeVisitor);
$nodeTraverserForFormatPreservePrinting->addVisitor($this->functionLikeParamArgPositionNodeVisitor);

$fileNodeVisitor = new FileNodeVisitor($file);
$nodeTraverserForFormatPreservePrinting->addVisitor($fileNodeVisitor);

$stmts = $nodeTraverserForFormatPreservePrinting->traverse($stmts);

// this split is needed, so nodes have names, classes and namespaces
Expand Down
30 changes: 0 additions & 30 deletions packages/NodeTypeResolver/NodeVisitor/FileNodeVisitor.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PhpParser\Node\Scalar\LNumber;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\Application\File;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
Expand Down Expand Up @@ -142,14 +141,7 @@ private function shouldSkip(LNumber | DNumber $node, string $numericValueAsStrin
/** @var int $startToken */
$startToken = $node->getAttribute(AttributeKey::START_TOKEN_POSITION);

$file = $node->getAttribute(AttributeKey::FILE);

// new node
if (! $file instanceof File) {
return true;
}

$oldTokens = $file->getOldTokens();
$oldTokens = $this->file->getOldTokens();

foreach ($oldTokens[$startToken] as $token) {
if (! is_string($token)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public function refactor(Node $node): ?Node
}

$newPathName = $this->createPathName($oldPathname);

$file = $node->getAttribute(AttributeKey::FILE);
$this->removedAndAddedFilesCollector->addMovedFile($file, $newPathName);
$this->removedAndAddedFilesCollector->addMovedFile($this->file, $newPathName);

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PhpParser\Node\Stmt\ClassLike;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\Application\File;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down Expand Up @@ -65,14 +64,9 @@ public function refactor(Node $node): ?Node
return null;
}

$file = $node->getAttribute(AttributeKey::FILE);
if (! $file instanceof File) {
return null;
}

// no match → rename file
$newFileLocation = $smartFileInfo->getPath() . DIRECTORY_SEPARATOR . $classShortName . '.php';
$this->removedAndAddedFilesCollector->addMovedFile($file, $newFileLocation);
$this->removedAndAddedFilesCollector->addMovedFile($this->file, $newFileLocation);

return null;
}
Expand Down

0 comments on commit 9b9ee9a

Please sign in to comment.