Lines
17.64%
3 / 17
Functions and Methods
60.00%
3 / 5
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ReloadCheckReport | 17.64% | 3 / 17 | 60.00% | 3 / 5 | 18.96 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| fromDiscovery | 0.00% | 0 / 8 | 0.00% | 0 / 1 | 2 | |||||
| failed | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| findFirstError | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| restoreDiscovery | 0.00% | 0 / 6 | 0.00% | 0 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Broker\Reload; | |
| 6 | ||
| 7 | use Stewart\Contracts\App\AppId; | |
| 8 | use Stewart\Contracts\Wire\ListOf; | |
| 9 | use Stewart\Runtime\App\Collection\DiscoveredAppCollection; | |
| 10 | use Stewart\Runtime\App\Collection\UnloadableAppFileCollection; | |
| 11 | use Stewart\Runtime\App\Collection\UnmarkedAppCollection; | |
| 12 | use Stewart\Runtime\App\DiscoveredApp; | |
| 13 | use Stewart\Runtime\App\DiscoveryResult; | |
| 14 | use Stewart\Runtime\App\UnmarkedApp; | |
| 15 | use Stewart\Runtime\Broker\GeneratedManifest; | |
| 16 | ||
| 17 | // What reload:check found, from a process that could load the apps fresh; it carries no option values. | |
| 18 | final readonly class ReloadCheckReport | |
| 19 | { | |
| 20 | /** | |
| 21 | * @param list<ReloadCheckApp> $apps | |
| 22 | * @param list<class-string> $unmarkedClasses | |
| 23 | * @param list<string> $errors | |
| 24 | * @param list<class-string> $templateClasses | |
| 25 | */ | |
| 26 | public function __construct( | |
| 27 | #[ListOf(ReloadCheckApp::class)] | |
| 28 | public array $apps, | |
| 29 | #[ListOf('string')] | |
| 30 | public array $unmarkedClasses, | |
| 31 | #[ListOf('string')] | |
| 32 | public array $errors, | |
| 33 | public string $configFingerprint, | |
| 34 | public ?GeneratedManifest $generated = null, | |
| 35 | #[ListOf('string')] | |
| 36 | public array $templateClasses = [], | |
| 37 | ) {} | |
| 38 | ||
| 39 | public static function fromDiscovery(DiscoveryResult $discovered, string $configFingerprint, ?GeneratedManifest $generated): self | |
| 40 | { | |
| 41 | return new self( | |
| 42 | $discovered->apps->mapToList(static fn(DiscoveredApp $app): ReloadCheckApp => new ReloadCheckApp($app->id->value, $app->class, $app->origin)), | |
| 43 | $discovered->unmarked->mapToList(static fn(UnmarkedApp $app): string => $app->class), | |
| 44 | [], | |
| 45 | $configFingerprint, | |
| 46 | $generated, | |
| 47 | $discovered->templateClasses, | |
| 48 | ); | |
| 49 | } | |
| 50 | ||
| 51 | /** @param list<string> $errors */ | |
| 52 | public static function failed(array $errors, string $configFingerprint = ''): self | |
| 53 | { | |
| 54 | return new self([], [], $errors, $configFingerprint); | |
| 55 | } | |
| 56 | ||
| 57 | public function findFirstError(): ?string | |
| 58 | { | |
| 59 | return $this->errors[0] ?? null; | |
| 60 | } | |
| 61 | ||
| 62 | public function restoreDiscovery(): DiscoveryResult | |
| 63 | { | |
| 64 | return new DiscoveryResult( | |
| 65 | DiscoveredAppCollection::fromApps(array_map(static fn(ReloadCheckApp $app): DiscoveredApp => new DiscoveredApp($app->class, new AppId($app->id), $app->origin), $this->apps)), | |
| 66 | UnmarkedAppCollection::fromList(array_map(static fn(string $class): UnmarkedApp => new UnmarkedApp($class), $this->unmarkedClasses)), | |
| 67 | UnloadableAppFileCollection::empty(), | |
| 68 | $this->templateClasses, | |
| 69 | ); | |
| 70 | } | |
| 71 | } |