1 | <?php |
||
23 | final class SelfValueVisitor extends NodeVisitorAbstract |
||
24 | { |
||
25 | /** |
||
26 | * List of replaced nodes |
||
27 | * |
||
28 | * @var Node[] |
||
29 | */ |
||
30 | protected $replacedNodes = []; |
||
31 | |||
32 | /** |
||
33 | * Current namespace |
||
34 | * |
||
35 | * @var null|Name|string |
||
36 | */ |
||
37 | protected $namespace; |
||
38 | |||
39 | /** |
||
40 | * Current class name |
||
41 | * |
||
42 | * @var null|Name |
||
43 | */ |
||
44 | protected $className; |
||
45 | |||
46 | /** |
||
47 | * Returns list of changed `self` nodes |
||
48 | * |
||
49 | * @return Node[] |
||
50 | */ |
||
51 | 1 | public function getReplacedNodes() |
|
55 | |||
56 | /** |
||
57 | * @inheritDoc |
||
58 | */ |
||
59 | 1 | public function beforeTraverse(array $nodes) |
|
65 | |||
66 | /** |
||
67 | * @inheritDoc |
||
68 | */ |
||
69 | 1 | public function enterNode(Node $node) |
|
96 | |||
97 | /** |
||
98 | * Resolves `self` class name with value |
||
99 | * |
||
100 | * @param Name $name Instance of original node |
||
101 | * |
||
102 | * @return Name|FullyQualified |
||
103 | */ |
||
104 | 1 | protected function resolveClassName(Name $name) |
|
123 | |||
124 | /** |
||
125 | * Helper method for resolving type nodes |
||
126 | * |
||
127 | * @param Node|string|null $node Instance of node |
||
128 | * |
||
129 | * @return Node|Name|FullyQualified |
||
130 | */ |
||
131 | 1 | private function resolveType($node) |
|
143 | } |
||
144 |
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.