Issues (12)

examples/query.php (1 issue)

Labels
Severity
1
<?php
2
3
require_once __DIR__ . '/../vendor/autoload.php';
4
5
// Any PSR6 cache can be used.
6
$cache = new Stash\Pool( new \Stash\Driver\FileSystem() );
7
8
$sparql = 'SELECT ?item WHERE {
9
  ?item wdt:P31 wd:Q54050
10
} LIMIT 5';
11
$query = new \Samwilson\SimpleWikidata\Query( $sparql, 'en', $cache );
12
$hills = $query->getItems();
13
foreach ( $hills as $hill ) {
14
	$heights = $hill->getPropertyOfTypeQuantity( 'P2044' );
15
	if ( !$heights ) {
16
		echo "No heights found for " . $hill->getLabel() . "\n";
17
		continue;
18
	}
19
	$height = array_shift( $heights );
0 ignored issues
show
It seems like $heights can also be of type true; however, parameter $array of array_shift() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
	$height = array_shift( /** @scrutinizer ignore-type */ $heights );
Loading history...
20
	echo $hill->getLabel() . " is "
21
		. $height['amount'] . " " . $height['unit']->getLabel() . " high.\n";
22
}
23