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,18 @@
<?php

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

/**
* @see https://3v4l.org/I3GQS
*/
final class SkipBoolEqualFloat
{
public function equal()
{
// maybe compare to numeric string
$value = rand(0, 1) ? 1.0 : null;

var_dump(true == $value);
var_dump($value == true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,33 @@ public function refactor(Node $node): ?Node

private function shouldSkipCompareBoolToNumeric(Type $leftStaticType, Type $rightStaticType): bool
{
// use ! ->no() as to verify both yes and maybe
if ($leftStaticType instanceof BooleanType) {
if (! $rightStaticType->isNumericString()->no()) {
return true;
}

return ! $rightStaticType->isInteger()
->no();
return $this->shouldSkipNumericType($rightStaticType);
}

if ($rightStaticType instanceof BooleanType) {
if (! $leftStaticType->isNumericString()->no()) {
return true;
}

return ! $leftStaticType->isInteger()
->no();
return $this->shouldSkipNumericType($leftStaticType);
}

return false;
}

private function shouldSkipNumericType(Type $type): bool
{
// use ! ->no() as to verify both yes and maybe
if (! $type->isNumericString()->no()) {
return true;
}

if (! $type->isInteger()
->no()) {
return true;
}

return ! $type->isFloat()
->no();
}

private function processIdenticalOrNotIdentical(Equal|NotEqual $node): Identical|NotIdentical
{
if ($node instanceof Equal) {
Expand Down