forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThisInStaticStatementRule.php
More file actions
44 lines (36 loc) · 871 Bytes
/
ThisInStaticStatementRule.php
File metadata and controls
44 lines (36 loc) · 871 Bytes
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
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Variables;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\DependencyInjection\RegisteredRule;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use function is_string;
/**
* @implements Rule<Node\Stmt\Static_>
*/
#[RegisteredRule(level: 0)]
final class ThisInStaticStatementRule implements Rule
{
public function getNodeType(): string
{
return Node\Stmt\Static_::class;
}
public function processNode(Node $node, Scope $scope): array
{
$errors = [];
foreach ($node->vars as $var) {
if (!is_string($var->var->name)) {
continue;
}
if ($var->var->name !== 'this') {
continue;
}
$errors[] = RuleErrorBuilder::message('Cannot use $this as static variable.')
->identifier('static.this')
->nonIgnorable()
->build();
}
return $errors;
}
}