| Conditions | 4 |
| Paths | 4 |
| Total Lines | 19 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 11 | public function hydrateObjects($collectionPropertyName, $modelType, $records) |
||
| 12 | { |
||
| 13 | if(empty($records)) { |
||
| 14 | throw new \Exception('No records found'); |
||
| 15 | } else { |
||
| 16 | foreach($records as $item) { |
||
| 17 | // Requires a fully qualified namespace |
||
| 18 | $doc = new $modelType($this->app); |
||
| 19 | |||
| 20 | foreach($item as $key => $val) { |
||
| 21 | $doc->{$key} = $val; |
||
| 22 | } |
||
| 23 | |||
| 24 | $this->{$collectionPropertyName}[] = $doc; |
||
| 25 | } |
||
| 26 | |||
| 27 | return $this->{$collectionPropertyName}; |
||
| 28 | } |
||
| 29 | } |
||
| 30 | } |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.