Lines 100.00% 12 / 12
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
CodegenConfig 100.00% 12 / 12 100.00% 2 / 2 2 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 fromSection 100.00% 11 / 11 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Config;
6
7use Stewart\Runtime\Config\Collection\DomainAttributesConfigCollection;
8use Stewart\Runtime\Exception\ConfigurationException;
9
10final readonly class CodegenConfig
11{
12    /**
13     * @param list<string> $include
14     * @param list<string> $exclude
15     */
16    public function __construct(
17        public ClassNamespace $namespace,
18        public ProjectDirectory $outputDir,
19        public array $include,
20        public array $exclude,
21        public DomainAttributesConfigCollection $attributes,
22    ) {}
23
24    /** @throws ConfigurationException */
25    public static function fromSection(ConfigSection $codegen, GeneratedNamespaceResolver $namespaces): self
26    {
27        $outputDir = $codegen->readParsedValue('output_dir', static fn(string $directory): ProjectDirectory => new ProjectDirectory($directory));
28
29        return new self(
30            namespace: $codegen->findParsedValue('namespace', static fn(string $namespace): ClassNamespace => new ClassNamespace($namespace))
31                ?? $namespaces->resolveNamespaceFor($outputDir),
32            outputDir: $outputDir,
33            include: $codegen->readStringList('include'),
34            exclude: $codegen->readStringList('exclude'),
35            attributes: DomainAttributesConfigCollection::keyedByDomain(
36                $codegen->readSection('attributes')->mapSubsections(DomainAttributesConfig::fromSection(...)),
37            ),
38        );
39    }
40}