Skip to content

Commit

Permalink
[StaticTypeMapper] Remove parent attribute usage on FullyQualifiedObj…
Browse files Browse the repository at this point in the history
…ectType (#4347)

* [StaticTypeMapper] Remove parent attribute usage on FullyQualifiedObjectType

* [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 beca17d commit 6cc42eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use Rector\NodeTypeResolver\Node\AttributeKey;

/**
* @api
Expand All @@ -31,6 +32,8 @@ public function getFullyQualifiedName(): string
public function getUseNode(): Use_
{
$name = new Name($this->fullyQualifiedClass);
$name->setAttribute(AttributeKey::IS_USEUSE_NAME, true);

$useUse = new UseUse($name, $this->getClassName());
return new Use_([$useUse]);
}
Expand All @@ -48,6 +51,8 @@ public function areShortNamesEqual(self | FullyQualifiedObjectType $comparedObje
public function getFunctionUseNode(): Use_
{
$name = new Name($this->fullyQualifiedClass);
$name->setAttribute(AttributeKey::IS_USEUSE_NAME, true);

$useUse = new UseUse($name, $this->getClassName());

$use = new Use_([$useUse]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public function getShortNameNode(): Name
public function getUseNode(): Use_
{
$name = new Name($this->getClassName());
$useUse = new UseUse($name);
$name->setAttribute(AttributeKey::IS_USEUSE_NAME, true);

$name->setAttribute(AttributeKey::PARENT_NODE, $useUse);
$useUse = new UseUse($name);

return new Use_([$useUse]);
}

public function getFunctionUseNode(): Use_
{
$name = new Name($this->getClassName());
$useUse = new UseUse($name, null);
$name->setAttribute(AttributeKey::IS_USEUSE_NAME, true);

$name->setAttribute(AttributeKey::PARENT_NODE, $useUse);
$useUse = new UseUse($name, null);

$use = new Use_([$useUse]);
$use->type = Use_::TYPE_FUNCTION;
Expand Down
7 changes: 1 addition & 6 deletions rules/CodingStyle/Node/NameImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\CodingStyle\Node;

use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Use_;
use Rector\CodingStyle\ClassNameImport\AliasUsesResolver;
Expand Down Expand Up @@ -140,11 +139,7 @@ private function isNamespaceOrUseImportName(Name $name): bool
return true;
}

if ($name->getAttribute(AttributeKey::IS_USEUSE_NAME) === true) {
return true;
}

return ! $name instanceof FullyQualified;
return $name->getAttribute(AttributeKey::IS_USEUSE_NAME) === true;
}

private function isFunctionOrConstantImportWithSingleName(Name $name): bool
Expand Down

0 comments on commit 6cc42eb

Please sign in to comment.