diff --git a/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php b/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php index ae23ee1a1a4..7acbe64a264 100644 --- a/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php +++ b/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php @@ -27,7 +27,6 @@ use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; -use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\TypeAnalyzer\ArrayTypeAnalyzer; use Rector\NodeTypeResolver\TypeAnalyzer\StringTypeAnalyzer; use Rector\PhpParser\Node\Value\ValueResolver; @@ -125,9 +124,6 @@ CODE_SAMPLE $node->cond = $binaryOp; return [$expression, $node]; } - if ($node->cond instanceof Assign) { - $binaryOp->left->setAttribute(AttributeKey::WRAPPED_IN_PARENTHESES, \true); - } $node->cond = $binaryOp; return $node; } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 8c71cf42fab..1cc7cd5d5f9 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '9691e9eaf4400f57e9008c409756dae37efdde7e'; + public const PACKAGE_VERSION = 'e4e77b2fe9ddefec46aeea5b18ea90ade7188874'; /** * @api * @var string */ - public const RELEASE_DATE = '2025-01-20 12:29:31'; + public const RELEASE_DATE = '2025-01-21 19:26:17'; /** * @var int */ diff --git a/src/PhpParser/Printer/BetterStandardPrinter.php b/src/PhpParser/Printer/BetterStandardPrinter.php index ee2783fe87e..e188332f817 100644 --- a/src/PhpParser/Printer/BetterStandardPrinter.php +++ b/src/PhpParser/Printer/BetterStandardPrinter.php @@ -11,6 +11,7 @@ use PhpParser\Node\AttributeGroup; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrowFunction; +use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\CallLike; use PhpParser\Node\Expr\Match_; use PhpParser\Node\Expr\MethodCall; @@ -316,6 +317,19 @@ final class BetterStandardPrinter extends Standard { return $this->pAttrGroups($param->attrGroups) . $this->pModifiers($param->flags) . ($param->type instanceof Node ? $this->p($param->type) . ' ' : '') . ($param->byRef ? '&' : '') . ($param->variadic ? '...' : '') . $this->p($param->var) . ($param->default instanceof Expr ? ' = ' . $this->p($param->default) : '') . ($param->hooks !== [] ? ' {' . $this->pStmts($param->hooks) . $this->nl . '}' : ''); } + protected function pInfixOp(string $class, Node $leftNode, string $operatorString, Node $rightNode, int $precedence, int $lhsPrecedence) : string + { + /** + * ensure left side is assign and right side is just created + * + * @see https://github.com/rectorphp/rector-src/pull/6668 + * @see https://github.com/rectorphp/rector/issues/8980 + */ + if ($leftNode instanceof Assign && $leftNode->getStartTokenPos() > 0 && $rightNode->getStartTokenPos() < 0) { + $leftNode->setAttribute(AttributeKey::WRAPPED_IN_PARENTHESES, \true); + } + return parent::pInfixOp($class, $leftNode, $operatorString, $rightNode, $precedence, $lhsPrecedence); + } private function cleanStartIndentationOnHeredocNowDoc(string $content) : string { $lines = NewLineSplitter::split($content);