Lines 88.88% 8 / 9
Functions and Methods 66.66% 2 / 3
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
GeneratedRoots 88.88% 8 / 9 66.66% 2 / 3 6.05 0.00% 0 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 fromWorkerSettings 0.00% 0 / 1 0.00% 0 / 1 2
 fromNamespace 100.00% 7 / 7 100.00% 1 / 1 4
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\App;
6
7use Stewart\Contracts\Generated\Manifest;
8use Stewart\Runtime\Ipc\WorkerSettings;
9
10final readonly class GeneratedRoots
11{
12    /**
13     * @param class-string $entitiesClass
14     * @param class-string $servicesClass
15     * @param class-string<Manifest>|null $manifestClass
16     */
17    private function __construct(
18        public string $entitiesClass,
19        public string $servicesClass,
20        public ?string $manifestClass,
21    ) {}
22
23    public static function fromWorkerSettings(WorkerSettings $workerSettings): ?self
24    {
25        return self::fromNamespace($workerSettings->generatedNamespace);
26    }
27
28    public static function fromNamespace(string $generatedNamespace): ?self
29    {
30        $namespace = trim($generatedNamespace, '\\');
31        $entities = $namespace . '\\Entities';
32        $services = $namespace . '\\Services';
33
34        if (!class_exists($entities) || !class_exists($services)) {
35            return null;
36        }
37
38        $manifest = $namespace . '\\Manifest';
39
40        return new self($entities, $services, is_a($manifest, Manifest::class, true) ? $manifest : null);
41    }
42}