| Conditions | 7 |
| Paths | 20 |
| Total Lines | 30 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 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 (trim($json)[0] != '{') { |
||
| 22 | $path = dirname(realpath($json)); |
||
| 23 | $json = str_replace('__DIR__', $path, file_get_contents($json)); |
||
| 24 | } |
||
| 25 | |||
| 26 | $map = json_decode($json, true); |
||
| 27 | if (!is_array($map)) { |
||
| 28 | throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
||
| 29 | } |
||
| 30 | |||
| 31 | if (isset($map['rules'])) { |
||
| 32 | foreach ($map['rules'] as $rule) { |
||
| 33 | $name = $rule['name']; |
||
| 34 | unset($rule['name']); |
||
| 35 | $dice->addRule($name, $rule); |
||
| 36 | } |
||
| 37 | return $dice; |
||
| 38 | } |
||
| 39 | |||
| 40 | foreach ($map as $name => $rule) { |
||
| 41 | $dice->addRule($name, $rule); |
||
|
1 ignored issue
–
show
|
|||
| 42 | } |
||
| 43 | return $dice; |
||
| 44 | } |
||
| 45 | } |
||
| 46 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: