From 63472ea342fc243ca4239646cecf7f44875192c0 Mon Sep 17 00:00:00 2001 From: JW de Roos Date: Tue, 9 Dec 2025 12:35:39 +0100 Subject: [PATCH 1/2] Create identical_enclosed_ternary.php.inc Enclosed ternary comparations should retain the parentheses --- .../identical_enclosed_ternary.php.inc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/identical_enclosed_ternary.php.inc diff --git a/rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/identical_enclosed_ternary.php.inc b/rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/identical_enclosed_ternary.php.inc new file mode 100644 index 00000000000..be36a00554c --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/identical_enclosed_ternary.php.inc @@ -0,0 +1,19 @@ + +----- + From 0b8d3489711304b09347d87a5b0f49e0d18a7d1c Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 10 Dec 2025 03:00:37 +0700 Subject: [PATCH 2/2] fix --- .../Equal/UseIdenticalOverEqualWithSameTypeRector.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php b/rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php index 32a9e5043df..3c8e87d016f 100644 --- a/rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php +++ b/rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotEqual; use PhpParser\Node\Expr\BinaryOp\NotIdentical; +use PhpParser\Node\Expr\Ternary; use PHPStan\Type\BooleanType; use PHPStan\Type\FloatType; use PHPStan\Type\IntegerType; @@ -17,6 +18,7 @@ use PHPStan\Type\StringType; use PHPStan\Type\Type; use PHPStan\Type\TypeTraverser; +use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -135,6 +137,14 @@ private function normalizeScalarType(Type $type): Type private function processIdenticalOrNotIdentical(Equal|NotEqual $node): Identical|NotIdentical { + if ($node->left instanceof Ternary) { + $node->left->setAttribute(AttributeKey::WRAPPED_IN_PARENTHESES, true); + } + + if ($node->right instanceof Ternary) { + $node->right->setAttribute(AttributeKey::WRAPPED_IN_PARENTHESES, true); + } + if ($node instanceof Equal) { return new Identical($node->left, $node->right); }