diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/dynamic_bool.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/dynamic_bool.php.inc new file mode 100644 index 00000000..667e429b --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/dynamic_bool.php.inc @@ -0,0 +1,39 @@ +assertEquals($expected, $this->returnsBool($line)); + } + + public function returnsBool(): bool { + return rand(0,1) ? true : false; + } +} + +?> +----- +assertSame($expected, $this->returnsBool($line)); + } + + public function returnsBool(): bool { + return rand(0,1) ? true : false; + } +} + +?> diff --git a/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php b/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php index 4c60861f..6d5ae2e4 100644 --- a/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php +++ b/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php @@ -10,7 +10,9 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Scalar\InterpolatedString; +use PHPStan\Type\BooleanType; use PHPStan\Type\Constant\ConstantArrayType; +use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\FloatType; use PHPStan\Type\IntegerType; use PHPStan\Type\StringType; @@ -143,7 +145,11 @@ private function isScalarType(Type $valueNodeType): bool } } - return false; + if ($valueNodeType instanceof ConstantBooleanType) { + return false; + } + + return $valueNodeType instanceof BooleanType; } private function isScalarOrEnumValue(Expr $expr): bool