Lines
100.00%
19 / 19
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ManifestEmitter | 100.00% | 19 / 19 | 100.00% | 1 / 1 | 1 | 100.00% | 1 / 1 | |||
| emitFile | 100.00% | 19 / 19 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Codegen\Emitter; | |
| 6 | ||
| 7 | use Stewart\Codegen\Model\GenerationModel; | |
| 8 | use Stewart\Codegen\Output\GeneratedFile; | |
| 9 | use Stewart\Contracts\Generated\Manifest; | |
| 10 | use Stewart\Support\Wire\GeneratedFormat; | |
| 11 | ||
| 12 | final readonly class ManifestEmitter implements ModelFileEmitter | |
| 13 | { | |
| 14 | public const string CLASS_NAME = 'Manifest'; | |
| 15 | ||
| 16 | public function emitFile(GenerationModel $model, EmitContext $context): GeneratedFile | |
| 17 | { | |
| 18 | $namespace = $context->createNamespace(); | |
| 19 | $context->importClass($namespace, Manifest::class, self::CLASS_NAME); | |
| 20 | ||
| 21 | $class = $namespace->addClass(self::CLASS_NAME) | |
| 22 | ->setFinal() | |
| 23 | ->addComment('What `stewart generate` saw.'); | |
| 24 | ||
| 25 | $class->addImplement(Manifest::class); | |
| 26 | $class->addConstant(GeneratedFormat::MANIFEST_CONSTANT, GeneratedFormat::VERSION)->setType('int')->setPublic(); | |
| 27 | $class->addMethod('__construct')->setPrivate(); | |
| 28 | ||
| 29 | $class->addMethod('listEntityIds') | |
| 30 | ->setStatic() | |
| 31 | ->setReturnType('array') | |
| 32 | ->addComment('@return list<string>') | |
| 33 | ->setBody('return ?;', [$model->entityIds->toStrings()]); | |
| 34 | ||
| 35 | $class->addMethod('listIgnoredEntityIds') | |
| 36 | ->setStatic() | |
| 37 | ->setReturnType('array') | |
| 38 | ->addComment('@return list<string>') | |
| 39 | ->setBody('return ?;', [$model->ignoredEntityIds->toStrings()]); | |
| 40 | ||
| 41 | return $context->printFile($namespace, self::CLASS_NAME); | |
| 42 | } | |
| 43 | } |