Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector\Fixture;

if ((true ? 1 : 0) != (true ? 1 : 0)) {

}

?>
-----
<?php

namespace Rector\Tests\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector\Fixture;

if ((true ? 1 : 0) !== (true ? 1 : 0)) {

}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
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;
use PHPStan\Type\MixedType;
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;
Expand Down Expand Up @@ -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);
}
Expand Down