| Conditions | 7 |
| Paths | 10 |
| Total Lines | 16 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 7 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | 7 | public function addTreeStructure($data) |
|
| 18 | {
|
||
| 19 | 7 | $tree = isset($this->tree) ? $this->tree : []; |
|
| 20 | |||
| 21 | 7 | foreach ( $data as $rec ) {
|
|
| 22 | 7 | if ( is_object($rec) === false ) throw new Exception('data record must be object.');
|
|
| 23 | 6 | if ( isset($rec->id) === false ) throw new Exception('data record object does not have property => "id".');
|
|
| 24 | 5 | if ( isset($rec->parent_id) === false || ! $rec->parent_id ) {
|
|
| 25 | 5 | $rec->children = []; |
|
| 26 | 5 | $tree[$rec->id] = $rec; |
|
| 27 | 5 | } else {
|
|
| 28 | 5 | $this->addTree($tree,$rec); |
|
| 29 | } |
||
| 30 | 5 | } |
|
| 31 | 5 | $this->tree = $tree; |
|
| 32 | 5 | } |
|
| 33 | 5 | protected function addTree(&$tree,$data) |
|
| 62 |