| Conditions | 7 |
| Paths | 8 |
| Total Lines | 21 |
| Code Lines | 11 |
| Lines | 5 |
| Ratio | 23.81 % |
| Tests | 11 |
| CRAP Score | 7 |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 7 | 8 | function toObject($data) |
|
|
|
|||
| 8 | {
|
||
| 9 | 8 | if(is_array($data)) {
|
|
| 10 | 8 | if(array_keys($data) === range(0, count($data) -1)) {
|
|
| 11 | 1 | foreach($data as $k => $v) {
|
|
| 12 | 1 | $data[$k] = $this->toObject($v); |
|
| 13 | } |
||
| 14 | 1 | return $data; |
|
| 15 | } |
||
| 16 | } |
||
| 17 | |||
| 18 | 8 | $data = (object) $data; |
|
| 19 | |||
| 20 | 8 | View Code Duplication | foreach ($data as $k => $v) {
|
| 21 | 8 | if (is_array($v) || is_object($v)) {
|
|
| 22 | 8 | $data->$k = $this->toObject($v); |
|
| 23 | } |
||
| 24 | } |
||
| 25 | |||
| 26 | 8 | return $data; |
|
| 27 | } |
||
| 28 | |||
| 47 | } |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.