Lines
92.85%
13 / 14
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| GeneratedCodeFromOlderMajorRule | 92.85% | 13 / 14 | 50.00% | 1 / 2 | 3.00 | 0.00% | 0 / 1 | |||
| getNodeType | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| processNode | 92.30% | 12 / 13 | 0.00% | 0 / 1 | 2.00 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\PHPStan\Rule; | |
| 6 | ||
| 7 | use PhpParser\Node; | |
| 8 | use PHPStan\Analyser\Scope; | |
| 9 | use PHPStan\Node\CollectedDataNode; | |
| 10 | use PHPStan\Rules\Rule; | |
| 11 | use PHPStan\Rules\RuleErrorBuilder; | |
| 12 | use Stewart\PHPStan\Collector\GeneratedCodeFromOlderMajorCollector; | |
| 13 | ||
| 14 | // Reported once per run, on the first analysed file, since the generated classes are usually not analysed. | |
| 15 | /** @implements Rule<CollectedDataNode> */ | |
| 16 | final readonly class GeneratedCodeFromOlderMajorRule implements Rule | |
| 17 | { | |
| 18 | private const string IDENTIFIER = 'stewart.generatedCode'; | |
| 19 | ||
| 20 | public function getNodeType(): string | |
| 21 | { | |
| 22 | return CollectedDataNode::class; | |
| 23 | } | |
| 24 | ||
| 25 | public function processNode(Node $node, Scope $scope): array | |
| 26 | { | |
| 27 | $collected = $node->get(GeneratedCodeFromOlderMajorCollector::class); | |
| 28 | ||
| 29 | if ($collected === []) { | |
| 30 | return []; | |
| 31 | } | |
| 32 | ||
| 33 | ksort($collected); | |
| 34 | $file = (string) array_key_first($collected); | |
| 35 | ||
| 36 | return [ | |
| 37 | RuleErrorBuilder::message(\sprintf('%s was generated by Stewart 1.x, so entity IDs and action names go unchecked.', $collected[$file][0])) | |
| 38 | ->identifier(self::IDENTIFIER) | |
| 39 | ->tip('Run `make generate`.') | |
| 40 | ->file($file) | |
| 41 | ->line(1) | |
| 42 | ->build(), | |
| 43 | ]; | |
| 44 | } | |
| 45 | } |