Skip to content

Commit

Permalink
Simplify UseIdenticalOverEqualWithSameTypeRector (#5029)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Sep 16, 2023
1 parent c8ff683 commit 0acf4bd
Showing 1 changed file with 2 additions and 20 deletions.
Expand Up @@ -22,11 +22,6 @@
*/
final class UseIdenticalOverEqualWithSameTypeRector extends AbstractRector
{
public function __construct(
private readonly ExprAnalyzer $exprAnalyzer
) {
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down Expand Up @@ -72,7 +67,7 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$leftStaticType = $this->getType($node->left);
$leftStaticType = $this->nodeTypeResolver->getNativeType($node->left);

// objects can be different by content
if ($leftStaticType instanceof ObjectType) {
Expand All @@ -83,7 +78,7 @@ public function refactor(Node $node): ?Node
return null;
}

$rightStaticType = $this->getType($node->right);
$rightStaticType = $this->nodeTypeResolver->getNativeType($node->right);
if ($rightStaticType instanceof MixedType) {
return null;
}
Expand All @@ -93,23 +88,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($this->areNonTypedFromParam($node->left, $node->right)) {
return null;
}

if ($node instanceof Equal) {
return new Identical($node->left, $node->right);
}

return new NotIdentical($node->left, $node->right);
}

private function areNonTypedFromParam(Expr $left, Expr $right): bool
{
if ($this->exprAnalyzer->isNonTypedFromParam($left)) {
return true;
}

return $this->exprAnalyzer->isNonTypedFromParam($right);
}
}

0 comments on commit 0acf4bd

Please sign in to comment.