Completed
Push — master ( 9dadc8...ff6b34 )
by Garrett
02:14
created

Json   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 7
c 4
b 0
f 0
lcom 0
cbo 1
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C load() 0 30 7
1
<?php
2
3
/* @description Dice - A minimal Dependency Injection Container for PHP
4
 * @author      Tom Butler [email protected]
5
 * @copyright   2012-2014 Tom Butler <[email protected]>
6
 * @link        http://r.je/dice.html
7
 * @license     http://www.opensource.org/licenses/bsd-license.php  BSD License
8
 * @version     2.0
9
 */
10
11
namespace Dice\Loader;
12
13
class Json
14
{
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
Documentation introduced by
$rule is of type null, but the function expects a array.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
        }
43
        return $dice;
44
    }
45
}
46