Total Complexity | 10 |
Total Lines | 76 |
Duplicated Lines | 0 % |
Coverage | 89.47% |
Changes | 0 |
1 | <?php |
||
10 | class CoreObject |
||
11 | { |
||
12 | /** @var mixed $object */ |
||
13 | protected $object; |
||
14 | |||
15 | /** @var callable|false */ |
||
16 | protected $retriever = false; |
||
17 | |||
18 | /** |
||
19 | * CoreObject constructor. |
||
20 | * |
||
21 | * @param mixed $object |
||
22 | */ |
||
23 | 13 | public function __construct($object) |
|
24 | { |
||
25 | 13 | $this->object = $object; |
|
26 | 13 | } |
|
27 | |||
28 | /** |
||
29 | * @param callable $retriever |
||
30 | * |
||
31 | * @return CoreObject |
||
32 | */ |
||
33 | 1 | public function setRetriever(callable $retriever) |
|
34 | { |
||
35 | 1 | $this->retriever = $retriever; |
|
36 | |||
37 | 1 | return $this; |
|
38 | } |
||
39 | |||
40 | public function hasRetriever() { |
||
41 | return (bool) $this->retriever; |
||
42 | } |
||
43 | /** |
||
44 | * @param bool $useRetriever |
||
45 | * |
||
46 | * @return mixed |
||
47 | */ |
||
48 | 8 | public function getObject($useRetriever = true) |
|
49 | { |
||
50 | 8 | $retriever = $this->retriever; |
|
|
|||
51 | |||
52 | 8 | return ($retriever && $useRetriever) ? $retriever($this->object) : $this->object; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return string |
||
57 | */ |
||
58 | 1 | public function getClass() |
|
59 | { |
||
60 | 1 | return get_class($this->object); |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param string $instance |
||
65 | * |
||
66 | * @return boolean |
||
67 | */ |
||
68 | 3 | public function isInstanceOf($instance) |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param string $method |
||
75 | * |
||
76 | * @return boolean |
||
77 | */ |
||
78 | 3 | public function hasMethod($method) |
|
79 | { |
||
80 | 3 | return method_exists($this->object, $method); |
|
81 | } |
||
82 | |||
83 | 1 | public function isArray() |
|
86 | } |
||
87 | } |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.