forked from phpstan/phpstan-phpunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssertSameWithCountRule.php
49 lines (39 loc) · 1.05 KB
/
AssertSameWithCountRule.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
<?php declare(strict_types = 1);
namespace PHPStan\Rules\PHPUnit;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
class AssertSameWithCountRule implements \PHPStan\Rules\Rule
{
public function getNodeType(): string
{
return \PhpParser\NodeAbstract::class;
}
/**
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node
* @param \PHPStan\Analyser\Scope $scope
* @return string[] errors
*/
public function processNode(Node $node, Scope $scope): array
{
if (!AssertRuleHelper::isMethodOrStaticCallOnTestCase($node, $scope)) {
return [];
}
if (count($node->args) < 2) {
return [];
}
if (!is_string($node->name) || strtolower($node->name) !== 'assertsame') {
return [];
}
$right = $node->args[1]->value;
if (
$right instanceof Node\Expr\FuncCall
&& $right->name instanceof Node\Name
&& strtolower($right->name->toString()) === 'count'
) {
return [
'You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)).',
];
}
return [];
}
}