These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use Maps\Elements\Location; |
||
4 | |||
5 | /** |
||
6 | * Class for handling geographical SMW queries. |
||
7 | * |
||
8 | * @since 0.7.3 |
||
9 | * |
||
10 | * @licence GNU GPL v2+ |
||
11 | * @author Jeroen De Dauw < [email protected] > |
||
12 | */ |
||
13 | class SMQueryHandler { |
||
14 | |||
15 | protected $queryResult; |
||
16 | protected $outputmode; |
||
17 | |||
18 | /** |
||
19 | * @since 2.0 |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $geoShapes = [ |
||
24 | 'lines' => [], |
||
25 | 'locations' => [], |
||
26 | 'polygons' => [] |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * The template to use for the text, or false if there is none. |
||
31 | * |
||
32 | * @since 0.7.3 |
||
33 | * |
||
34 | * @var string|boolean false |
||
35 | */ |
||
36 | protected $template = false; |
||
37 | |||
38 | /** |
||
39 | * The global icon. |
||
40 | * |
||
41 | * @since 0.7.3 |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | public $icon = ''; |
||
46 | |||
47 | /** |
||
48 | * The global text. |
||
49 | * |
||
50 | * @since 1.0 |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | public $text = ''; |
||
55 | |||
56 | /** |
||
57 | * The global title. |
||
58 | * |
||
59 | * @since 1.0 |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | public $title = ''; |
||
64 | |||
65 | /** |
||
66 | * Make a separate link to the title or not? |
||
67 | * |
||
68 | * @since 0.7.3 |
||
69 | * |
||
70 | * @var boolean |
||
71 | */ |
||
72 | public $titleLinkSeparate; |
||
73 | |||
74 | /** |
||
75 | * Should link targets be made absolute (instead of relative)? |
||
76 | * |
||
77 | * @since 1.0 |
||
78 | * |
||
79 | * @var boolean |
||
80 | */ |
||
81 | protected $linkAbsolute; |
||
82 | |||
83 | /** |
||
84 | * The text used for the link to the page (if it's created). $1 will be replaced by the page name. |
||
85 | * |
||
86 | * @since 1.0 |
||
87 | * |
||
88 | * @var string |
||
89 | */ |
||
90 | protected $pageLinkText; |
||
91 | |||
92 | /** |
||
93 | * A separator to use between the subject and properties in the text field. |
||
94 | * |
||
95 | * @since 1.0 |
||
96 | * |
||
97 | * @var string |
||
98 | */ |
||
99 | protected $subjectSeparator = '<hr />'; |
||
100 | |||
101 | /** |
||
102 | * Make the subject in the text bold or not? |
||
103 | * |
||
104 | * @since 1.0 |
||
105 | * |
||
106 | * @var boolean |
||
107 | */ |
||
108 | protected $boldSubject = true; |
||
109 | |||
110 | /** |
||
111 | * Show the subject in the text or not? |
||
112 | * |
||
113 | * @since 1.0 |
||
114 | * |
||
115 | * @var boolean |
||
116 | */ |
||
117 | protected $showSubject = true; |
||
118 | |||
119 | /** |
||
120 | * Hide the namespace or not. |
||
121 | * |
||
122 | * @var boolean |
||
123 | */ |
||
124 | protected $hideNamespace = false; |
||
125 | |||
126 | |||
127 | /** |
||
128 | * Defines which article names in the result are hyperlinked, all normally is the default |
||
129 | * none, subject, all |
||
130 | */ |
||
131 | protected $linkStyle = 'all'; |
||
132 | |||
133 | /* |
||
134 | * Show headers (with links), show headers (just text) or hide them. show is default |
||
135 | * show, plain, hide |
||
136 | */ |
||
137 | protected $headerStyle = 'show'; |
||
138 | |||
139 | /** |
||
140 | * Marker icon to show when marker equals active page |
||
141 | * |
||
142 | * @var string |
||
143 | */ |
||
144 | protected $activeIcon; |
||
145 | |||
146 | /** |
||
147 | * @var string |
||
148 | */ |
||
149 | protected $userParam = ''; |
||
150 | |||
151 | /** |
||
152 | * Constructor. |
||
153 | * |
||
154 | * @since 0.7.3 |
||
155 | * |
||
156 | * @param SMWQueryResult $queryResult |
||
157 | * @param integer $outputmode |
||
158 | * @param boolean $linkAbsolute |
||
159 | * @param string $pageLinkText |
||
160 | * @param boolean $titleLinkSeparate |
||
161 | * @param string $activeIcon |
||
162 | */ |
||
163 | public function __construct( SMWQueryResult $queryResult, $outputmode, $linkAbsolute = false, $pageLinkText = '$1', $titleLinkSeparate = false, $hideNamespace = false, $activeIcon = null ) { |
||
164 | $this->queryResult = $queryResult; |
||
165 | $this->outputmode = $outputmode; |
||
166 | |||
167 | $this->linkAbsolute = $linkAbsolute; |
||
168 | $this->pageLinkText = $pageLinkText; |
||
169 | $this->titleLinkSeparate = $titleLinkSeparate; |
||
170 | $this->hideNamespace = $hideNamespace; |
||
171 | $this->activeIcon = $activeIcon; |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * Sets the template. |
||
176 | * |
||
177 | * @since 1.0 |
||
178 | * |
||
179 | * @param string $template |
||
180 | */ |
||
181 | public function setTemplate( $template ) { |
||
182 | $this->template = $template === '' ? false : $template; |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * @since 3.2 |
||
187 | * |
||
188 | * @param string $userParam |
||
189 | */ |
||
190 | public function setUserParam( $userParam ) { |
||
191 | $this->userParam = $userParam; |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Sets the global icon. |
||
196 | * |
||
197 | * @since 1.0 |
||
198 | * |
||
199 | * @param string $icon |
||
200 | */ |
||
201 | public function setIcon( $icon ) { |
||
202 | $this->icon = $icon; |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * Sets the global title. |
||
207 | * |
||
208 | * @since 1.0 |
||
209 | * |
||
210 | * @param string $title |
||
211 | */ |
||
212 | public function setTitle( $title ) { |
||
213 | $this->title = $title; |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * Sets the global text. |
||
218 | * |
||
219 | * @since 1.0 |
||
220 | * |
||
221 | * @param string $text |
||
222 | */ |
||
223 | public function setText( $text ) { |
||
224 | $this->text = $text; |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * Sets the subject separator. |
||
229 | * |
||
230 | * @since 1.0 |
||
231 | * |
||
232 | * @param string $subjectSeparator |
||
233 | */ |
||
234 | public function setSubjectSeparator( $subjectSeparator ) { |
||
235 | $this->subjectSeparator = $subjectSeparator; |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * Sets if the subject should be made bold in the text. |
||
240 | * |
||
241 | * @since 1.0 |
||
242 | * |
||
243 | * @param string $boldSubject |
||
244 | */ |
||
245 | public function setBoldSubject( $boldSubject ) { |
||
246 | $this->boldSubject = $boldSubject; |
||
0 ignored issues
–
show
|
|||
247 | } |
||
248 | |||
249 | /** |
||
250 | * Sets if the subject should shown in the text. |
||
251 | * |
||
252 | * @since 1.0 |
||
253 | * |
||
254 | * @param string $showSubject |
||
255 | */ |
||
256 | public function setShowSubject( $showSubject ) { |
||
257 | $this->showSubject = $showSubject; |
||
0 ignored issues
–
show
The property
$showSubject was declared of type boolean , but $showSubject is of type string . Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
258 | } |
||
259 | |||
260 | /** |
||
261 | * Sets the text for the link to the page when separate from the title. |
||
262 | * |
||
263 | * @since 1.0 |
||
264 | * |
||
265 | * @param string $text |
||
266 | */ |
||
267 | public function setPageLinkText( $text ) { |
||
268 | $this->pageLinkText = $text; |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * |
||
273 | * @since 2.0.1 |
||
274 | * |
||
275 | * @param boolean $link |
||
276 | */ |
||
277 | public function setLinkStyle ( $link ) { |
||
278 | $this->linkStyle = $link; |
||
0 ignored issues
–
show
The property
$linkStyle was declared of type string , but $link is of type boolean . Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
279 | } |
||
280 | |||
281 | /** |
||
282 | * |
||
283 | * @since 2.0.1 |
||
284 | * |
||
285 | * @param boolean $headers |
||
286 | */ |
||
287 | public function setHeaderStyle ( $headers ) { |
||
288 | $this->headerStyle = $headers; |
||
0 ignored issues
–
show
The property
$headerStyle was declared of type string , but $headers is of type boolean . Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
289 | } |
||
290 | |||
291 | /** |
||
292 | * @since 2.0 |
||
293 | * |
||
294 | * @return array |
||
295 | */ |
||
296 | public function getShapes() { |
||
297 | $this->findShapes(); |
||
298 | return $this->geoShapes; |
||
299 | } |
||
300 | |||
301 | /** |
||
302 | * @since 2.0 |
||
303 | */ |
||
304 | protected function findShapes() { |
||
305 | while ( ( $row = $this->queryResult->getNext() ) !== false ) { |
||
306 | $this->handleResultRow( $row ); |
||
307 | } |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * Returns the locations found in the provided result row. |
||
312 | * |
||
313 | * @since 0.7.3 |
||
314 | * |
||
315 | * @param SMWResultArray[] $row |
||
316 | */ |
||
317 | protected function handleResultRow( array $row ) { |
||
318 | $locations = []; |
||
319 | $properties = []; |
||
320 | |||
321 | $title = ''; |
||
322 | $text = ''; |
||
323 | |||
324 | // Loop through all fields of the record. |
||
325 | foreach ( $row as $i => $resultArray ) { |
||
326 | /* SMWPrintRequest */ $printRequest = $resultArray->getPrintRequest(); |
||
327 | |||
328 | // Loop through all the parts of the field value. |
||
329 | while ( ( /* SMWDataValue */ $dataValue = $resultArray->getNextDataValue() ) !== false ) { |
||
330 | if ( $dataValue->getTypeID() == '_wpg' && $i == 0 ) { |
||
331 | list( $title, $text ) = $this->handleResultSubject( $dataValue ); |
||
332 | } |
||
333 | else if ( $dataValue->getTypeID() == '_str' && $i == 0 ) { |
||
334 | $title = $dataValue->getLongText( $this->outputmode, null ); |
||
335 | $text = $dataValue->getLongText( $this->outputmode, smwfGetLinker() ); |
||
336 | } |
||
337 | else if ( $dataValue->getTypeID() == '_gpo' ) { |
||
338 | $dataItem = $dataValue->getDataItem(); |
||
339 | $polyHandler = new PolygonHandler ( $dataItem->getString() ); |
||
340 | $this->geoShapes[ $polyHandler->getGeoType() ][] = $polyHandler->shapeFromText(); |
||
341 | } else if ( strpos( $dataValue->getTypeID(), '_rec' ) !== false ) { |
||
342 | foreach ( $dataValue->getDataItems() as $dataItem ) { |
||
343 | if ( $dataItem instanceof \SMWDIGeoCoord ) { |
||
0 ignored issues
–
show
The class
SMWDIGeoCoord does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed.
Loading history...
|
|||
344 | $location = Location::newFromLatLon( $dataItem->getLatitude(), $dataItem->getLongitude() ); |
||
345 | $locations[] = $location; |
||
346 | } |
||
347 | } |
||
348 | } |
||
349 | else if ( $dataValue->getTypeID() != '_geo' && $i != 0 && !$this->isHeadersHide()) { |
||
350 | $properties[] = $this->handleResultProperty( $dataValue, $printRequest ); |
||
351 | } |
||
352 | else if ( $printRequest->getMode() == SMWPrintRequest::PRINT_PROP && $printRequest->getTypeID() == '_geo' || $dataValue->getTypeID() == '_geo' ) { |
||
353 | $dataItem = $dataValue->getDataItem(); |
||
354 | |||
355 | $location = Location::newFromLatLon( $dataItem->getLatitude(), $dataItem->getLongitude() ); |
||
356 | |||
357 | $locations[] = $location; |
||
358 | } |
||
359 | } |
||
360 | } |
||
361 | |||
362 | if ( count( $properties ) > 0 && $text !== '' ) { |
||
363 | $text .= $this->subjectSeparator; |
||
364 | } |
||
365 | |||
366 | $icon = $this->getLocationIcon( $row ); |
||
367 | |||
368 | $this->geoShapes['locations'] = array_merge( |
||
369 | $this->geoShapes['locations'], |
||
370 | $this->buildLocationsList( |
||
371 | $locations, |
||
372 | $text, |
||
373 | $icon, |
||
374 | $properties, |
||
375 | Title::newFromText( $title ) |
||
376 | ) |
||
377 | ); |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * Handles a SMWWikiPageValue subject value. |
||
382 | * Gets the plain text title and creates the HTML text with headers and the like. |
||
383 | * |
||
384 | * @since 1.0 |
||
385 | * |
||
386 | * @param SMWWikiPageValue $object |
||
387 | * |
||
388 | * @return array with title and text |
||
389 | */ |
||
390 | protected function handleResultSubject( SMWWikiPageValue $object ) { |
||
391 | $title = $object->getLongText( $this->outputmode, null ); |
||
392 | $text = ''; |
||
393 | |||
394 | if ( $this->showSubject ) { |
||
395 | if( !$this->showArticleLink()){ |
||
396 | $text = $this->hideNamespace ? $object->getText() : $object->getTitle()->getFullText(); |
||
397 | }else if ( !$this->titleLinkSeparate && $this->linkAbsolute ) { |
||
398 | $text = Html::element( |
||
399 | 'a', |
||
400 | [ 'href' => $object->getTitle()->getFullUrl() ], |
||
401 | $this->hideNamespace ? $object->getText() : $object->getTitle()->getFullText() |
||
402 | ); |
||
403 | } |
||
404 | else { |
||
405 | if($this->hideNamespace){ |
||
406 | $text = $object->getShortHTMLText(smwfGetLinker()); |
||
407 | }else{ |
||
408 | $text = $object->getLongHTMLText( smwfGetLinker() ); |
||
409 | } |
||
410 | } |
||
411 | |||
412 | if ( $this->boldSubject ) { |
||
413 | $text = '<b>' . $text . '</b>'; |
||
414 | } |
||
415 | |||
416 | if ( $this->titleLinkSeparate ) { |
||
417 | $txt = $object->getTitle()->getText(); |
||
418 | |||
419 | if ( $this->pageLinkText !== '' ) { |
||
420 | $txt = str_replace( '$1', $txt, $this->pageLinkText ); |
||
421 | } |
||
422 | $text .= Html::element( |
||
423 | 'a', |
||
424 | [ 'href' => $object->getTitle()->getFullUrl() ], |
||
425 | $txt |
||
426 | ); |
||
427 | } |
||
428 | } |
||
429 | |||
430 | return [ $title, $text ]; |
||
431 | } |
||
432 | |||
433 | protected function showArticleLink(){ |
||
434 | return $this->linkStyle !== 'none'; |
||
435 | } |
||
436 | |||
437 | /** |
||
438 | * Handles a single property (SMWPrintRequest) to be displayed for a record (SMWDataValue). |
||
439 | * |
||
440 | * @since 1.0 |
||
441 | * |
||
442 | * @param SMWDataValue $object |
||
443 | * @param SMWPrintRequest $printRequest |
||
444 | * |
||
445 | * @return string |
||
446 | */ |
||
447 | protected function handleResultProperty( SMWDataValue $object, SMWPrintRequest $printRequest ) { |
||
448 | if($this->isHeadersHide()){ |
||
449 | return ''; |
||
450 | } |
||
451 | |||
452 | if ( $this->template ) { |
||
453 | if ( $object instanceof SMWWikiPageValue ) { |
||
0 ignored issues
–
show
The class
SMWWikiPageValue does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed.
Loading history...
|
|||
454 | return $object->getTitle()->getPrefixedText(); |
||
455 | } else { |
||
456 | return $object->getLongText( SMW_OUTPUT_WIKI, null ); |
||
457 | } |
||
458 | } |
||
459 | |||
460 | if ( $this->linkAbsolute ) { |
||
461 | $titleText = $printRequest->getText( null ); |
||
462 | $t = Title::newFromText($titleText , SMW_NS_PROPERTY ); |
||
463 | |||
464 | if ($this->isHeadersShow() && $t instanceof Title && $t->exists() ) { |
||
0 ignored issues
–
show
The class
Title does not exist. Did you forget a USE statement, or did you not list all dependencies?
This error could be the result of: 1. Missing dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed.
Loading history...
|
|||
465 | $propertyName = $propertyName = Html::element( |
||
466 | 'a', |
||
467 | [ 'href' => $t->getFullUrl() ], |
||
468 | $printRequest->getHTMLText( null ) |
||
469 | ); |
||
470 | } |
||
471 | else { |
||
472 | $propertyName = $titleText; |
||
473 | } |
||
474 | } |
||
475 | else { |
||
476 | if($this->isHeadersShow()){ |
||
477 | $propertyName = $printRequest->getHTMLText( smwfGetLinker() ); |
||
478 | }else if($this->isHeadersPlain()){ |
||
479 | $propertyName = $printRequest->getText(null); |
||
480 | } |
||
481 | } |
||
482 | |||
483 | if ( $this->linkAbsolute ) { |
||
484 | $hasPage = $object->getTypeID() == '_wpg'; |
||
485 | |||
486 | if ( $hasPage ) { |
||
487 | $t = Title::newFromText( $object->getLongText( $this->outputmode, null ), NS_MAIN ); |
||
488 | $hasPage = $t !== null && $t->exists(); |
||
489 | } |
||
490 | |||
491 | if ( $hasPage ) { |
||
492 | $propertyValue = Html::element( |
||
493 | 'a', |
||
494 | [ 'href' => $t->getFullUrl() ], |
||
0 ignored issues
–
show
The variable
$t does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
495 | $object->getLongText( $this->outputmode, null ) |
||
496 | ); |
||
497 | } |
||
498 | else { |
||
499 | $propertyValue = $object->getLongText( $this->outputmode, null ); |
||
500 | } |
||
501 | } |
||
502 | else { |
||
503 | $propertyValue = $object->getLongText( $this->outputmode, smwfGetLinker() ); |
||
504 | } |
||
505 | |||
506 | return $propertyName . ( $propertyName === '' ? '' : ': ' ) . $propertyValue; |
||
0 ignored issues
–
show
The variable
$propertyName does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
507 | } |
||
508 | |||
509 | |||
510 | protected function isHeadersShow(){ |
||
511 | return $this->headerStyle === 'show'; |
||
512 | } |
||
513 | |||
514 | protected function isHeadersHide(){ |
||
515 | return $this->headerStyle === 'hide'; |
||
516 | } |
||
517 | |||
518 | protected function isHeadersPlain(){ |
||
519 | return $this->headerStyle === 'plain'; |
||
520 | } |
||
521 | |||
522 | /** |
||
523 | * Builds a set of locations with the provided title, text and icon. |
||
524 | * |
||
525 | * @since 1.0 |
||
526 | * |
||
527 | * @param Location[] $locations |
||
528 | * @param string $text |
||
529 | * @param string $icon |
||
530 | * @param array $properties |
||
531 | * @param Title|null $title |
||
532 | * |
||
533 | * @return Location[] |
||
534 | */ |
||
535 | protected function buildLocationsList( array $locations, $text, $icon, array $properties, Title $title = null ) { |
||
536 | if ( $this->template ) { |
||
537 | global $wgParser; |
||
538 | $parser = clone $wgParser; |
||
539 | } |
||
540 | else { |
||
541 | $text .= implode( '<br />', $properties ); |
||
542 | } |
||
543 | |||
544 | if ( $title === null ) { |
||
545 | $titleOutput = ''; |
||
546 | } |
||
547 | else { |
||
548 | $titleOutput = $this->hideNamespace ? $title->getText() : $title->getFullText(); |
||
549 | } |
||
550 | |||
551 | foreach ( $locations as &$location ) { |
||
552 | if ( $this->template ) { |
||
553 | $segments = array_merge( |
||
554 | [ |
||
555 | $this->template, |
||
556 | 'title=' . $titleOutput, |
||
557 | 'latitude=' . $location->getCoordinates()->getLatitude(), |
||
558 | 'longitude=' . $location->getCoordinates()->getLongitude(), |
||
559 | 'userparam=' . $this->userParam |
||
560 | ], |
||
561 | $properties |
||
562 | ); |
||
563 | |||
564 | $text .= $parser->parse( '{{' . implode( '|', $segments ) . '}}', $parser->getTitle(), new ParserOptions() )->getText(); |
||
0 ignored issues
–
show
The variable
$parser does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
565 | } |
||
566 | |||
567 | $location->setTitle( $titleOutput ); |
||
568 | $location->setText( $text ); |
||
569 | $location->setIcon( $icon ); |
||
570 | } |
||
571 | |||
572 | return $locations; |
||
573 | } |
||
574 | |||
575 | /** |
||
576 | * Get the icon for a row. |
||
577 | * |
||
578 | * @since 0.7.3 |
||
579 | * |
||
580 | * @param array $row |
||
581 | * |
||
582 | * @return string |
||
583 | */ |
||
584 | protected function getLocationIcon( array $row ) { |
||
585 | $icon = ''; |
||
586 | $legend_labels = []; |
||
587 | |||
588 | //Check for activeicon parameter |
||
589 | |||
590 | if ( $this->shouldGetActiveIconUrlFor( $row[0]->getResultSubject()->getTitle() ) ){ |
||
591 | $icon = MapsMapper::getFileUrl( $this->activeIcon ); |
||
0 ignored issues
–
show
|
|||
592 | } |
||
593 | |||
594 | // Look for display_options field, which can be set by Semantic Compound Queries |
||
595 | // the location of this field changed in SMW 1.5 |
||
596 | $display_location = method_exists( $row[0], 'getResultSubject' ) ? $row[0]->getResultSubject() : $row[0]; |
||
597 | |||
598 | if ( property_exists( $display_location, 'display_options' ) && is_array( $display_location->display_options ) ) { |
||
599 | $display_options = $display_location->display_options; |
||
600 | if ( array_key_exists( 'icon', $display_options ) ) { |
||
601 | $icon = $display_options['icon']; |
||
602 | |||
603 | // This is somewhat of a hack - if a legend label has been set, we're getting it for every point, instead of just once per icon |
||
604 | if ( array_key_exists( 'legend label', $display_options ) ) { |
||
605 | |||
606 | $legend_label = $display_options['legend label']; |
||
607 | |||
608 | if ( ! array_key_exists( $icon, $legend_labels ) ) { |
||
609 | $legend_labels[$icon] = $legend_label; |
||
610 | } |
||
611 | } |
||
612 | } |
||
613 | } // Icon can be set even for regular, non-compound queries If it is, though, we have to translate the name into a URL here |
||
614 | elseif ( $this->icon !== '' ) { |
||
615 | $icon = MapsMapper::getFileUrl( $this->icon ); |
||
0 ignored issues
–
show
|
|||
616 | } |
||
617 | |||
618 | return $icon; |
||
619 | } |
||
620 | |||
621 | private function shouldGetActiveIconUrlFor( Title $title ) { |
||
622 | global $wgTitle; |
||
623 | |||
624 | return isset( $this->activeIcon ) && is_object( $wgTitle ) |
||
625 | && $wgTitle->equals( $title ); |
||
626 | } |
||
627 | |||
628 | /** |
||
629 | * @param boolean $hideNamespace |
||
630 | */ |
||
631 | public function setHideNamespace( $hideNamespace ) { |
||
632 | $this->hideNamespace = $hideNamespace; |
||
633 | } |
||
634 | |||
635 | /** |
||
636 | * @return boolean |
||
637 | */ |
||
638 | public function getHideNamespace() { |
||
639 | return $this->hideNamespace; |
||
640 | } |
||
641 | |||
642 | /** |
||
643 | * @param string $activeIcon |
||
644 | */ |
||
645 | public function setActiveIcon( $activeIcon ){ |
||
646 | $this->activeIcon = $activeIcon; |
||
647 | } |
||
648 | |||
649 | /** |
||
650 | * @return string |
||
651 | */ |
||
652 | public function getActiveIcon( ){ |
||
653 | return $this->activeIcon; |
||
654 | } |
||
655 | |||
656 | } |
||
657 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.