diff --git a/rules-tests/Naming/Naming/PropertyNamingTest.php b/rules-tests/Naming/Naming/PropertyNamingTest.php index 52ee99d3487..57ae2baeb07 100644 --- a/rules-tests/Naming/Naming/PropertyNamingTest.php +++ b/rules-tests/Naming/Naming/PropertyNamingTest.php @@ -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()); diff --git a/src/DependencyInjection/LazyContainerFactory.php b/src/DependencyInjection/LazyContainerFactory.php index e9421c50ab4..85be0568482 100644 --- a/src/DependencyInjection/LazyContainerFactory.php +++ b/src/DependencyInjection/LazyContainerFactory.php @@ -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; @@ -241,7 +240,6 @@ final class LazyContainerFactory NameNodeVisitor::class, StaticVariableNodeVisitor::class, StmtKeyNodeVisitor::class, - ReprintNodeVisitor::class, ]; /** diff --git a/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ReprintNodeVisitor.php b/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ReprintNodeVisitor.php deleted file mode 100644 index 1457c0eab80..00000000000 --- a/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ReprintNodeVisitor.php +++ /dev/null @@ -1,40 +0,0 @@ -getAttribute(AttributeKey::ORIGINAL_NODE) instanceof Node) { - return null; - } - - if ($node instanceof BinaryOp && ! $node instanceof Coalesce) { - 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); - } - - return $node; - } - - return null; - } -} diff --git a/src/PhpParser/Printer/BetterStandardPrinter.php b/src/PhpParser/Printer/BetterStandardPrinter.php index 7bc032ef71d..c61600b413f 100644 --- a/src/PhpParser/Printer/BetterStandardPrinter.php +++ b/src/PhpParser/Printer/BetterStandardPrinter.php @@ -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_; @@ -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); @@ -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);