Skip to content
Merged
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
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);
}
}