Lines
100.00%
10 / 10
Functions and Methods
100.00%
5 / 5
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ManifestCheck | 100.00% | 10 / 10 | 100.00% | 5 / 5 | 9 | 100.00% | 1 / 1 | |||
| __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 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Broker; | |
| 6 | ||
| 7 | use Stewart\Contracts\Generated\Manifest; | |
| 8 | use Stewart\Runtime\App\GeneratedRoots; | |
| 9 | use Stewart\Runtime\Config\CodegenConfig; | |
| 10 | use Stewart\Support\Wire\GeneratedFormat; | |
| 11 | ||
| 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 | } |