Lines 100.00% 17 / 17
Methods 100.00% 3 / 3
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 writeFiles 100.00% 11 / 11 100.00% 1 / 1 1
 checkAgainstSnapshot 100.00% 5 / 5 100.00% 1 / 1 1
16final readonly class Generator
17{
18    public function __construct(
19        private GenerationModelFactory $models,
20        private SourceTree $sources,
21    ) {}
22
23    /** @throws CodegenException */
24    public function writeFiles(Snapshot $snapshot, GenerationTarget $target, GenerationOptions $options, ShrinkPolicy $shrinkPolicy): GenerationReport
25    {
26        $model = $this->models->buildModelFromSnapshot($snapshot, $options);
27
28        return new GenerationReport(
29            changes: new OutputDirectory($target->directory)->writeChanges($this->sources->renderFiles($model, $target), $shrinkPolicy),
30            entities: $model->countEntities(),
31            domains: \count($model->listEntityDomains()),
32            services: $model->countServices(),
33            ignored: \count($model->ignoredEntityIds),
34            attributes: $model->countAttributes(),
35            warnings: $model->warnings,
36            haVersion: $snapshot->haVersion,
37        );
38    }
39
40    /** @throws CodegenException */
41    public function checkAgainstSnapshot(Snapshot $snapshot, GenerationTarget $target, GenerationOptions $options): CheckResult
42    {
43        $model = $this->models->buildModelFromSnapshot($snapshot, $options);
44
45        return new CheckResult(
46            new OutputDirectory($target->directory)->planChanges($this->sources->renderFiles($model, $target)),
47            $model->warnings,
48        );
49    }
50}