1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus framework.
7: *
8: * (c) John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
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: * @implements Rule<Node\Stmt\EnumCase>
23: */
24: final class EnumCaseNamingRule implements Rule
25: {
26: #[\Override]
27: public function getNodeType(): string
28: {
29: return Node\Stmt\EnumCase::class;
30: }
31:
32: #[\Override]
33: public function processNode(Node $node, Scope $scope): array
34: {
35: $enumCaseName = $node->name->name;
36:
37: if (preg_match('/(?:[A-Z][a-z]+)+/', $enumCaseName) !== 1) {
38: return [
39: RuleErrorBuilder::message(\sprintf(
40: 'Enum case "%s" should be in PascalCase format.',
41: $enumCaseName,
42: ))
43: ->identifier('nexus.enumCaseNaming')
44: ->build(),
45: ];
46: }
47:
48: return [];
49: }
50: }
51: