Skip to content

Commit

Permalink
[Core] Remove unneeded ChangedNodeAnalyzer service (#1868)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Feb 25, 2022
1 parent da3c997 commit 961c3ae
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 90 deletions.
26 changes: 22 additions & 4 deletions e2e/applied-rule-change-docblock/expected-output.diff
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
1 file with changes
===================
2 files with changes
====================

1) src/RenameDocblock.php:0
1) src/UselessVarTag.php:1

---------- begin diff ----------
@@ @@

final class UselessVarTag
{
- /**
- * @var string
- */
public string $name = 'name';
}
----------- end diff -----------

Applied rules:
* RemoveUselessVarTagRector


2) src/RenameDocblock.php:0

---------- begin diff ----------
@@ @@
Expand All @@ -19,4 +37,4 @@ Applied rules:
* RenameClassRector


[OK] 1 file would have changed (dry-run) by Rector
[OK] 2 files would have changed (dry-run) by Rector
2 changes: 2 additions & 0 deletions e2e/applied-rule-change-docblock/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Core\Configuration\Option;
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
use Rector\DowngradePhp80\Rector\Class_\DowngradeAttributeToAnnotationRector;
use Rector\DowngradePhp80\ValueObject\DowngradeAttributeToAnnotation;
use Rector\Renaming\Rector\Name\RenameClassRector;
Expand All @@ -19,4 +20,5 @@
->configure(['DateTime' => 'DateTimeInterface']);
$services->set(DowngradeAttributeToAnnotationRector::class)
->configure([new DowngradeAttributeToAnnotation('Symfony\Component\Routing\Annotation\Route')]);
$services->set(RemoveUselessVarTagRector::class);
};
9 changes: 9 additions & 0 deletions e2e/applied-rule-change-docblock/src/UselessVarTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

final class UselessVarTag
{
/**
* @var string
*/
public string $name = 'name';
}
6 changes: 0 additions & 6 deletions packages/NodeTypeResolver/Node/AttributeKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,6 @@ final class AttributeKey
*/
public const FILE = 'file';

/**
* In case the php-doc info just changed, for reporting of changed nodes
* @var string
*/
public const HAS_PHP_DOC_INFO_JUST_CHANGED = 'has_php_doc_info_just_changed';

/**
* Helps with infinite loop detection
* @var string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Type\UnionType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\UnionTypeAnalyzer;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -97,7 +96,6 @@ public function refactor(Node $node): ?Node
}

if ($this->hasChanged) {
$node->setAttribute(AttributeKey::HAS_PHP_DOC_INFO_JUST_CHANGED, true);
return $node;
}

Expand Down
2 changes: 0 additions & 2 deletions rules/DeadCode/Rector/ClassLike/RemoveAnnotationRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
Expand Down Expand Up @@ -86,7 +85,6 @@ public function refactor(Node $node): ?Node
}

if ($phpDocInfo->hasChanged()) {
$node->setAttribute(AttributeKey::HAS_PHP_DOC_INFO_JUST_CHANGED, true);
return $node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\PhpDoc\TagRemover\ParamTagRemover;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down Expand Up @@ -78,7 +77,6 @@ public function refactor(Node $node): ?Node

$hasChanged = $this->paramTagRemover->removeParamTagsIfUseless($phpDocInfo, $node);
if ($hasChanged) {
$node->setAttribute(AttributeKey::HAS_PHP_DOC_INFO_JUST_CHANGED, true);
return $node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\PhpDoc\TagRemover\ReturnTagRemover;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down Expand Up @@ -76,7 +75,6 @@ public function refactor(Node $node): ?Node
return null;
}

$node->setAttribute(AttributeKey::HAS_PHP_DOC_INFO_JUST_CHANGED, true);
return $node;
}
}
2 changes: 0 additions & 2 deletions rules/DeadCode/Rector/Property/RemoveUselessVarTagRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PhpParser\Node\Stmt\Property;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down Expand Up @@ -64,7 +63,6 @@ public function refactor(Node $node): ?Node
$this->varTagRemover->removeVarTagIfUseless($phpDocInfo, $node);

if ($phpDocInfo->hasChanged()) {
$node->setAttribute(AttributeKey::HAS_PHP_DOC_INFO_JUST_CHANGED, true);
return $node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Rector\Core\NodeAnalyzer\ParamAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\PhpDoc\TagRemover\ParamTagRemover;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\TypeDeclaration\TypeInferer\ParamTypeInferer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -124,7 +123,6 @@ public function refactor(Node $node): ?Node
}

if ($phpDocInfo->hasChanged() && $hasChangedNode) {
$node->setAttribute(AttributeKey::HAS_PHP_DOC_INFO_JUST_CHANGED, true);
$this->paramTagRemover->removeParamTagsIfUseless($phpDocInfo, $node);
return $node;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\PhpDoc\TagRemover\ReturnTagRemover;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Privatization\TypeManipulator\NormalizeTypeToRespectArrayScalarType;
use Rector\Privatization\TypeManipulator\TypeNormalizer;
use Rector\TypeDeclaration\NodeTypeAnalyzer\DetailedTypeAnalyzer;
Expand Down Expand Up @@ -143,7 +142,6 @@ public function refactor(Node $node): ?Node
return null;
}

$node->setAttribute(AttributeKey::HAS_PHP_DOC_INFO_JUST_CHANGED, true);
$hasChanged = $this->returnTagRemover->removeReturnTagIfUseless($phpDocInfo, $node);
if ($hasChanged) {
return $node;
Expand Down
55 changes: 0 additions & 55 deletions src/NodeAnalyzer/ChangedNodeAnalyzer.php

This file was deleted.

12 changes: 1 addition & 11 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Exclusion\ExclusionManager;
use Rector\Core\Logging\CurrentRectorProvider;
use Rector\Core\NodeAnalyzer\ChangedNodeAnalyzer;
use Rector\Core\NodeDecorator\CreatedByRuleDecorator;
use Rector\Core\Php\PhpVersionProvider;
use Rector\Core\PhpParser\Comparing\NodeComparator;
Expand Down Expand Up @@ -116,8 +115,6 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn

private CurrentFileProvider $currentFileProvider;

private ChangedNodeAnalyzer $changedNodeAnalyzer;

/**
* @var array<string, Node[]|Node>
*/
Expand Down Expand Up @@ -153,7 +150,6 @@ public function autowire(
BetterNodeFinder $betterNodeFinder,
NodeComparator $nodeComparator,
CurrentFileProvider $currentFileProvider,
ChangedNodeAnalyzer $changedNodeAnalyzer,
InfiniteLoopValidator $infiniteLoopValidator,
RectifiedAnalyzer $rectifiedAnalyzer,
CreatedByRuleDecorator $createdByRuleDecorator
Expand All @@ -180,7 +176,6 @@ public function autowire(
$this->betterNodeFinder = $betterNodeFinder;
$this->nodeComparator = $nodeComparator;
$this->currentFileProvider = $currentFileProvider;
$this->changedNodeAnalyzer = $changedNodeAnalyzer;
$this->infiniteLoopValidator = $infiniteLoopValidator;
$this->rectifiedAnalyzer = $rectifiedAnalyzer;
$this->createdByRuleDecorator = $createdByRuleDecorator;
Expand Down Expand Up @@ -261,13 +256,8 @@ final public function enterNode(Node $node)
return $originalNode;
}

// not changed, return node early
/** @var Node $node */
if (! $this->changedNodeAnalyzer->hasNodeChanged($originalNode, $node)) {
return $node;
}

// update parents relations - must run before connectParentNodes()
/** @var Node $node */
$this->mirrorAttributes($originalAttributes, $node);
$this->connectParentNodes($node);

Expand Down

0 comments on commit 961c3ae

Please sign in to comment.