Lines 100.00% 10 / 10
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% 10 / 10 100.00% 2 / 2 2 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 fromSection 100.00% 9 / 9 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): self
26    {
27        return new self(
28            namespace: $codegen->readParsedValue('namespace', static fn(string $namespace): ClassNamespace => new ClassNamespace($namespace)),
29            outputDir: $codegen->readParsedValue('output_dir', static fn(string $directory): ProjectDirectory => new ProjectDirectory($directory)),
30            include: $codegen->readStringList('include'),
31            exclude: $codegen->readStringList('exclude'),
32            attributes: DomainAttributesConfigCollection::keyedByDomain(
33                $codegen->readSection('attributes')->mapSubsections(DomainAttributesConfig::fromSection(...)),
34            ),
35        );
36    }
37}