Skip to content

Commit

Permalink
[Printer] Remove unnecessary BetterStandardPrinter::pStmt_Use() (#5478)
Browse files Browse the repository at this point in the history
* [Printer] Remove unnecessary BetterStandardPrinter::pStmt_Use()

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user authored Jan 18, 2024
1 parent 863a5ed commit 76714b9
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 46 deletions.
7 changes: 0 additions & 7 deletions rules/Renaming/NodeManipulator/ClassRenamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,6 @@ private function refactorName(FullyQualified $fullyQualified, array $oldToNewCla
return null;
}

// no need to preslash "use \SomeNamespace" of imported namespace
if ($fullyQualified->getAttribute(AttributeKey::IS_USEUSE_NAME) === true) {
// no need to rename imports, they will be handled by autoimport and coding standard
// also they might cause some rename
return null;
}

if ($this->shouldSkip($newName, $fullyQualified)) {
return null;
}
Expand Down
5 changes: 0 additions & 5 deletions src/NodeTypeResolver/Node/AttributeKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,6 @@ final class AttributeKey
*/
public const IS_ARRAY_IN_ATTRIBUTE = 'is_array_in_attribute';

/**
* @var string
*/
public const IS_USEUSE_NAME = 'is_useuse_name';

/**
* @var string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use PhpParser\NodeVisitorAbstract;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
Expand All @@ -20,11 +18,6 @@ final class NameNodeVisitor extends NodeVisitorAbstract implements ScopeResolver
{
public function enterNode(Node $node): ?Node
{
if ($node instanceof UseUse && ($node->type === Use_::TYPE_NORMAL || $node->type === Use_::TYPE_UNKNOWN)) {
$node->name->setAttribute(AttributeKey::IS_USEUSE_NAME, true);
return null;
}

if ($node instanceof FuncCall && $node->name instanceof Name) {
$node->name->setAttribute(AttributeKey::IS_FUNCCALL_NAME, true);
return null;
Expand Down
23 changes: 0 additions & 23 deletions src/PhpParser/Printer/BetterStandardPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Param;
use PhpParser\Node\Scalar\DNumber;
use PhpParser\Node\Scalar\EncapsedStringPart;
Expand All @@ -24,7 +22,6 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\Nop;
use PhpParser\Node\Stmt\Use_;
use PhpParser\PrettyPrinter\Standard;
use PHPStan\Node\Expr\AlwaysRememberedExpr;
use Rector\Configuration\Option;
Expand Down Expand Up @@ -392,26 +389,6 @@ protected function pExpr_Ternary(Ternary $ternary): string
return parent::pExpr_Ternary($ternary);
}

/**
* Remove extra \\ from FQN use imports, for easier use in the code
*/
protected function pStmt_Use(Use_ $use): string
{
if ($use->type !== Use_::TYPE_NORMAL) {
return parent::pStmt_Use($use);
}

foreach ($use->uses as $useUse) {
if (! $useUse->name instanceof FullyQualified) {
continue;
}

$useUse->name = new Name($useUse->name->toString());
}

return parent::pStmt_Use($use);
}

protected function pScalar_EncapsedStringPart(EncapsedStringPart $encapsedStringPart): string
{
// parent throws exception, but we need to compare string
Expand Down
2 changes: 0 additions & 2 deletions src/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use Rector\NodeTypeResolver\Node\AttributeKey;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public function getShortNameNode(): Name
public function getUseNode(int $useType): Use_
{
$name = new Name($this->getClassName());
$name->setAttribute(AttributeKey::IS_USEUSE_NAME, true);

$useUse = new UseUse($name);

$use = new Use_([$useUse]);
Expand Down

0 comments on commit 76714b9

Please sign in to comment.