Lines
100.00%
10 / 10
Methods
100.00%
5 / 5
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| forGeneratedCode | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| readFormatVersion | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 3 | ||
| hasCurrentFormat | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| findDrift | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | ||
| 12 | final readonly class ManifestCheck | |
| 13 | { | |
| 14 | /** @param class-string<Manifest> $manifest */ | |
| 15 | public function __construct(private string $manifest) {} | |
| 16 | ||
| 17 | public static function forGeneratedCode(CodegenConfig $codegen): ?self | |
| 18 | { | |
| 19 | $manifest = GeneratedRoots::fromNamespace($codegen->namespace->value)?->manifestClass; | |
| 20 | ||
| 21 | return $manifest === null ? null : new self($manifest); | |
| 22 | } | |
| 23 | ||
| 24 | public function readFormatVersion(): int | |
| 25 | { | |
| 26 | $constant = $this->manifest . '::' . GeneratedFormat::MANIFEST_CONSTANT; | |
| 27 | $version = \defined($constant) ? \constant($constant) : 0; | |
| 28 | ||
| 29 | return \is_int($version) ? $version : 0; | |
| 30 | } | |
| 31 | ||
| 32 | public function hasCurrentFormat(): bool | |
| 33 | { | |
| 34 | return $this->readFormatVersion() === GeneratedFormat::VERSION; | |
| 35 | } | |
| 36 | ||
| 37 | /** @param list<string> $liveEntityIds */ | |
| 38 | public function findDrift(array $liveEntityIds): ?ManifestDrift | |
| 39 | { | |
| 40 | $manifest = $this->manifest; | |
| 41 | $drift = ManifestDrift::calculateBetween($manifest::listEntityIds(), $liveEntityIds, $manifest::listIgnoredEntityIds()); | |
| 42 | ||
| 43 | return $drift->isEmpty() ? null : $drift; | |
| 44 | } | |
| 45 | } |