add VIRTUAL_NODE constant, prevent double post traversing nodes

This commit is contained in:
TomasVotruba 2020-06-19 01:35:11 +02:00
parent 233b1d9680
commit 34c40428f3
7 changed files with 14 additions and 4 deletions

View File

@ -44,6 +44,7 @@ expectedArguments(
\Rector\NodeTypeResolver\Node\AttributeKey::IS_REGULAR_PATTERN,
\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NAME,
\Rector\NodeTypeResolver\Node\AttributeKey::COMMENTS,
\Rector\NodeTypeResolver\Node\AttributeKey::VIRTUAL_NODE,
);
expectedArguments(
@ -73,6 +74,7 @@ expectedArguments(
\Rector\NodeTypeResolver\Node\AttributeKey::IS_REGULAR_PATTERN,
\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NAME,
\Rector\NodeTypeResolver\Node\AttributeKey::COMMENTS,
\Rector\NodeTypeResolver\Node\AttributeKey::VIRTUAL_NODE,
);
expectedArguments(

View File

@ -14,6 +14,11 @@ use Symplify\SmartFileSystem\SmartFileInfo;
final class AttributeKey
{
/**
* @var string
*/
public const VIRTUAL_NODE = 'virtual_node';
/**
* @var string
*/

View File

@ -99,7 +99,7 @@ final class NameImporter
private function shouldSkipName(Name $name): bool
{
if ($name->getAttribute('virtual_node')) {
if ($name->getAttribute(AttributeKey::VIRTUAL_NODE)) {
return true;
}

View File

@ -38,7 +38,7 @@ final class FullyQualifiedObjectType extends ObjectType
public function getShortNameNode(): Name
{
$name = new Name($this->getShortName());
$name->setAttribute('virtual_node', true);
$name->setAttribute(AttributeKey::VIRTUAL_NODE, true);
return $name;
}

View File

@ -320,7 +320,7 @@ final class ClassRenamer
continue;
}
if (! $implementName->getAttribute('virtual_node')) {
if (! $implementName->getAttribute(AttributeKey::VIRTUAL_NODE)) {
continue;
}

View File

@ -142,7 +142,6 @@ final class FileProcessor
$this->currentFileInfoProvider->setCurrentStmt($newStmts);
$newStmts = $this->rectorNodeTraverser->traverse($newStmts);
$newStmts = $this->postFileProcessor->traverse($newStmts);
// this is needed for new tokens added in "afterTraverse()"
$this->tokensByFilePathStorage->addForRealPath($smartFileInfo, $newStmts, $oldStmts, $oldTokens);

View File

@ -258,6 +258,10 @@ abstract class AbstractRectorTestCase extends AbstractGenericRectorTestCase
$this->fileProcessor->parseFileInfoToLocalCache($originalFileInfo);
$this->fileProcessor->refactor($originalFileInfo);
$this->fileProcessor->postFileRefactor($originalFileInfo);
// mimic post-rectors
$changedContent = $this->fileProcessor->printToString($originalFileInfo);
$causedByFixtureMessage = $fixtureFileInfo->getRelativeFilePathFromCwd();