mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-20 08:05:29 +01:00
Merge pull request #2520 from rectorphp/fix-identical-boolean-false
[CodingStyle] Fix IdenticalFalseToBooleanNotRector for null|bool
This commit is contained in:
commit
c2f76f54da
@ -9,9 +9,9 @@ use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\BinaryOp;
|
||||
use PhpParser\Node\Expr\BinaryOp\Identical;
|
||||
use PhpParser\Node\Expr\BooleanNot;
|
||||
use PHPStan\Type\Constant\ConstantBooleanType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\PhpParser\Node\Manipulator\BinaryOpManipulator;
|
||||
@ -101,8 +101,16 @@ final class IdenticalFalseToBooleanNotRector extends AbstractRector
|
||||
return false;
|
||||
}
|
||||
|
||||
return $staticType->isSuperTypeOf(new IntegerType())->yes() && $staticType->isSuperTypeOf(
|
||||
new ConstantBooleanType(false)
|
||||
)->yes();
|
||||
foreach ($staticType->getTypes() as $unionedType) {
|
||||
if ($unionedType instanceof NullType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($unionedType instanceof IntegerType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Identical\IdenticalFalseToBooleanNotRector\Fixture;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class SkipNullFalseAgain
|
||||
{
|
||||
public function someFunction(string $startStr, string $endStr)
|
||||
{
|
||||
$start = !empty($startStr) ? 1 : null;
|
||||
$end = !empty($endStr) ? 2 : null;
|
||||
|
||||
if (false === $end) {
|
||||
} elseif (false === $start) {
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user