1 | <?php |
||
32 | class TypeParser |
||
33 | { |
||
34 | /** |
||
35 | * @var ReflectionComposite |
||
36 | */ |
||
37 | protected $context; |
||
38 | |||
39 | /** |
||
40 | * @var boolean |
||
41 | */ |
||
42 | protected $nullable; |
||
43 | |||
44 | /** |
||
45 | * @var boolean |
||
46 | */ |
||
47 | protected $collection; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $currentValue; |
||
53 | |||
54 | /** |
||
55 | * Constructs the TypeParser with an optional context for |
||
56 | * interpreting classnames |
||
57 | * |
||
58 | * @param ReflectionComposite $context |
||
59 | */ |
||
60 | 44 | public function __construct(ReflectionComposite $context = null) |
|
64 | |||
65 | /** |
||
66 | * Accepts any value and returns its type |
||
67 | * |
||
68 | * @param mixed $var |
||
69 | * @return AbstractType |
||
70 | */ |
||
71 | 17 | public function parseFromType($var) : AbstractType |
|
80 | |||
81 | /** |
||
82 | * Accepts an object and returns its type |
||
83 | * |
||
84 | * @param mixed $var |
||
85 | * @return ObjectType |
||
86 | */ |
||
87 | 6 | public function parseObjectName($var) : ObjectType |
|
91 | |||
92 | /** |
||
93 | * Sets the property's type by parsing the @type annotation |
||
94 | * |
||
95 | * @param string $value The value string to parse |
||
96 | * @return AbstractType The type of this item |
||
97 | */ |
||
98 | 37 | public function parse(string $value) : AbstractType |
|
127 | |||
128 | /** |
||
129 | * Checks that the given value at the given offset closes a |
||
130 | * collection block correctly |
||
131 | * |
||
132 | * @param string $value |
||
133 | * @param int $i |
||
134 | * @return void |
||
135 | */ |
||
136 | 13 | protected function checkCollectionClose(string $value, int $i) |
|
155 | |||
156 | /** |
||
157 | * Interprets the currentValue and converts it to an AbstractType |
||
158 | * |
||
159 | * @param AbstractType |
||
160 | */ |
||
161 | 34 | protected function currentValueToType() : AbstractType |
|
171 | |||
172 | 41 | public function scalarToType($var) : ?AbstractType |
|
196 | |||
197 | /** |
||
198 | * Resolves the currentValue to an AbstractType, setting it up as |
||
199 | * nullable or a collection as appropriate |
||
200 | * |
||
201 | * @return AbstractType |
||
202 | */ |
||
203 | 34 | protected function resolveName() : AbstractType |
|
224 | |||
225 | /** |
||
226 | * Checks if the currentValue means something in the TypeParser's |
||
227 | * context |
||
228 | * |
||
229 | * @return string The fully resolved classname |
||
230 | */ |
||
231 | 25 | protected function checkContext() |
|
250 | } |
||
251 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.