| Conditions | 7 |
| Paths | 5 |
| Total Lines | 17 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 7.0222 |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | 6 | public static function getByPath($subject, array $path, $notFoundIsError = true) |
|
| 26 | { |
||
| 27 | 6 | $ptr = & $subject; |
|
| 28 | 6 | foreach ($path as $key) { |
|
| 29 | 6 | if (is_object($ptr) && property_exists($ptr, $key)) { |
|
| 30 | $ptr = & $ptr->$key; |
||
| 31 | 6 | } elseif (is_array($ptr) && array_key_exists($key, $ptr)) { |
|
| 32 | 5 | $ptr = & $ptr[$key]; |
|
| 33 | 5 | } else { |
|
| 34 | 2 | if ($notFoundIsError === true) { |
|
| 35 | 1 | throw new \OutOfBoundsException("Path not found: " . implode('.', $path) . ", key {$key} did not resolve"); |
|
| 36 | } |
||
| 37 | 2 | return null; |
|
| 38 | } |
||
| 39 | 5 | } |
|
| 40 | 5 | return $ptr; |
|
| 41 | } |
||
| 42 | |||
| 71 | } |