Skip to content

Commit

Permalink
[CodingStyle] Reduce parent attribute usage on NameImporter take 2 (#…
Browse files Browse the repository at this point in the history
…4345)

* [CodingStyle] Reduce parent attribute usage on NameImporter take 2

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Jun 25, 2023
1 parent 53e4e9f commit a01259f
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions rules/CodingStyle/Node/NameImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

namespace Rector\CodingStyle\Node;

use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use PHPStan\Reflection\ReflectionProvider;
use Rector\CodingStyle\ClassNameImport\AliasUsesResolver;
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipper;
use Rector\Core\Configuration\Option;
Expand All @@ -32,8 +30,7 @@ public function __construct(
private readonly ClassNameImportSkipper $classNameImportSkipper,
private readonly ParameterProvider $parameterProvider,
private readonly StaticTypeMapper $staticTypeMapper,
private readonly UseNodesToAddCollector $useNodesToAddCollector,
private readonly ReflectionProvider $reflectionProvider
private readonly UseNodesToAddCollector $useNodesToAddCollector
) {
}

Expand Down Expand Up @@ -149,18 +146,6 @@ private function isNamespaceOrUseImportName(Name $name): bool

private function isFunctionOrConstantImportWithSingleName(Name $name): bool
{
$parentNode = $name->getAttribute(AttributeKey::PARENT_NODE);

$fullName = $name->toString();

$autoImportNames = $this->parameterProvider->provideBoolParameter(Option::AUTO_IMPORT_NAMES);
if ($autoImportNames && ! $parentNode instanceof Node && ! \str_contains(
$fullName,
'\\'
) && $this->reflectionProvider->hasFunction(new Name($fullName), null)) {
return true;
}

if ($name->getAttribute(AttributeKey::IS_CONSTFETCH_NAME) === true) {
return count($name->getParts()) === 1;
}
Expand Down

0 comments on commit a01259f

Please sign in to comment.