Passed
Push — master ( 1aaa34...34a985 )
by Sam
02:42 queued 32s
created
examples/query.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@
 block discarded – undo
11 11
 $query = new \Samwilson\SimpleWikidata\Query( $sparql, 'en', $cache );
12 12
 $hills = $query->getItems();
13 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 );
20
-	echo $hill->getLabel() . " is "
21
-		. $height['amount'] . " " . $height['unit']->getLabel() . " high.\n";
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 );
20
+    echo $hill->getLabel() . " is "
21
+        . $height['amount'] . " " . $height['unit']->getLabel() . " high.\n";
22 22
 }
Please login to merge, or discard this patch.
examples/search.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,9 +9,9 @@
 block discarded – undo
9 9
 $search = new \Samwilson\SimpleWikidata\Search( 'pride and prejudice', 'en', $cache );
10 10
 $items = $search->getItems( 3 );
11 11
 foreach ( $items as $item ) {
12
-	$instanceOf = $item->getPropertyOfTypeItem(
13
-		\Samwilson\SimpleWikidata\Item::PROP_INSTANCE_OF
14
-	);
15
-	$instanceOfLabel = isset( $instanceOf[0] ) ? $instanceOf[0]->getItem()->getLabel() : 'UNKNOWN';
16
-	echo $item->getLabel() . ' (' . $instanceOfLabel . ')' . "\n";
12
+    $instanceOf = $item->getPropertyOfTypeItem(
13
+        \Samwilson\SimpleWikidata\Item::PROP_INSTANCE_OF
14
+    );
15
+    $instanceOfLabel = isset( $instanceOf[0] ) ? $instanceOf[0]->getItem()->getLabel() : 'UNKNOWN';
16
+    echo $item->getLabel() . ' (' . $instanceOfLabel . ')' . "\n";
17 17
 }
Please login to merge, or discard this patch.
examples/humans.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 $datesOfBirth = $princeCharles->getDatesOfBirth();
18 18
 echo "  Date of birth: " . $datesOfBirth[0]->getDateTime()->format( 'j F, Y' ) . " ";
19 19
 foreach ( $datesOfBirth[0]->getReferences() as $ref ) {
20
-	if ( $ref->statedIn() ) {
21
-		echo "[$refNum]";
22
-		$references[$refNum] = $ref;
23
-	}
20
+    if ( $ref->statedIn() ) {
21
+        echo "[$refNum]";
22
+        $references[$refNum] = $ref;
23
+    }
24 24
 }
25 25
 echo "\n";
26 26
 
@@ -28,13 +28,13 @@  discard block
 block discarded – undo
28 28
 $fathers = $princeCharles->fathers();
29 29
 echo "  Father: " . $fathers[0]->getItem()->getLabel() . " ";
30 30
 foreach ( $fathers[0]->getReferences() as $ref ) {
31
-	if ( $ref->statedIn() ) {
32
-		echo "[$refNum]";
33
-		$references[$refNum] = $ref;
34
-	}
31
+    if ( $ref->statedIn() ) {
32
+        echo "[$refNum]";
33
+        $references[$refNum] = $ref;
34
+    }
35 35
 }
36 36
 echo "\n";
37 37
 
38 38
 foreach ( $references as $refNum => $ref ) {
39
-	echo "  [$refNum] - " . $ref->statedIn()->getLabel() . "\n";
39
+    echo "  [$refNum] - " . $ref->statedIn()->getLabel() . "\n";
40 40
 }
Please login to merge, or discard this patch.
src/Query.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -9,84 +9,84 @@
 block discarded – undo
9 9
 
10 10
 class Query {
11 11
 
12
-	/** @var string */
13
-	protected $query;
12
+    /** @var string */
13
+    protected $query;
14 14
 
15
-	/** @var string */
16
-	protected $lang;
15
+    /** @var string */
16
+    protected $lang;
17 17
 
18
-	/** @var CacheItemPoolInterface */
19
-	protected $cache;
18
+    /** @var CacheItemPoolInterface */
19
+    protected $cache;
20 20
 
21
-	/**
22
-	 * Query constructor.
23
-	 * @param string $query The Sparql query.
24
-	 * @param string $lang The language.
25
-	 * @param CacheItemPoolInterface $cache The cache.
26
-	 */
27
-	public function __construct( $query, $lang, CacheItemPoolInterface $cache ) {
28
-		$this->query = $query;
29
-		$this->lang = $lang;
30
-		$this->cache = $cache;
31
-	}
21
+    /**
22
+     * Query constructor.
23
+     * @param string $query The Sparql query.
24
+     * @param string $lang The language.
25
+     * @param CacheItemPoolInterface $cache The cache.
26
+     */
27
+    public function __construct( $query, $lang, CacheItemPoolInterface $cache ) {
28
+        $this->query = $query;
29
+        $this->lang = $lang;
30
+        $this->cache = $cache;
31
+    }
32 32
 
33
-	/**
34
-	 * Get the items.
35
-	 * @return Item[] The results.
36
-	 */
37
-	public function getItems() {
38
-		$xml = $this->getXml( $this->query );
39
-		$results = [];
40
-		foreach ( $xml->results->result as $res ) {
41
-			$result = $this->getBindings( $res );
42
-			$id = substr( $result['item'], strrpos( $result['item'], '/' ) + 1 );
43
-			$item = Item::factory( $id, $this->lang, $this->cache );
44
-			$results[] = $item;
45
-		}
46
-		return $results;
47
-	}
33
+    /**
34
+     * Get the items.
35
+     * @return Item[] The results.
36
+     */
37
+    public function getItems() {
38
+        $xml = $this->getXml( $this->query );
39
+        $results = [];
40
+        foreach ( $xml->results->result as $res ) {
41
+            $result = $this->getBindings( $res );
42
+            $id = substr( $result['item'], strrpos( $result['item'], '/' ) + 1 );
43
+            $item = Item::factory( $id, $this->lang, $this->cache );
44
+            $results[] = $item;
45
+        }
46
+        return $results;
47
+    }
48 48
 
49
-	/**
50
-	 * @param string $query The Sparql query.
51
-	 * @return SimpleXmlElement
52
-	 * @throws Exception
53
-	 */
54
-	protected function getXml( $query ) {
55
-		$url = "https://query.wikidata.org/bigdata/namespace/wdq/sparql";
56
-		$client = new Client();
57
-		try {
58
-			$response = $client->request( 'GET', $url, [
59
-				// https://meta.wikimedia.org/wiki/User-Agent_policy
60
-				'User-Agent' => 'samwilson/simple-wikidata (User:Samwilson) PHP',
61
-				'query' => [ 'query' => $query ],
62
-			] );
63
-		} catch ( Exception $e ) {
64
-			throw new Exception( "Unable to run query: <pre>" . htmlspecialchars( $query ) . "</pre>", 500 );
65
-		}
66
-		$result = $response->getBody()->getContents();
67
-		if ( empty( $result ) ) {
68
-			$msg = "No result from query: <pre>" . htmlspecialchars( $query ) . "</pre>";
69
-			throw new Exception( $msg, 500 );
70
-		}
71
-		$xml = new SimpleXmlElement( $result );
72
-		return $xml;
73
-	}
49
+    /**
50
+     * @param string $query The Sparql query.
51
+     * @return SimpleXmlElement
52
+     * @throws Exception
53
+     */
54
+    protected function getXml( $query ) {
55
+        $url = "https://query.wikidata.org/bigdata/namespace/wdq/sparql";
56
+        $client = new Client();
57
+        try {
58
+            $response = $client->request( 'GET', $url, [
59
+                // https://meta.wikimedia.org/wiki/User-Agent_policy
60
+                'User-Agent' => 'samwilson/simple-wikidata (User:Samwilson) PHP',
61
+                'query' => [ 'query' => $query ],
62
+            ] );
63
+        } catch ( Exception $e ) {
64
+            throw new Exception( "Unable to run query: <pre>" . htmlspecialchars( $query ) . "</pre>", 500 );
65
+        }
66
+        $result = $response->getBody()->getContents();
67
+        if ( empty( $result ) ) {
68
+            $msg = "No result from query: <pre>" . htmlspecialchars( $query ) . "</pre>";
69
+            throw new Exception( $msg, 500 );
70
+        }
71
+        $xml = new SimpleXmlElement( $result );
72
+        return $xml;
73
+    }
74 74
 
75
-	/**
76
-	 * @param SimpleXmlElement $xml The query result XML.
77
-	 * @return array
78
-	 */
79
-	protected function getBindings( $xml ) {
80
-		$out = [];
81
-		foreach ( $xml->binding as $binding ) {
82
-			if ( isset( $binding->literal ) ) {
83
-				$out[(string)$binding['name']] = (string)$binding->literal;
84
-			}
85
-			if ( isset( $binding->uri ) ) {
86
-				$out[(string)$binding['name']] = (string)$binding->uri;
87
-			}
88
-		}
89
-		return $out;
90
-	}
75
+    /**
76
+     * @param SimpleXmlElement $xml The query result XML.
77
+     * @return array
78
+     */
79
+    protected function getBindings( $xml ) {
80
+        $out = [];
81
+        foreach ( $xml->binding as $binding ) {
82
+            if ( isset( $binding->literal ) ) {
83
+                $out[(string)$binding['name']] = (string)$binding->literal;
84
+            }
85
+            if ( isset( $binding->uri ) ) {
86
+                $out[(string)$binding['name']] = (string)$binding->uri;
87
+            }
88
+        }
89
+        return $out;
90
+    }
91 91
 
92 92
 }
Please login to merge, or discard this patch.