Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify UseIdenticalOverEqualWithSameTypeRector #5029

Merged
merged 2 commits into from
Sep 16, 2023
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);
}
}