These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * |
||
4 | */ |
||
5 | |||
6 | namespace Mvc5\Config; |
||
7 | |||
8 | trait Config |
||
9 | { |
||
10 | /** |
||
11 | * |
||
12 | */ |
||
13 | use ArrayAccess; |
||
14 | use Iterator; |
||
15 | use PropertyAccess; |
||
16 | |||
17 | /** |
||
18 | * @var array|Configuration |
||
19 | */ |
||
20 | protected $config = []; |
||
21 | |||
22 | /** |
||
23 | * @param array $config |
||
24 | */ |
||
25 | 444 | function __construct($config = []) |
|
0 ignored issues
–
show
|
|||
26 | { |
||
27 | 444 | $this->config = $config; |
|
28 | 444 | } |
|
29 | |||
30 | /** |
||
31 | * @param string $name |
||
32 | * @return mixed |
||
33 | */ |
||
34 | 322 | function get($name) |
|
0 ignored issues
–
show
|
|||
35 | { |
||
36 | 322 | return is_array($this->config) ? |
|
37 | 322 | (isset($this->config[$name]) ? $this->config[$name] : null) : $this->config[$name]; |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param string $name |
||
42 | * @return bool |
||
43 | */ |
||
44 | 39 | function has($name) |
|
0 ignored issues
–
show
|
|||
45 | { |
||
46 | 39 | return isset($this->config[$name]); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $name |
||
51 | * @return void |
||
52 | */ |
||
53 | 7 | function remove($name) |
|
0 ignored issues
–
show
|
|||
54 | { |
||
55 | 7 | unset($this->config[$name]); |
|
56 | 7 | } |
|
57 | |||
58 | /** |
||
59 | * @param string $name |
||
60 | * @param mixed $value |
||
61 | * @return mixed |
||
62 | */ |
||
63 | 117 | function set($name, $value) |
|
0 ignored issues
–
show
|
|||
64 | { |
||
65 | 117 | return $this->config[$name] = $value; |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * @param string $name |
||
70 | * @param mixed $value |
||
71 | * @return self|mixed |
||
72 | */ |
||
73 | 24 | function with($name, $value) |
|
0 ignored issues
–
show
|
|||
74 | { |
||
75 | 24 | $new = clone $this; |
|
76 | |||
77 | 24 | $new->config instanceof Immutable |
|
78 | 1 | ? $new->config = $new->config->with($name, $value) |
|
79 | 24 | : $new->set($name, $value); |
|
80 | |||
81 | 24 | return $new; |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param string $name |
||
86 | * @return self|mixed |
||
87 | */ |
||
88 | 3 | function without($name) |
|
0 ignored issues
–
show
|
|||
89 | { |
||
90 | 3 | $new = clone $this; |
|
91 | |||
92 | 3 | $new->config instanceof Immutable |
|
93 | 1 | ? $new->config = $new->config->without($name) |
|
94 | 3 | : $new->remove($name); |
|
95 | |||
96 | 3 | return $new; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * |
||
101 | */ |
||
102 | 48 | function __clone() |
|
0 ignored issues
–
show
|
|||
103 | { |
||
104 | 48 | if (!is_object($this->config)) { |
|
105 | 45 | return null; |
|
106 | } |
||
107 | |||
108 | 21 | if (!$this->config instanceof Scope) { |
|
109 | 18 | return $this->config = clone $this->config; |
|
110 | } |
||
111 | |||
112 | 3 | $scope = $this->config->scope(); |
|
113 | |||
114 | 3 | if (!$scope instanceof self) { |
|
115 | 2 | return $this->config = clone $this->config; |
|
0 ignored issues
–
show
It seems like
clone $this->config of type object<Mvc5\Config\Scope> is incompatible with the declared type array|object<Mvc5\Config\Configuration> of property $config .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..
Loading history...
|
|||
116 | } |
||
117 | |||
118 | 1 | $this->config->scope(false); |
|
0 ignored issues
–
show
false is of type boolean , but the function expects a null|object .
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...
|
|||
119 | |||
120 | 1 | $clone = clone $this->config; |
|
121 | 1 | $clone->scope($this); |
|
122 | |||
123 | 1 | $this->config->scope($scope); |
|
124 | |||
125 | 1 | return $this->config = $clone; |
|
0 ignored issues
–
show
It seems like
$clone of type object<Mvc5\Config\Scope> is incompatible with the declared type array|object<Mvc5\Config\Configuration> of property $config .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..
Loading history...
|
|||
126 | } |
||
127 | } |
||
128 |
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.