1 | <?php |
||
46 | class Path |
||
47 | { |
||
48 | /** |
||
49 | * Xpath to element |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $xpath; |
||
53 | |||
54 | /** |
||
55 | * Default value |
||
56 | * @var mixed |
||
57 | */ |
||
58 | protected $default; |
||
59 | |||
60 | /** |
||
61 | * Filter function |
||
62 | * @var \Closure |
||
63 | */ |
||
64 | protected $filter; |
||
65 | |||
66 | /** |
||
67 | * Key name for this Path |
||
68 | * @var type |
||
69 | */ |
||
70 | protected $key; |
||
71 | |||
72 | /** |
||
73 | * Should we loop on this path ? |
||
74 | * @var type |
||
75 | */ |
||
76 | protected $loop = false; |
||
77 | |||
78 | /** |
||
79 | * Xpath to a value used as a key identifier when looping |
||
80 | * @var string |
||
81 | */ |
||
82 | protected $loopId; |
||
83 | |||
84 | /** |
||
85 | * List of sub-elements (Paths) |
||
86 | * @var array |
||
87 | */ |
||
88 | protected $childrens = array(); |
||
89 | |||
90 | /** |
||
91 | * List of attributes to fetch |
||
92 | * @var array |
||
93 | */ |
||
94 | protected $attributes = array(); |
||
95 | |||
96 | /** |
||
97 | * Key used for main element's value |
||
98 | * @var string |
||
99 | */ |
||
100 | protected $valueKey; |
||
101 | |||
102 | /** |
||
103 | * Constructor |
||
104 | * |
||
105 | * @param string $xpath XPath to element |
||
106 | * @param string $key Key name |
||
107 | * @param mixed $default Default value if element not defined |
||
108 | * @param callable $filter Filtering function |
||
|
|||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | 13 | public function __construct($xpath, $key, $default = null, |
|
120 | |||
121 | /** |
||
122 | * Defines looping on this path |
||
123 | * |
||
124 | * @param boolean $bool Should we loop on this element ? |
||
125 | * @param string $loopId Xpath to key identifier |
||
126 | * |
||
127 | * @return Path |
||
128 | */ |
||
129 | 8 | public function loop($bool, $loopId = null) |
|
136 | |||
137 | /** |
||
138 | * Defines a filtering function applied on the value |
||
139 | * |
||
140 | * @param \Closure $filter Value filtering function |
||
141 | * |
||
142 | * @return Path |
||
143 | */ |
||
144 | 1 | public function filter($filter) |
|
150 | |||
151 | /** |
||
152 | * Tells the Map to fetch the element's value, in $keyName |
||
153 | * |
||
154 | * @param string $keyName Key name where the value will be stored |
||
155 | * |
||
156 | * @return Path |
||
157 | */ |
||
158 | 4 | public function value($keyName) |
|
164 | |||
165 | /** |
||
166 | * Defines a default value in case element is empty |
||
167 | * |
||
168 | * @param mixed $default Default value |
||
169 | * |
||
170 | * @return Path |
||
171 | */ |
||
172 | 2 | public function setDefault($default) |
|
178 | |||
179 | /** |
||
180 | * Returns the Xpath to the element |
||
181 | * |
||
182 | * @return string |
||
183 | */ |
||
184 | 12 | public function getXpath() |
|
188 | |||
189 | /** |
||
190 | * Returns the defined default value (if any) |
||
191 | * |
||
192 | * @return mixed |
||
193 | */ |
||
194 | 12 | public function getDefault() |
|
198 | |||
199 | /** |
||
200 | * Returns the filter function (if any) |
||
201 | * |
||
202 | * @return \Closure |
||
203 | */ |
||
204 | 1 | public function getFilter() |
|
208 | |||
209 | /** |
||
210 | * Return the key of this Path |
||
211 | * |
||
212 | * @return string |
||
213 | */ |
||
214 | 12 | public function getKey() |
|
218 | |||
219 | /** |
||
220 | * Tells if we should loop on this xpath |
||
221 | * |
||
222 | * @return boolean |
||
223 | */ |
||
224 | 11 | public function isLoop() |
|
228 | |||
229 | /** |
||
230 | * Tells if we should store the element's main value |
||
231 | * |
||
232 | * @return boolean |
||
233 | */ |
||
234 | 5 | public function hasValueKey() |
|
238 | |||
239 | /** |
||
240 | * Tells if a filter function has been defined |
||
241 | * |
||
242 | * @return boolean |
||
243 | */ |
||
244 | 9 | public function hasFilter() |
|
248 | |||
249 | /** |
||
250 | * Factory method (helps chaining) |
||
251 | * |
||
252 | * @param string $xpath XPath to element |
||
253 | * @param string $key Key name |
||
254 | * @param mixed $default Default value if element not defined |
||
255 | * @param callable $filter Filtering function |
||
256 | * |
||
257 | * @return Path |
||
258 | */ |
||
259 | 13 | public static function factory($xpath, $key, $default = null, |
|
264 | |||
265 | /** |
||
266 | * Adds a child Path |
||
267 | * |
||
268 | * @param Path $path Child Path |
||
269 | * |
||
270 | * @return Path |
||
271 | */ |
||
272 | 5 | public function addChildren(Path $path) |
|
278 | |||
279 | /** |
||
280 | * Returns all child Paths |
||
281 | * |
||
282 | * @return array |
||
283 | */ |
||
284 | 11 | public function getChildrens() |
|
288 | |||
289 | /** |
||
290 | * Tells the Map to fetch an attribute of this path. |
||
291 | * If no $key is defined the $attrName is used. |
||
292 | * |
||
293 | * @param string $attrName Attribute name |
||
294 | * @param string $key Attribute key name |
||
295 | * |
||
296 | * @return Path |
||
297 | */ |
||
298 | 4 | public function attribute($attrName, $key = null) |
|
308 | |||
309 | /** |
||
310 | * Returns all attributes |
||
311 | * |
||
312 | * @return array |
||
313 | */ |
||
314 | 11 | public function getAttributes() |
|
318 | |||
319 | /** |
||
320 | * Returns the loop key identifiers |
||
321 | * |
||
322 | * @return string |
||
323 | */ |
||
324 | 7 | public function getLoopId() |
|
328 | |||
329 | /** |
||
330 | * Returns the key identifier where the root value is stored |
||
331 | * |
||
332 | * @return string |
||
333 | */ |
||
334 | 4 | public function getValueKey() |
|
338 | } |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type
array
and suggests a stricter type likearray<String>
.Most often this is a case of a parameter that can be null in addition to its declared types.