1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | namespace Nexus\PHPStan\Rules\Enums; |
15: | |
16: | use PhpParser\Node; |
17: | use PHPStan\Analyser\Scope; |
18: | use PHPStan\Rules\Rule; |
19: | use PHPStan\Rules\RuleErrorBuilder; |
20: | |
21: | |
22: | |
23: | |
24: | final class EnumCaseNamingRule implements Rule |
25: | { |
26: | public function getNodeType(): string |
27: | { |
28: | return Node\Stmt\EnumCase::class; |
29: | } |
30: | |
31: | public function processNode(Node $node, Scope $scope): array |
32: | { |
33: | $enumCaseName = $node->name->name; |
34: | |
35: | if (preg_match('/(?:[A-Z][a-z]+)+/', $enumCaseName) !== 1) { |
36: | return [ |
37: | RuleErrorBuilder::message(\sprintf( |
38: | 'Enum case "%s" should be in PascalCase format.', |
39: | $enumCaseName, |
40: | )) |
41: | ->identifier('nexus.enumCaseNaming') |
42: | ->build(), |
43: | ]; |
44: | } |
45: | |
46: | return []; |
47: | } |
48: | } |
49: | |