Lines 17.64% 3 / 17
Methods 60.00% 3 / 5
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __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
18final 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}