| Conditions | 5 |
| Paths | 4 |
| Total Lines | 18 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | public function populate(string $class, array $data, $relations = false) |
||
| 33 | { |
||
| 34 | $itemMap = ArrayHelper::getValue($this->map(), "$class.item", []); |
||
| 35 | |||
| 36 | $model = new $class(); |
||
| 37 | foreach ($itemMap as $to => $from) { |
||
| 38 | $model->$to = ArrayHelper::getValue($data, $from); |
||
| 39 | } |
||
| 40 | |||
| 41 | $relationsMap = ArrayHelper::getValue($this->map(), "$class.relations"); |
||
| 42 | if ($relations && $relationsMap) { |
||
| 43 | foreach ($relationsMap as $to => $class) { |
||
| 44 | $relationData = $this->normalizeData($class, $data); |
||
| 45 | $model->$to = $this->populate($class, $relationData); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | return $model; |
||
| 50 | } |
||
| 52 | } |