1 | <?php declare(strict_types = 1); |
||
16 | class RefResolver |
||
17 | { |
||
18 | /** |
||
19 | * @var object |
||
20 | */ |
||
21 | private $definition; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $uri; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $directory; |
||
32 | |||
33 | /** |
||
34 | * @var DefinitionLoader |
||
35 | */ |
||
36 | private $loader; |
||
37 | |||
38 | /** |
||
39 | * @param \stdClass $definition |
||
40 | * @param string $uri |
||
41 | * @param DefinitionLoader $loader |
||
42 | */ |
||
43 | public function __construct(\stdClass $definition, $uri, DefinitionLoader $loader = null) |
||
50 | |||
51 | /** |
||
52 | * @return \stdClass |
||
53 | */ |
||
54 | public function getDefinition(): \stdClass |
||
58 | |||
59 | /** |
||
60 | * Resolve all references |
||
61 | * |
||
62 | * @return mixed The whole definition can be a reference to a scalar value |
||
63 | */ |
||
64 | public function resolve() |
||
70 | |||
71 | /** |
||
72 | * Revert to original state |
||
73 | * |
||
74 | * @return \stdClass |
||
75 | */ |
||
76 | public function unresolve(): \stdClass |
||
82 | |||
83 | /** |
||
84 | * @param object|array $current |
||
85 | * @param \stdClass $document |
||
86 | * @param string $uri |
||
87 | */ |
||
88 | private function resolveRecursively(&$current, \stdClass $document = null, string $uri = null) |
||
121 | |||
122 | /** |
||
123 | * @param object|array $current |
||
124 | * @param object|array $parent |
||
125 | * |
||
126 | * @return void |
||
127 | */ |
||
128 | private function unresolveRecursively(&$current, &$parent = null) |
||
139 | |||
140 | /** |
||
141 | * @param string $path |
||
142 | * @param \stdClass $document |
||
143 | * @param string $uri |
||
144 | * |
||
145 | * @return mixed |
||
146 | * @throws InvalidReferenceException |
||
147 | */ |
||
148 | private function lookup($path, \stdClass $document, string $uri = null) |
||
160 | |||
161 | /** |
||
162 | * @param array $segments |
||
163 | * @param \stdClass $context |
||
164 | * |
||
165 | * @return mixed |
||
166 | */ |
||
167 | private function lookupRecursively(array $segments, \stdClass $context) |
||
180 | |||
181 | /** |
||
182 | * @param string $fileUrl |
||
183 | * |
||
184 | * @return \stdClass |
||
185 | */ |
||
186 | private function loadExternal(string $fileUrl): \stdClass |
||
190 | |||
191 | /** |
||
192 | * @param array $uriSegments |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | private function normalizeFileUri(array $uriSegments): string |
||
210 | |||
211 | /** |
||
212 | * @param string $uri |
||
213 | * |
||
214 | * @return array |
||
215 | */ |
||
216 | private function parseUri(string $uri): array |
||
238 | } |
||
239 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.