Skip to content

Commit

Permalink
[NodeTypeResolver] Remove ReprintNodeVisitor take 2 (#6710)
Browse files Browse the repository at this point in the history
* [NodeTypeResolver] Remove ReprintNodeVisitor

* [ci-review] Rector Rectify

* try clean up Coalesce check

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user authored Feb 1, 2025
1 parent f51f41d commit 11789be
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 46 deletions.
2 changes: 1 addition & 1 deletion rules-tests/Naming/Naming/PropertyNamingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testGetExpectedNameFromMethodName(string $methodName, ?string $e
$expectedName = $this->propertyNaming->getExpectedNameFromMethodName($methodName);

if ($expectedPropertyName === null) {
$this->assertNull($expectedName);
$this->assertNotInstanceOf(ExpectedName::class, $expectedName);
} else {
$this->assertInstanceOf(ExpectedName::class, $expectedName);
$this->assertSame($expectedPropertyName, $expectedName->getSingularized());
Expand Down
2 changes: 0 additions & 2 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\ContextNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\GlobalVariableNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\NameNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\ReprintNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\StaticVariableNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\StmtKeyNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver;
Expand Down Expand Up @@ -241,7 +240,6 @@ final class LazyContainerFactory
NameNodeVisitor::class,
StaticVariableNodeVisitor::class,
StmtKeyNodeVisitor::class,
ReprintNodeVisitor::class,
];

/**
Expand Down

This file was deleted.

30 changes: 27 additions & 3 deletions src/PhpParser/Printer/BetterStandardPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Expr\Match_;
Expand Down Expand Up @@ -144,9 +145,7 @@ protected function p(
}
}

if ($this->exprAnalyzer->isExprWithExprPropertyWrappable($node)) {
$node->expr->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
$this->wrapBinaryOp($node);

$content = parent::p($node, $precedence, $lhsPrecedence, $parentFormatPreserved);

Expand All @@ -155,6 +154,31 @@ protected function p(
: $content;
}

private function wrapBinaryOp(Node $node): void
{
if ($this->exprAnalyzer->isExprWithExprPropertyWrappable($node)) {
$node->expr->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}

if (! $node instanceof BinaryOp) {
return;
}

if ($node->getAttribute(AttributeKey::ORIGINAL_NODE) instanceof Node) {
return;
}

if ($node->left instanceof BinaryOp &&
$node->left->getAttribute(AttributeKey::ORIGINAL_NODE) instanceof Node) {
$node->left->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}

if ($node->right instanceof BinaryOp &&
$node->right->getAttribute(AttributeKey::ORIGINAL_NODE) instanceof Node) {
$node->right->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
}

protected function pAttributeGroup(AttributeGroup $attributeGroup): string
{
$ret = parent::pAttributeGroup($attributeGroup);
Expand Down

0 comments on commit 11789be

Please sign in to comment.