diff --git a/rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture/assign_on_right.php.inc b/rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture/assign_on_right.php.inc new file mode 100644 index 00000000000..400dfa49381 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture/assign_on_right.php.inc @@ -0,0 +1,15 @@ + +----- + diff --git a/src/PhpParser/Printer/BetterStandardPrinter.php b/src/PhpParser/Printer/BetterStandardPrinter.php index 96067ef515f..f2f18342f9c 100644 --- a/src/PhpParser/Printer/BetterStandardPrinter.php +++ b/src/PhpParser/Printer/BetterStandardPrinter.php @@ -478,6 +478,12 @@ private function wrapBinaryOpWithBrackets(Node $node): void $node->left->setAttribute(AttributeKey::ORIGINAL_NODE, null); } + if ($node->right instanceof Assign + && $this->origTokens instanceof TokenStream + && ! $this->origTokens->haveParens($node->right->getStartTokenPos(), $node->right->getEndTokenPos())) { + $node->right->setAttribute(AttributeKey::ORIGINAL_NODE, null); + } + if ($node->left instanceof BinaryOp && $node->left->getAttribute(AttributeKey::ORIGINAL_NODE) instanceof Node) { $node->left->setAttribute(AttributeKey::ORIGINAL_NODE, null);