-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathAssertSameNullExpectedRule.php
51 lines (41 loc) · 1.11 KB
/
AssertSameNullExpectedRule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php declare(strict_types = 1);
namespace PHPStan\Rules\PHPUnit;
use PhpParser\Node;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\ConstFetch;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use function count;
/**
* @implements Rule<CallLike>
*/
class AssertSameNullExpectedRule implements Rule
{
public function getNodeType(): string
{
return CallLike::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (!AssertRuleHelper::isMethodOrStaticCallOnAssert($node, $scope)) {
return [];
}
if (count($node->getArgs()) < 2) {
return [];
}
if (!$node->name instanceof Node\Identifier || $node->name->toLowerString() !== 'assertsame') {
return [];
}
$expectedArgumentValue = $node->getArgs()[0]->value;
if (!($expectedArgumentValue instanceof ConstFetch)) {
return [];
}
if ($expectedArgumentValue->name->toLowerString() === 'null') {
return [
RuleErrorBuilder::message('You should use assertNull() instead of assertSame(null, $actual).')->identifier('phpunit.assertNull')->build(),
];
}
return [];
}
}