[CodingStyle] Fix IdenticalFalseToBooleanNotRector for null|bool

This commit is contained in:
TomasVotruba 2019-12-29 13:16:03 +01:00
parent 214c69e1ec
commit 97e574e5f2
2 changed files with 30 additions and 4 deletions

View File

@ -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;
}
}

View File

@ -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) {
}
}
}