| Total Complexity | 10 |
| Total Lines | 83 |
| Duplicated Lines | 0 % |
| Coverage | 51.61% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 10 | abstract class CodeGenerator |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | public $name; |
||
| 16 | |||
| 17 | 10 | public function __construct(string $name) |
|
| 18 | { |
||
| 19 | 10 | $this->name = $name; |
|
| 20 | 10 | } |
|
| 21 | |||
| 22 | 10 | public function getName(): string |
|
| 23 | { |
||
| 24 | 10 | return $this->name; |
|
| 25 | } |
||
| 26 | |||
| 27 | public function datatypeDeclarations(): string |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Returns a single declaration for a specific datatype. |
||
| 44 | * |
||
| 45 | * @param Datatype $datatype |
||
| 46 | * @return string |
||
| 47 | */ |
||
| 48 | public function datatypeDeclaration(Datatype $datatype): string |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Generates fields code for this model. |
||
| 56 | * |
||
| 57 | * @return string[] |
||
| 58 | */ |
||
| 59 | 10 | public function fields(Model $model): array |
|
| 60 | { |
||
| 61 | 10 | $defs = []; |
|
| 62 | 10 | foreach ($model->getFields() as $field) { |
|
| 63 | 10 | $d = $this->field($field); |
|
| 64 | 10 | if (is_array($d)) { |
|
| 65 | $defs += $d; |
||
| 66 | 10 | } elseif (is_string($d)) { |
|
| 67 | 10 | $defs[$field->getName()] = $d; |
|
| 68 | } |
||
| 69 | } |
||
| 70 | 10 | return $defs; |
|
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Generates fields code for this model. |
||
| 75 | * |
||
| 76 | * @return string|string[] |
||
| 77 | */ |
||
| 78 | 10 | public function field(Field $field) |
|
| 82 | } |
||
| 83 | |||
| 84 | abstract public function type(Model $model): string; |
||
| 85 | |||
| 86 | public function variable(Field $field): string |
||
| 90 | } |
||
| 91 | |||
| 92 | abstract public function getFilename(string $base): string; |
||
| 93 | } |
||
| 94 |