Skip to content

Commit

Permalink
add null/false/true support
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jan 19, 2025
1 parent f452fac commit a880233
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\FlipAssertRector\Fixture;

final class AssertSameNull extends \PHPUnit\Framework\TestCase
{
public function test()
{
$result = '...';
$this->assertSame($result, null);
$this->assertNotSame($result, false);
}
}

?>
-----
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\FlipAssertRector\Fixture;

final class AssertSameNull extends \PHPUnit\Framework\TestCase
{
public function test()
{
$result = '...';
$this->assertSame(null, $result);
$this->assertNotSame(false, $result);
}
}

?>
5 changes: 5 additions & 0 deletions rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Scalar;
Expand Down Expand Up @@ -119,6 +120,10 @@ private function isScalarValue(Expr $expr): bool
return true;
}

if ($expr instanceof ConstFetch) {
return true;
}

return $expr instanceof ClassConstFetch;
}
}

0 comments on commit a880233

Please sign in to comment.