Skip to content

Commit 676ad27

Browse files
committed
Internal PHPStan rule - attributes must have named arguments
1 parent f001793 commit 676ad27

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Build;
4+
5+
use PhpParser\Node;
6+
use PhpParser\Node\Attribute;
7+
use PHPStan\Analyser\Scope;
8+
use PHPStan\Rules\Rule;
9+
use PHPStan\Rules\RuleErrorBuilder;
10+
use function sprintf;
11+
12+
/**
13+
* @implements Rule<Attribute>
14+
*/
15+
final class AttributeNamedArgumentsRule implements Rule
16+
{
17+
18+
public function getNodeType(): string
19+
{
20+
return Attribute::class;
21+
}
22+
23+
public function processNode(Node $node, Scope $scope): array
24+
{
25+
foreach ($node->args as $arg) {
26+
if ($arg->name !== null) {
27+
continue;
28+
}
29+
30+
return [
31+
RuleErrorBuilder::message(sprintf('Attribute %s is not using named arguments.', $node->name->toString()))
32+
->identifier('phpstan.attributeWithoutNamedArguments')
33+
->nonIgnorable()
34+
->build(),
35+
];
36+
}
37+
38+
return [];
39+
}
40+
41+
}

build/phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ parameters:
117117

118118
rules:
119119
- PHPStan\Build\FinalClassRule
120+
- PHPStan\Build\AttributeNamedArgumentsRule
120121

121122
services:
122123
-

0 commit comments

Comments
 (0)