Lines
100.00%
17 / 17
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Generator | 100.00% | 17 / 17 | 100.00% | 3 / 3 | 3 | 100.00% | 1 / 1 | |||
| __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 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Codegen; | |
| 6 | ||
| 7 | use Stewart\Codegen\Emitter\SourceTree; | |
| 8 | use Stewart\Codegen\Exception\CodegenException; | |
| 9 | use Stewart\Codegen\Model\GenerationModelFactory; | |
| 10 | use Stewart\Codegen\Output\CheckResult; | |
| 11 | use Stewart\Codegen\Output\GenerationReport; | |
| 12 | use Stewart\Codegen\Output\OutputDirectory; | |
| 13 | use Stewart\Codegen\Output\ShrinkPolicy; | |
| 14 | use Stewart\Codegen\Snapshot\Snapshot; | |
| 15 | ||
| 16 | final 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 | } |