| Conditions | 9 |
| Paths | 24 |
| Total Lines | 37 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 15 | public function load($json, \Dice\Dice $dice = null) |
||
|
|
|||
| 16 | { |
||
| 17 | if ($dice === null) { |
||
| 18 | $dice = new \Dice\Dice(); |
||
| 19 | } |
||
| 20 | |||
| 21 | if (is_array($json)) { |
||
| 22 | foreach ($json as $file) { |
||
| 23 | $dice = $this->load($file, $dice); |
||
| 24 | } |
||
| 25 | return $dice; |
||
| 26 | } |
||
| 27 | |||
| 28 | if (trim($json)[0] != '{') { |
||
| 29 | $path = dirname(realpath($json)); |
||
| 30 | $json = str_replace('__DIR__', $path, file_get_contents($json)); |
||
| 31 | } |
||
| 32 | |||
| 33 | $map = json_decode($json, true); |
||
| 34 | if (!is_array($map)) { |
||
| 35 | throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
||
| 36 | } |
||
| 37 | |||
| 38 | if (isset($map['rules'])) { |
||
| 39 | foreach ($map['rules'] as $rule) { |
||
| 40 | $name = $rule['name']; |
||
| 41 | unset($rule['name']); |
||
| 42 | $dice->addRule($name, $rule); |
||
| 43 | } |
||
| 44 | return $dice; |
||
| 45 | } |
||
| 46 | |||
| 47 | foreach ($map as $name => $rule) { |
||
| 48 | $dice->addRule($name, $rule); |
||
| 49 | } |
||
| 50 | return $dice; |
||
| 51 | } |
||
| 52 | } |
||
| 53 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.