Lines
100.00%
8 / 8
Methods
100.00%
5 / 5
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| readFromClass | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 3 | ||
| findForGeneratedCode | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| hasCurrentFormat | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| findDrift | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 15 | final readonly class GeneratedManifest | |
| 16 | { | |
| 17 | /** | |
| 18 | * @param list<string> $entityIds | |
| 19 | * @param list<string> $ignoredEntityIds | |
| 20 | */ | |
| 21 | public function __construct( | |
| 22 | public int $formatVersion, | |
| 23 | #[ListOf('string')] | |
| 24 | public array $entityIds, | |
| 25 | #[ListOf('string')] | |
| 26 | public array $ignoredEntityIds, | |
| 27 | ) {} | |
| 28 | ||
| 29 | /** @param class-string<Manifest> $manifest */ | |
| 30 | public static function readFromClass(string $manifest): self | |
| 31 | { | |
| 32 | $constant = $manifest . '::' . GeneratedFormat::MANIFEST_CONSTANT; | |
| 33 | $version = \defined($constant) ? \constant($constant) : 0; | |
| 34 | ||
| 35 | return new self(\is_int($version) ? $version : 0, $manifest::listEntityIds(), $manifest::listIgnoredEntityIds()); | |
| 36 | } | |
| 37 | ||
| 38 | /** @throws AppException */ | |
| 39 | public static function findForGeneratedCode(CodegenConfig $codegen): ?self | |
| 40 | { | |
| 41 | $manifest = GeneratedRoots::fromNamespace($codegen->namespace->value)?->manifestClass; | |
| 42 | ||
| 43 | return $manifest === null ? null : self::readFromClass($manifest); | |
| 44 | } | |
| 45 | ||
| 46 | public function hasCurrentFormat(): bool | |
| 47 | { | |
| 48 | return $this->formatVersion === GeneratedFormat::VERSION; | |
| 49 | } | |
| 50 | ||
| 51 | /** @param list<string> $liveEntityIds */ | |
| 52 | public function findDrift(array $liveEntityIds): ManifestDrift | |
| 53 | { | |
| 54 | return ManifestDrift::calculateBetween($this->entityIds, $liveEntityIds, $this->ignoredEntityIds); | |
| 55 | } | |
| 56 | } |