| Total Complexity | 9 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | class ComputeTypes implements CompilerInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Automatically clarify column types based on table column types. |
||
| 21 | * |
||
| 22 | * @param Registry $builder |
||
| 23 | * @param Entity $entity |
||
| 24 | */ |
||
| 25 | public function compute(Registry $builder, Entity $entity) |
||
| 26 | { |
||
| 27 | $table = $builder->getTable($entity); |
||
| 28 | |||
| 29 | foreach ($entity->getFields() as $field) { |
||
| 30 | if ($field->hasTypecast() || !$table->hasColumn($field->getColumn())) { |
||
| 31 | continue; |
||
| 32 | } |
||
| 33 | |||
| 34 | $column = $table->column($field->getColumn()); |
||
| 35 | |||
| 36 | $field->setTypecast($this->typecast($column)); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param AbstractColumn $column |
||
| 42 | * @return string|callable |
||
| 43 | */ |
||
| 44 | private function typecast(AbstractColumn $column) |
||
| 60 | } |
||
| 61 | } |