Skip to content

Commit 9fe16ab

Browse files
[CodeQuality] Allow dynamic bool on AssertEqualsToSameRector (#422)
* [CodeQuality] Allow dynamic bool on AssertEqualsToSameRector * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <actions@github.com>
1 parent 4bd1f6e commit 9fe16ab

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class DynamicBool extends TestCase
8+
{
9+
public function testIsHeaderLine(string $line, bool $expected): void
10+
{
11+
$this->assertEquals($expected, $this->returnsBool($line));
12+
}
13+
14+
public function returnsBool(): bool {
15+
return rand(0,1) ? true : false;
16+
}
17+
}
18+
19+
?>
20+
-----
21+
<?php
22+
23+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector\Fixture;
24+
25+
use PHPUnit\Framework\TestCase;
26+
27+
final class DynamicBool extends TestCase
28+
{
29+
public function testIsHeaderLine(string $line, bool $expected): void
30+
{
31+
$this->assertSame($expected, $this->returnsBool($line));
32+
}
33+
34+
public function returnsBool(): bool {
35+
return rand(0,1) ? true : false;
36+
}
37+
}
38+
39+
?>

rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
use PhpParser\Node\Expr\MethodCall;
1111
use PhpParser\Node\Expr\StaticCall;
1212
use PhpParser\Node\Scalar\InterpolatedString;
13+
use PHPStan\Type\BooleanType;
1314
use PHPStan\Type\Constant\ConstantArrayType;
15+
use PHPStan\Type\Constant\ConstantBooleanType;
1416
use PHPStan\Type\FloatType;
1517
use PHPStan\Type\IntegerType;
1618
use PHPStan\Type\StringType;
@@ -143,7 +145,11 @@ private function isScalarType(Type $valueNodeType): bool
143145
}
144146
}
145147

146-
return false;
148+
if ($valueNodeType instanceof ConstantBooleanType) {
149+
return false;
150+
}
151+
152+
return $valueNodeType instanceof BooleanType;
147153
}
148154

149155
private function isScalarOrEnumValue(Expr $expr): bool

0 commit comments

Comments
 (0)