| Conditions | 6 |
| Paths | 10 |
| Total Lines | 37 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 24 |
| CRAP Score | 6 |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 27 | 15 | protected function createObject($table, $row) |
|
| 28 | { |
||
| 29 | 15 | $newTable = ucfirst(singular($table)); |
|
| 30 | 15 | $model = new $newTable; |
|
| 31 | |||
| 32 | 15 | if ( ! array_key_exists($newTable, $this->tables)) { |
|
| 33 | 15 | $tableInfo = $this->describe->getTable($newTable); |
|
| 34 | |||
| 35 | 15 | $this->tables[$newTable] = $tableInfo; |
|
| 36 | 15 | } else { |
|
| 37 | 12 | $tableInfo = $this->tables[$newTable]; |
|
| 38 | } |
||
| 39 | |||
| 40 | 15 | foreach ($row as $key => $value) { |
|
| 41 | 15 | foreach ($tableInfo as $column) { |
|
| 42 | 15 | if ($column->getField() != $key) { |
|
| 43 | 15 | continue; |
|
| 44 | } |
||
| 45 | |||
| 46 | 15 | $model->$key = $value; |
|
| 47 | |||
| 48 | 15 | if ($column->isForeignKey()) { |
|
| 49 | 15 | $foreignColumn = $column->getReferencedField(); |
|
| 50 | 15 | $foreignTable = $column->getReferencedTable(); |
|
| 51 | |||
| 52 | 15 | $delimiters = [ $foreignColumn => $value ]; |
|
| 53 | 15 | $foreignData = $this->find($foreignTable, $delimiters); |
|
| 54 | |||
| 55 | 15 | $newColumn = singular($foreignTable); |
|
| 56 | |||
| 57 | 15 | $model->$newColumn = $foreignData; |
|
| 58 | 15 | } |
|
| 59 | 15 | } |
|
| 60 | 15 | } |
|
| 61 | |||
| 62 | 15 | return $model; |
|
| 63 | } |
||
| 64 | |||
| 75 |