Passed
Push — master ( aeb35e...5f0582 )
by Sam
04:41
created
examples/humans.php 2 patches
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.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -3,21 +3,21 @@  discard block
 block discarded – undo
3 3
 require_once __DIR__ . '/../vendor/autoload.php';
4 4
 
5 5
 // Any PSR6 cache can be used.
6
-$cache = new Stash\Pool( new \Stash\Driver\FileSystem() );
6
+$cache = new Stash\Pool(new \Stash\Driver\FileSystem());
7 7
 
8 8
 /** @var \Samwilson\SimpleWikidata\Items\Human $princeCharles */
9
-$princeCharles = Samwilson\SimpleWikidata\Item::factory( 'Q43274', 'en', $cache );
9
+$princeCharles = Samwilson\SimpleWikidata\Item::factory('Q43274', 'en', $cache);
10 10
 
11
-echo $princeCharles->getLabel().":\n";
11
+echo $princeCharles->getLabel() . ":\n";
12 12
 
13 13
 $refNum = 1;
14 14
 $references = [];
15 15
 
16 16
 /** @var \Samwilson\SimpleWikidata\Properties\Time[] $datesOfBirth */
17 17
 $datesOfBirth = $princeCharles->getDatesOfBirth();
18
-echo "  Date of birth: ".$datesOfBirth[0]->getDateTime()->format( 'j F, Y' )." ";
19
-foreach ( $datesOfBirth[0]->getReferences() as $ref ) {
20
-	if ( $ref->statedIn() ) {
18
+echo "  Date of birth: " . $datesOfBirth[0]->getDateTime()->format('j F, Y') . " ";
19
+foreach ($datesOfBirth[0]->getReferences() as $ref) {
20
+	if ($ref->statedIn()) {
21 21
 		echo "[$refNum]";
22 22
 		$references[$refNum] = $ref;
23 23
 	}
@@ -26,15 +26,15 @@  discard block
 block discarded – undo
26 26
 
27 27
 /** @var \Samwilson\SimpleWikidata\Properties\Item[] $fathers */
28 28
 $fathers = $princeCharles->fathers();
29
-echo "  Father: ".$fathers[0]->getItem()->getLabel() . " ";
30
-foreach ( $fathers[0]->getReferences() as $ref ) {
31
-	if ( $ref->statedIn() ) {
29
+echo "  Father: " . $fathers[0]->getItem()->getLabel() . " ";
30
+foreach ($fathers[0]->getReferences() as $ref) {
31
+	if ($ref->statedIn()) {
32 32
 		echo "[$refNum]";
33 33
 		$references[$refNum] = $ref;
34 34
 	}
35 35
 }
36 36
 echo "\n";
37 37
 
38
-foreach ( $references as $refNum => $ref ) {
39
-	echo "  [$refNum] - " . $ref->statedIn()->getLabel()."\n";
38
+foreach ($references as $refNum => $ref) {
39
+	echo "  [$refNum] - " . $ref->statedIn()->getLabel() . "\n";
40 40
 }
Please login to merge, or discard this patch.
examples/query.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@
 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 ".$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 ".$height['amount']." ".$height['unit']->getLabel()." high.\n";
21 21
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -3,19 +3,19 @@
 block discarded – undo
3 3
 require_once __DIR__ . '/../vendor/autoload.php';
4 4
 
5 5
 // Any PSR6 cache can be used.
6
-$cache = new Stash\Pool( new \Stash\Driver\FileSystem() );
6
+$cache = new Stash\Pool(new \Stash\Driver\FileSystem());
7 7
 
8 8
 $sparql = 'SELECT ?item WHERE {
9 9
   ?item wdt:P31 wd:Q54050
10 10
 } LIMIT 5';
11
-$query = new \Samwilson\SimpleWikidata\Query( $sparql, 'en', $cache );
11
+$query = new \Samwilson\SimpleWikidata\Query($sparql, 'en', $cache);
12 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";
13
+foreach ($hills as $hill) {
14
+	$heights = $hill->getPropertyOfTypeQuantity('P2044');
15
+	if (!$heights) {
16
+		echo "No heights found for " . $hill->getLabel() . "\n";
17 17
 		continue;
18 18
 	}
19
-	$height = array_shift( $heights );
20
-	echo $hill->getLabel()." is ".$height['amount']." ".$height['unit']->getLabel()." high.\n";
19
+	$height = array_shift($heights);
20
+	echo $hill->getLabel() . " is " . $height['amount'] . " " . $height['unit']->getLabel() . " high.\n";
21 21
 }
Please login to merge, or discard this patch.
src/Items/Edition.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -16,22 +16,22 @@  discard block
 block discarded – undo
16 16
 	 * @return string
17 17
 	 */
18 18
 	public function getPublicationYear() {
19
-		$publicationYears = $this->getPropertyOfTypeTime( static::PROP_PUBLICATION_DATE );
20
-		return $publicationYears[0]->getDateTime()->format( 'Y' );
19
+		$publicationYears = $this->getPropertyOfTypeTime(static::PROP_PUBLICATION_DATE);
20
+		return $publicationYears[0]->getDateTime()->format('Y');
21 21
 	}
22 22
 
23 23
 	/**
24 24
 	 * @return \Samwilson\SimpleWikidata\Properties\Item[]
25 25
 	 */
26 26
 	public function getPublishers() {
27
-		return $this->getPropertyOfTypeItem( static::PROP_PUBLISHER );
27
+		return $this->getPropertyOfTypeItem(static::PROP_PUBLISHER);
28 28
 	}
29 29
 
30 30
 	/**
31 31
 	 * @return array|bool
32 32
 	 */
33 33
 	public function getWikisourceIndexPages() {
34
-		return $this->getPropertyOfTypeUrl( $this->getId(), static::PROP_WIKISOURCE_INDEX_PAGE );
34
+		return $this->getPropertyOfTypeUrl($this->getId(), static::PROP_WIKISOURCE_INDEX_PAGE);
35 35
 	}
36 36
 
37 37
 	/**
@@ -50,16 +50,16 @@  discard block
 block discarded – undo
50 50
 	 * @return string[]
51 51
 	 */
52 52
 	public function getWikisourceLink() {
53
-		$entity = $this->getEntity( $this->id );
54
-		if ( !isset( $entity['sitelinks'] ) ) {
53
+		$entity = $this->getEntity($this->id);
54
+		if (!isset($entity['sitelinks'])) {
55 55
 			return [];
56 56
 		}
57
-		foreach ( $entity['sitelinks'] as $sitelink ) {
58
-			if ( strpos( $sitelink['site'], 'wikisource' ) !== false ) {
59
-				$lang = substr( $sitelink['site'], 0, strpos( $sitelink['site'], 'wikisource' ) );
57
+		foreach ($entity['sitelinks'] as $sitelink) {
58
+			if (strpos($sitelink['site'], 'wikisource') !== false) {
59
+				$lang = substr($sitelink['site'], 0, strpos($sitelink['site'], 'wikisource'));
60 60
 				return [
61 61
 					'title' => $sitelink['title'],
62
-					'url' => "https://$lang.wikisource.org/wiki/".$sitelink['title'],
62
+					'url' => "https://$lang.wikisource.org/wiki/" . $sitelink['title'],
63 63
 					'lang' => $lang,
64 64
 				];
65 65
 			}
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -6,66 +6,66 @@
 block discarded – undo
6 6
 
7 7
 class Edition extends Item {
8 8
 
9
-	const PROP_EDITION_OR_TRANSLATION_OF = 'P629';
10
-	const PROP_WIKISOURCE_INDEX_PAGE = 'P1957';
11
-	const PROP_SCANNED_FILE_ON_COMMONS = 'P996';
12
-	const PROP_INTERNET_ARCHIVE_ID = 'P724';
13
-	const PROP_PUBLICATION_DATE = 'P577';
14
-	const PROP_PUBLISHER = 'P123';
9
+    const PROP_EDITION_OR_TRANSLATION_OF = 'P629';
10
+    const PROP_WIKISOURCE_INDEX_PAGE = 'P1957';
11
+    const PROP_SCANNED_FILE_ON_COMMONS = 'P996';
12
+    const PROP_INTERNET_ARCHIVE_ID = 'P724';
13
+    const PROP_PUBLICATION_DATE = 'P577';
14
+    const PROP_PUBLISHER = 'P123';
15 15
 
16
-	/**
17
-	 * @return string
18
-	 */
19
-	public function getPublicationYear() {
20
-		$publicationYears = $this->getPropertyOfTypeTime( static::PROP_PUBLICATION_DATE );
21
-		return $publicationYears[0]->getDateTime()->format( 'Y' );
22
-	}
16
+    /**
17
+     * @return string
18
+     */
19
+    public function getPublicationYear() {
20
+        $publicationYears = $this->getPropertyOfTypeTime( static::PROP_PUBLICATION_DATE );
21
+        return $publicationYears[0]->getDateTime()->format( 'Y' );
22
+    }
23 23
 
24
-	/**
25
-	 * @return \Samwilson\SimpleWikidata\Properties\Item[]
26
-	 */
27
-	public function getPublishers() {
28
-		return $this->getPropertyOfTypeItem( static::PROP_PUBLISHER );
29
-	}
24
+    /**
25
+     * @return \Samwilson\SimpleWikidata\Properties\Item[]
26
+     */
27
+    public function getPublishers() {
28
+        return $this->getPropertyOfTypeItem( static::PROP_PUBLISHER );
29
+    }
30 30
 
31
-	/**
32
-	 * @return array|bool
33
-	 */
34
-	public function getWikisourceIndexPages() {
35
-		return $this->getPropertyOfTypeUrl( $this->getId(), static::PROP_WIKISOURCE_INDEX_PAGE );
36
-	}
31
+    /**
32
+     * @return array|bool
33
+     */
34
+    public function getWikisourceIndexPages() {
35
+        return $this->getPropertyOfTypeUrl( $this->getId(), static::PROP_WIKISOURCE_INDEX_PAGE );
36
+    }
37 37
 
38
-	/**
39
-	 * @return array
40
-	 */
41
-	public function internetArchiveIds() {
42
-		return $this->getPropertyOfTypeExternalIdentifier(
43
-			$this->getId(),
44
-			self::PROP_INTERNET_ARCHIVE_ID
45
-		);
46
-	}
38
+    /**
39
+     * @return array
40
+     */
41
+    public function internetArchiveIds() {
42
+        return $this->getPropertyOfTypeExternalIdentifier(
43
+            $this->getId(),
44
+            self::PROP_INTERNET_ARCHIVE_ID
45
+        );
46
+    }
47 47
 
48
-	/**
49
-	 * Get information about the Wikisource sitelink.
50
-	 * An edition should only ever be present on one Wikisource.
51
-	 * @return string[]
52
-	 */
53
-	public function getWikisourceLink() {
54
-		$entity = $this->getEntity( $this->id );
55
-		if ( !isset( $entity['sitelinks'] ) ) {
56
-			return [];
57
-		}
58
-		foreach ( $entity['sitelinks'] as $sitelink ) {
59
-			if ( strpos( $sitelink['site'], 'wikisource' ) !== false ) {
60
-				$lang = substr( $sitelink['site'], 0, strpos( $sitelink['site'], 'wikisource' ) );
61
-				return [
62
-					'title' => $sitelink['title'],
63
-					'url' => "https://$lang.wikisource.org/wiki/".$sitelink['title'],
64
-					'lang' => $lang,
65
-				];
66
-			}
67
-		}
68
-		return [];
69
-	}
48
+    /**
49
+     * Get information about the Wikisource sitelink.
50
+     * An edition should only ever be present on one Wikisource.
51
+     * @return string[]
52
+     */
53
+    public function getWikisourceLink() {
54
+        $entity = $this->getEntity( $this->id );
55
+        if ( !isset( $entity['sitelinks'] ) ) {
56
+            return [];
57
+        }
58
+        foreach ( $entity['sitelinks'] as $sitelink ) {
59
+            if ( strpos( $sitelink['site'], 'wikisource' ) !== false ) {
60
+                $lang = substr( $sitelink['site'], 0, strpos( $sitelink['site'], 'wikisource' ) );
61
+                return [
62
+                    'title' => $sitelink['title'],
63
+                    'url' => "https://$lang.wikisource.org/wiki/".$sitelink['title'],
64
+                    'lang' => $lang,
65
+                ];
66
+            }
67
+        }
68
+        return [];
69
+    }
70 70
 
71 71
 }
Please login to merge, or discard this patch.
src/Properties/Time.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -27,48 +27,48 @@
 block discarded – undo
27 27
  */
28 28
 class Time extends Property {
29 29
 
30
-	/**
31
-	 * @return DateTime
32
-	 */
33
-	public function getDateTime() {
34
-		return new DateTime( $this->claim['mainsnak']['datavalue']['value']['time'] );
35
-	}
30
+    /**
31
+     * @return DateTime
32
+     */
33
+    public function getDateTime() {
34
+        return new DateTime( $this->claim['mainsnak']['datavalue']['value']['time'] );
35
+    }
36 36
 
37
-	/**
38
-	 * @return DateTimeZone
39
-	 */
40
-	public function getTimezone() {
41
-		return new DateTimeZone( $this->claim['mainsnak']['datavalue']['value']['timezone'] );
42
-	}
37
+    /**
38
+     * @return DateTimeZone
39
+     */
40
+    public function getTimezone() {
41
+        return new DateTimeZone( $this->claim['mainsnak']['datavalue']['value']['timezone'] );
42
+    }
43 43
 
44
-	/**
45
-	 * @return mixed
46
-	 */
47
-	public function getBefore() {
48
-		return $this->claim['mainsnak']['datavalue']['value']['before'];
49
-	}
44
+    /**
45
+     * @return mixed
46
+     */
47
+    public function getBefore() {
48
+        return $this->claim['mainsnak']['datavalue']['value']['before'];
49
+    }
50 50
 
51
-	/**
52
-	 * @return mixed
53
-	 */
54
-	public function getAfter() {
55
-		return $this->claim['mainsnak']['datavalue']['value']['time'];
56
-	}
51
+    /**
52
+     * @return mixed
53
+     */
54
+    public function getAfter() {
55
+        return $this->claim['mainsnak']['datavalue']['value']['time'];
56
+    }
57 57
 
58
-	/**
59
-	 * @return int The numbers have the following meanings: 0 - billion years,
60
-	 * 1 - hundred million years, ...,
61
-	 * 6 - millennium, 7 - century, 8 - decade, 9 - year, 10 - month, 11 - day, 12 - hour,
62
-	 * 13 - minute, 14 - second.
63
-	 */
64
-	public function getPrecision() {
65
-		return $this->claim['mainsnak']['datavalue']['value']['precision'];
66
-	}
58
+    /**
59
+     * @return int The numbers have the following meanings: 0 - billion years,
60
+     * 1 - hundred million years, ...,
61
+     * 6 - millennium, 7 - century, 8 - decade, 9 - year, 10 - month, 11 - day, 12 - hour,
62
+     * 13 - minute, 14 - second.
63
+     */
64
+    public function getPrecision() {
65
+        return $this->claim['mainsnak']['datavalue']['value']['precision'];
66
+    }
67 67
 
68
-	/**
69
-	 * @return mixed
70
-	 */
71
-	public function getCalendarModel() {
72
-		return $this->claim['mainsnak']['datavalue']['value']['calendarmodel'];
73
-	}
68
+    /**
69
+     * @return mixed
70
+     */
71
+    public function getCalendarModel() {
72
+        return $this->claim['mainsnak']['datavalue']['value']['calendarmodel'];
73
+    }
74 74
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,14 +31,14 @@
 block discarded – undo
31 31
 	 * @return DateTime
32 32
 	 */
33 33
 	public function getDateTime() {
34
-		return new DateTime( $this->claim['mainsnak']['datavalue']['value']['time'] );
34
+		return new DateTime($this->claim['mainsnak']['datavalue']['value']['time']);
35 35
 	}
36 36
 
37 37
 	/**
38 38
 	 * @return DateTimeZone
39 39
 	 */
40 40
 	public function getTimezone() {
41
-		return new DateTimeZone( $this->claim['mainsnak']['datavalue']['value']['timezone'] );
41
+		return new DateTimeZone($this->claim['mainsnak']['datavalue']['value']['timezone']);
42 42
 	}
43 43
 
44 44
 	/**
Please login to merge, or discard this patch.
src/Properties/Item.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -6,11 +6,11 @@
 block discarded – undo
6 6
 
7 7
 class Item extends Property {
8 8
 
9
-	/**
10
-	 * @return \Samwilson\SimpleWikidata\Item
11
-	 */
12
-	public function getItem() {
13
-		$itemId = $this->claim['mainsnak']['datavalue']['value']['id'];
14
-		return \Samwilson\SimpleWikidata\Item::factory( $itemId, $this->lang, $this->cache );
15
-	}
9
+    /**
10
+     * @return \Samwilson\SimpleWikidata\Item
11
+     */
12
+    public function getItem() {
13
+        $itemId = $this->claim['mainsnak']['datavalue']['value']['id'];
14
+        return \Samwilson\SimpleWikidata\Item::factory( $itemId, $this->lang, $this->cache );
15
+    }
16 16
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,6 +11,6 @@
 block discarded – undo
11 11
 	 */
12 12
 	public function getItem() {
13 13
 		$itemId = $this->claim['mainsnak']['datavalue']['value']['id'];
14
-		return \Samwilson\SimpleWikidata\Item::factory( $itemId, $this->lang, $this->cache );
14
+		return \Samwilson\SimpleWikidata\Item::factory($itemId, $this->lang, $this->cache);
15 15
 	}
16 16
 }
Please login to merge, or discard this patch.
src/Property.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -6,32 +6,32 @@
 block discarded – undo
6 6
 
7 7
 abstract class Property {
8 8
 
9
-		/** @var string[] */
10
-	protected $claim;
11
-
12
-		/** @var string */
13
-	protected $lang;
14
-
15
-		/** @var CacheItemPoolInterface */
16
-	protected $cache;
17
-
18
-		public function __construct( $claim, $lang, $cache ) {
19
-		$this->claim = $claim;
20
-		$this->lang = $lang;
21
-		$this->cache = $cache;
22
-	 }
23
-
24
-	/**
25
-	 * @return Reference[]
26
-	 */
27
-	public function getReferences() {
28
-		$references = [];
29
-		if ( !isset( $this->claim['references'] ) ) {
30
-			return $references;
31
-		}
32
-		foreach ( $this->claim['references'] as $ref ) {
33
-			$references[] = new Reference( $ref, $this->lang, $this->cache );
34
-		}
35
-		return $references;
36
-	}
9
+        /** @var string[] */
10
+    protected $claim;
11
+
12
+        /** @var string */
13
+    protected $lang;
14
+
15
+        /** @var CacheItemPoolInterface */
16
+    protected $cache;
17
+
18
+        public function __construct( $claim, $lang, $cache ) {
19
+        $this->claim = $claim;
20
+        $this->lang = $lang;
21
+        $this->cache = $cache;
22
+        }
23
+
24
+    /**
25
+     * @return Reference[]
26
+     */
27
+    public function getReferences() {
28
+        $references = [];
29
+        if ( !isset( $this->claim['references'] ) ) {
30
+            return $references;
31
+        }
32
+        foreach ( $this->claim['references'] as $ref ) {
33
+            $references[] = new Reference( $ref, $this->lang, $this->cache );
34
+        }
35
+        return $references;
36
+    }
37 37
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 		/** @var CacheItemPoolInterface */
16 16
 	protected $cache;
17 17
 
18
-		public function __construct( $claim, $lang, $cache ) {
18
+		public function __construct($claim, $lang, $cache) {
19 19
 		$this->claim = $claim;
20 20
 		$this->lang = $lang;
21 21
 		$this->cache = $cache;
@@ -26,11 +26,11 @@  discard block
 block discarded – undo
26 26
 	 */
27 27
 	public function getReferences() {
28 28
 		$references = [];
29
-		if ( !isset( $this->claim['references'] ) ) {
29
+		if (!isset($this->claim['references'])) {
30 30
 			return $references;
31 31
 		}
32
-		foreach ( $this->claim['references'] as $ref ) {
33
-			$references[] = new Reference( $ref, $this->lang, $this->cache );
32
+		foreach ($this->claim['references'] as $ref) {
33
+			$references[] = new Reference($ref, $this->lang, $this->cache);
34 34
 		}
35 35
 		return $references;
36 36
 	}
Please login to merge, or discard this patch.
src/Query.php 2 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -8,78 +8,78 @@
 block discarded – undo
8 8
 
9 9
 class Query {
10 10
 
11
-	/** @var string */
12
-	protected $query;
11
+    /** @var string */
12
+    protected $query;
13 13
 
14
-	/** @var string */
15
-	protected $lang;
14
+    /** @var string */
15
+    protected $lang;
16 16
 
17
-	/** @var CacheItemPoolInterface */
18
-	protected $cache;
17
+    /** @var CacheItemPoolInterface */
18
+    protected $cache;
19 19
 
20
-	/**
21
-	 * Query constructor.
22
-	 * @param string $query The Sparql query.
23
-	 * @param string $lang The language.
24
-	 * @param CacheItemPoolInterface $cache The cache.
25
-	 */
26
-	public function __construct( $query, $lang, CacheItemPoolInterface $cache ) {
27
-		$this->query = $query;
28
-		$this->lang = $lang;
29
-		$this->cache = $cache;
30
-	}
20
+    /**
21
+     * Query constructor.
22
+     * @param string $query The Sparql query.
23
+     * @param string $lang The language.
24
+     * @param CacheItemPoolInterface $cache The cache.
25
+     */
26
+    public function __construct( $query, $lang, CacheItemPoolInterface $cache ) {
27
+        $this->query = $query;
28
+        $this->lang = $lang;
29
+        $this->cache = $cache;
30
+    }
31 31
 
32
-	/**
33
-	 * Get the items.
34
-	 * @return Item[] The results.
35
-	 */
36
-	public function getItems() {
37
-		$xml = $this->getXml( $this->query );
38
-		$results = [];
39
-		foreach ( $xml->results->result as $res ) {
40
-			$result = $this->getBindings( $res );
41
-			$id = substr( $result['item'], strrpos( $result['item'], '/' ) + 1 );
42
-			$item = Item::factory( $id, $this->lang, $this->cache );
43
-			$results[] = $item;
44
-		}
45
-		return $results;
46
-	}
32
+    /**
33
+     * Get the items.
34
+     * @return Item[] The results.
35
+     */
36
+    public function getItems() {
37
+        $xml = $this->getXml( $this->query );
38
+        $results = [];
39
+        foreach ( $xml->results->result as $res ) {
40
+            $result = $this->getBindings( $res );
41
+            $id = substr( $result['item'], strrpos( $result['item'], '/' ) + 1 );
42
+            $item = Item::factory( $id, $this->lang, $this->cache );
43
+            $results[] = $item;
44
+        }
45
+        return $results;
46
+    }
47 47
 
48
-	/**
49
-	 * @param string $query The Sparql query.
50
-	 * @return SimpleXmlElement
51
-	 * @throws Exception
52
-	 */
53
-	protected function getXml( $query ) {
54
-		$url = "https://query.wikidata.org/bigdata/namespace/wdq/sparql?query=" . urlencode( $query );
55
-		try {
56
-			$result = file_get_contents( $url );
57
-		} catch ( Exception $e ) {
58
-			throw new Exception( "Unable to run query: <pre>" . htmlspecialchars( $query ) . "</pre>", 500 );
59
-		}
60
-		if ( empty( $result ) ) {
61
-			$msg = "No result from query: <pre>" . htmlspecialchars( $query ) . "</pre>";
62
-			throw new Exception( $msg, 500 );
63
-		}
64
-		$xml = new SimpleXmlElement( $result );
65
-		return $xml;
66
-	}
48
+    /**
49
+     * @param string $query The Sparql query.
50
+     * @return SimpleXmlElement
51
+     * @throws Exception
52
+     */
53
+    protected function getXml( $query ) {
54
+        $url = "https://query.wikidata.org/bigdata/namespace/wdq/sparql?query=" . urlencode( $query );
55
+        try {
56
+            $result = file_get_contents( $url );
57
+        } catch ( Exception $e ) {
58
+            throw new Exception( "Unable to run query: <pre>" . htmlspecialchars( $query ) . "</pre>", 500 );
59
+        }
60
+        if ( empty( $result ) ) {
61
+            $msg = "No result from query: <pre>" . htmlspecialchars( $query ) . "</pre>";
62
+            throw new Exception( $msg, 500 );
63
+        }
64
+        $xml = new SimpleXmlElement( $result );
65
+        return $xml;
66
+    }
67 67
 
68
-	/**
69
-	 * @param SimpleXmlElement $xml The query result XML.
70
-	 * @return array
71
-	 */
72
-	protected function getBindings( $xml ) {
73
-		$out = [];
74
-		foreach ( $xml->binding as $binding ) {
75
-			if ( isset( $binding->literal ) ) {
76
-				$out[(string)$binding['name']] = (string)$binding->literal;
77
-			}
78
-			if ( isset( $binding->uri ) ) {
79
-				$out[(string)$binding['name']] = (string)$binding->uri;
80
-			}
81
-		}
82
-		return $out;
83
-	}
68
+    /**
69
+     * @param SimpleXmlElement $xml The query result XML.
70
+     * @return array
71
+     */
72
+    protected function getBindings( $xml ) {
73
+        $out = [];
74
+        foreach ( $xml->binding as $binding ) {
75
+            if ( isset( $binding->literal ) ) {
76
+                $out[(string)$binding['name']] = (string)$binding->literal;
77
+            }
78
+            if ( isset( $binding->uri ) ) {
79
+                $out[(string)$binding['name']] = (string)$binding->uri;
80
+            }
81
+        }
82
+        return $out;
83
+    }
84 84
 
85 85
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * @param string $lang The language.
24 24
 	 * @param CacheItemPoolInterface $cache The cache.
25 25
 	 */
26
-	public function __construct( $query, $lang, CacheItemPoolInterface $cache ) {
26
+	public function __construct($query, $lang, CacheItemPoolInterface $cache) {
27 27
 		$this->query = $query;
28 28
 		$this->lang = $lang;
29 29
 		$this->cache = $cache;
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
 	 * @return Item[] The results.
35 35
 	 */
36 36
 	public function getItems() {
37
-		$xml = $this->getXml( $this->query );
37
+		$xml = $this->getXml($this->query);
38 38
 		$results = [];
39
-		foreach ( $xml->results->result as $res ) {
40
-			$result = $this->getBindings( $res );
41
-			$id = substr( $result['item'], strrpos( $result['item'], '/' ) + 1 );
42
-			$item = Item::factory( $id, $this->lang, $this->cache );
39
+		foreach ($xml->results->result as $res) {
40
+			$result = $this->getBindings($res);
41
+			$id = substr($result['item'], strrpos($result['item'], '/') + 1);
42
+			$item = Item::factory($id, $this->lang, $this->cache);
43 43
 			$results[] = $item;
44 44
 		}
45 45
 		return $results;
@@ -50,18 +50,18 @@  discard block
 block discarded – undo
50 50
 	 * @return SimpleXmlElement
51 51
 	 * @throws Exception
52 52
 	 */
53
-	protected function getXml( $query ) {
54
-		$url = "https://query.wikidata.org/bigdata/namespace/wdq/sparql?query=" . urlencode( $query );
53
+	protected function getXml($query) {
54
+		$url = "https://query.wikidata.org/bigdata/namespace/wdq/sparql?query=" . urlencode($query);
55 55
 		try {
56
-			$result = file_get_contents( $url );
57
-		} catch ( Exception $e ) {
58
-			throw new Exception( "Unable to run query: <pre>" . htmlspecialchars( $query ) . "</pre>", 500 );
56
+			$result = file_get_contents($url);
57
+		} catch (Exception $e) {
58
+			throw new Exception("Unable to run query: <pre>" . htmlspecialchars($query) . "</pre>", 500);
59 59
 		}
60
-		if ( empty( $result ) ) {
61
-			$msg = "No result from query: <pre>" . htmlspecialchars( $query ) . "</pre>";
62
-			throw new Exception( $msg, 500 );
60
+		if (empty($result)) {
61
+			$msg = "No result from query: <pre>" . htmlspecialchars($query) . "</pre>";
62
+			throw new Exception($msg, 500);
63 63
 		}
64
-		$xml = new SimpleXmlElement( $result );
64
+		$xml = new SimpleXmlElement($result);
65 65
 		return $xml;
66 66
 	}
67 67
 
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
 	 * @param SimpleXmlElement $xml The query result XML.
70 70
 	 * @return array
71 71
 	 */
72
-	protected function getBindings( $xml ) {
72
+	protected function getBindings($xml) {
73 73
 		$out = [];
74
-		foreach ( $xml->binding as $binding ) {
75
-			if ( isset( $binding->literal ) ) {
74
+		foreach ($xml->binding as $binding) {
75
+			if (isset($binding->literal)) {
76 76
 				$out[(string)$binding['name']] = (string)$binding->literal;
77 77
 			}
78
-			if ( isset( $binding->uri ) ) {
78
+			if (isset($binding->uri)) {
79 79
 				$out[(string)$binding['name']] = (string)$binding->uri;
80 80
 			}
81 81
 		}
Please login to merge, or discard this patch.
src/Reference.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -6,37 +6,37 @@
 block discarded – undo
6 6
 
7 7
 class Reference {
8 8
 
9
-	const STATED_IN = 'P248';
10
-
11
-	/** @var array */
12
-	protected $data;
13
-
14
-	/** @var string */
15
-	protected $lang;
16
-
17
-	/** @var CacheItemPoolInterface */
18
-	protected $cache;
19
-
20
-	/**
21
-	 * @param string[] $data The data.
22
-	 * @param string $lang ISO639 language code.
23
-	 * @param CacheItemPoolInterface $cache The cache.
24
-	 */
25
-	public function __construct( $data, $lang, $cache ) {
26
-		$this->data = $data;
27
-		$this->lang = $lang;
28
-		$this->cache = $cache;
29
-	}
30
-
31
-	/**
32
-	 * @return Item|bool The item, or false if there isn't one.
33
-	 */
34
-	public function statedIn() {
35
-		if ( !isset( $this->data['snaks'][self::STATED_IN] ) ) {
36
-			return false;
37
-		}
38
-		foreach ( $this->data['snaks'][self::STATED_IN] as $snak ) {
39
-			return Item::factory( $snak['datavalue']['value']['id'], $this->lang, $this->cache );
40
-		}
41
-	}
9
+    const STATED_IN = 'P248';
10
+
11
+    /** @var array */
12
+    protected $data;
13
+
14
+    /** @var string */
15
+    protected $lang;
16
+
17
+    /** @var CacheItemPoolInterface */
18
+    protected $cache;
19
+
20
+    /**
21
+     * @param string[] $data The data.
22
+     * @param string $lang ISO639 language code.
23
+     * @param CacheItemPoolInterface $cache The cache.
24
+     */
25
+    public function __construct( $data, $lang, $cache ) {
26
+        $this->data = $data;
27
+        $this->lang = $lang;
28
+        $this->cache = $cache;
29
+    }
30
+
31
+    /**
32
+     * @return Item|bool The item, or false if there isn't one.
33
+     */
34
+    public function statedIn() {
35
+        if ( !isset( $this->data['snaks'][self::STATED_IN] ) ) {
36
+            return false;
37
+        }
38
+        foreach ( $this->data['snaks'][self::STATED_IN] as $snak ) {
39
+            return Item::factory( $snak['datavalue']['value']['id'], $this->lang, $this->cache );
40
+        }
41
+    }
42 42
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * @param string $lang ISO639 language code.
23 23
 	 * @param CacheItemPoolInterface $cache The cache.
24 24
 	 */
25
-	public function __construct( $data, $lang, $cache ) {
25
+	public function __construct($data, $lang, $cache) {
26 26
 		$this->data = $data;
27 27
 		$this->lang = $lang;
28 28
 		$this->cache = $cache;
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
 	 * @return Item|bool The item, or false if there isn't one.
33 33
 	 */
34 34
 	public function statedIn() {
35
-		if ( !isset( $this->data['snaks'][self::STATED_IN] ) ) {
35
+		if (!isset($this->data['snaks'][self::STATED_IN])) {
36 36
 			return false;
37 37
 		}
38
-		foreach ( $this->data['snaks'][self::STATED_IN] as $snak ) {
39
-			return Item::factory( $snak['datavalue']['value']['id'], $this->lang, $this->cache );
38
+		foreach ($this->data['snaks'][self::STATED_IN] as $snak) {
39
+			return Item::factory($snak['datavalue']['value']['id'], $this->lang, $this->cache);
40 40
 		}
41 41
 	}
42 42
 }
Please login to merge, or discard this patch.
src/Items/Work.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -11,94 +11,94 @@
 block discarded – undo
11 11
  */
12 12
 class Work extends Item {
13 13
 
14
-	const ITEM_WORK = 'Q386724';
15
-	const PROP_SUBTITLE = 'P1680';
16
-	const PROP_GENRE = 'P136';
17
-	const PROP_SUBJECT = 'P921';
14
+    const ITEM_WORK = 'Q386724';
15
+    const PROP_SUBTITLE = 'P1680';
16
+    const PROP_GENRE = 'P136';
17
+    const PROP_SUBJECT = 'P921';
18 18
 
19
-	/**
20
-	 * @param string $lang ISO639 language code.
21
-	 * @param CacheItemPoolInterface $cache The cache.
22
-	 * @return array|Item[]
23
-	 */
24
-	public static function getBookTypes( $lang = 'en', $cache ) {
25
-		$sparql = "SELECT ?item WHERE {
19
+    /**
20
+     * @param string $lang ISO639 language code.
21
+     * @param CacheItemPoolInterface $cache The cache.
22
+     * @return array|Item[]
23
+     */
24
+    public static function getBookTypes( $lang = 'en', $cache ) {
25
+        $sparql = "SELECT ?item WHERE {
26 26
 			?item wdt:P279 wd:Q571 .
27 27
 			?item rdfs:label ?label .
28 28
 			FILTER(LANG(?label) = '$lang') .
29 29
 			} ORDER BY ?label ";
30
-		$query = new Query( $sparql, $lang );
31
-		$query->setCache( $cache );
32
-		$bookType = Item::factory( self::ITEM_WORK, $lang, $cache );
33
-		return [ $bookType ] + $query->getItems();
34
-	}
30
+        $query = new Query( $sparql, $lang );
31
+        $query->setCache( $cache );
32
+        $bookType = Item::factory( self::ITEM_WORK, $lang, $cache );
33
+        return [ $bookType ] + $query->getItems();
34
+    }
35 35
 
36
-	/**
37
-	 * @return bool|string
38
-	 */
39
-	public function getSubtitle() {
40
-		return $this->getPropertyOfTypeText( self::PROP_SUBTITLE );
41
-	}
36
+    /**
37
+     * @return bool|string
38
+     */
39
+    public function getSubtitle() {
40
+        return $this->getPropertyOfTypeText( self::PROP_SUBTITLE );
41
+    }
42 42
 
43
-	/**
44
-	 * @param string $subtitle The new subtitle.
45
-	 */
46
-	public function setSubtitle( $subtitle ) {
47
-		$this->setPropertyOfTypeText( self::PROP_SUBTITLE, $subtitle );
48
-	}
43
+    /**
44
+     * @param string $subtitle The new subtitle.
45
+     */
46
+    public function setSubtitle( $subtitle ) {
47
+        $this->setPropertyOfTypeText( self::PROP_SUBTITLE, $subtitle );
48
+    }
49 49
 
50
-	/**
51
-	 * @param string $property A property identifier.
52
-	 * @return array
53
-	 */
54
-	public function getPropertyOfTypeItems( $property ) {
55
-		$entity = $this->getEntity( $this->id );
56
-		if ( ! isset( $entity['claims'][ $property ] ) ) {
57
-			return [];
58
-		}
59
-		$items = [];
60
-		foreach ( $entity['claims'][ $property ] as $authorClaim ) {
61
-			$item_id  = $authorClaim['mainsnak']['datavalue']['value']['id'];
62
-			$items[] = Item::factory( $item_id, $this->lang, $this->cache );
63
-		}
50
+    /**
51
+     * @param string $property A property identifier.
52
+     * @return array
53
+     */
54
+    public function getPropertyOfTypeItems( $property ) {
55
+        $entity = $this->getEntity( $this->id );
56
+        if ( ! isset( $entity['claims'][ $property ] ) ) {
57
+            return [];
58
+        }
59
+        $items = [];
60
+        foreach ( $entity['claims'][ $property ] as $authorClaim ) {
61
+            $item_id  = $authorClaim['mainsnak']['datavalue']['value']['id'];
62
+            $items[] = Item::factory( $item_id, $this->lang, $this->cache );
63
+        }
64 64
 
65
-		return $items;
66
-	}
65
+        return $items;
66
+    }
67 67
 
68
-	/**
69
-	 * @return array
70
-	 */
71
-	public function getAuthors() {
72
-		return $this->getPropertyOfTypeItems( self::PROP_AUTHOR );
73
-	}
68
+    /**
69
+     * @return array
70
+     */
71
+    public function getAuthors() {
72
+        return $this->getPropertyOfTypeItems( self::PROP_AUTHOR );
73
+    }
74 74
 
75
-	/**
76
-	 * @return Item[]
77
-	 */
78
-	public function getSubjects() {
79
-		return $this->getPropertyOfTypeItems( self::PROP_SUBJECT );
80
-	}
75
+    /**
76
+     * @return Item[]
77
+     */
78
+    public function getSubjects() {
79
+        return $this->getPropertyOfTypeItems( self::PROP_SUBJECT );
80
+    }
81 81
 
82
-	/**
83
-	 * @return Item[]
84
-	 */
85
-	public function getEditions() {
86
-		$sparql = "SELECT ?item WHERE {"
87
-			. " ?item wdt:" . Edition::PROP_EDITION_OR_TRANSLATION_OF . " wd:" . $this->getId()
88
-			. "}";
89
-		$query = new Query( $sparql, $this->lang, $this->cache );
90
-		$editions = $query->getItems();
91
-		usort( $editions, function ( Item $a, Item $b ) {
92
-			if ( $a instanceof EditionItem and $b instanceof EditionItem ) {
93
-				return $a->getPublicationYear() - $b->getPublicationYear();
94
-			}
95
-			return 0;
96
-		} );
82
+    /**
83
+     * @return Item[]
84
+     */
85
+    public function getEditions() {
86
+        $sparql = "SELECT ?item WHERE {"
87
+            . " ?item wdt:" . Edition::PROP_EDITION_OR_TRANSLATION_OF . " wd:" . $this->getId()
88
+            . "}";
89
+        $query = new Query( $sparql, $this->lang, $this->cache );
90
+        $editions = $query->getItems();
91
+        usort( $editions, function ( Item $a, Item $b ) {
92
+            if ( $a instanceof EditionItem and $b instanceof EditionItem ) {
93
+                return $a->getPublicationYear() - $b->getPublicationYear();
94
+            }
95
+            return 0;
96
+        } );
97 97
 
98
-		return $editions;
99
-	}
98
+        return $editions;
99
+    }
100 100
 
101
-	public function newEdition() {
102
-	}
101
+    public function newEdition() {
102
+    }
103 103
 
104 104
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -21,45 +21,45 @@  discard block
 block discarded – undo
21 21
 	 * @param CacheItemPoolInterface $cache The cache.
22 22
 	 * @return array|Item[]
23 23
 	 */
24
-	public static function getBookTypes( $lang = 'en', $cache ) {
24
+	public static function getBookTypes($lang = 'en', $cache) {
25 25
 		$sparql = "SELECT ?item WHERE {
26 26
 			?item wdt:P279 wd:Q571 .
27 27
 			?item rdfs:label ?label .
28 28
 			FILTER(LANG(?label) = '$lang') .
29 29
 			} ORDER BY ?label ";
30
-		$query = new Query( $sparql, $lang );
31
-		$query->setCache( $cache );
32
-		$bookType = Item::factory( self::ITEM_WORK, $lang, $cache );
33
-		return [ $bookType ] + $query->getItems();
30
+		$query = new Query($sparql, $lang);
31
+		$query->setCache($cache);
32
+		$bookType = Item::factory(self::ITEM_WORK, $lang, $cache);
33
+		return [$bookType] + $query->getItems();
34 34
 	}
35 35
 
36 36
 	/**
37 37
 	 * @return bool|string
38 38
 	 */
39 39
 	public function getSubtitle() {
40
-		return $this->getPropertyOfTypeText( self::PROP_SUBTITLE );
40
+		return $this->getPropertyOfTypeText(self::PROP_SUBTITLE);
41 41
 	}
42 42
 
43 43
 	/**
44 44
 	 * @param string $subtitle The new subtitle.
45 45
 	 */
46
-	public function setSubtitle( $subtitle ) {
47
-		$this->setPropertyOfTypeText( self::PROP_SUBTITLE, $subtitle );
46
+	public function setSubtitle($subtitle) {
47
+		$this->setPropertyOfTypeText(self::PROP_SUBTITLE, $subtitle);
48 48
 	}
49 49
 
50 50
 	/**
51 51
 	 * @param string $property A property identifier.
52 52
 	 * @return array
53 53
 	 */
54
-	public function getPropertyOfTypeItems( $property ) {
55
-		$entity = $this->getEntity( $this->id );
56
-		if ( ! isset( $entity['claims'][ $property ] ) ) {
54
+	public function getPropertyOfTypeItems($property) {
55
+		$entity = $this->getEntity($this->id);
56
+		if (!isset($entity['claims'][$property])) {
57 57
 			return [];
58 58
 		}
59 59
 		$items = [];
60
-		foreach ( $entity['claims'][ $property ] as $authorClaim ) {
61
-			$item_id  = $authorClaim['mainsnak']['datavalue']['value']['id'];
62
-			$items[] = Item::factory( $item_id, $this->lang, $this->cache );
60
+		foreach ($entity['claims'][$property] as $authorClaim) {
61
+			$item_id = $authorClaim['mainsnak']['datavalue']['value']['id'];
62
+			$items[] = Item::factory($item_id, $this->lang, $this->cache);
63 63
 		}
64 64
 
65 65
 		return $items;
@@ -69,14 +69,14 @@  discard block
 block discarded – undo
69 69
 	 * @return array
70 70
 	 */
71 71
 	public function getAuthors() {
72
-		return $this->getPropertyOfTypeItems( self::PROP_AUTHOR );
72
+		return $this->getPropertyOfTypeItems(self::PROP_AUTHOR);
73 73
 	}
74 74
 
75 75
 	/**
76 76
 	 * @return Item[]
77 77
 	 */
78 78
 	public function getSubjects() {
79
-		return $this->getPropertyOfTypeItems( self::PROP_SUBJECT );
79
+		return $this->getPropertyOfTypeItems(self::PROP_SUBJECT);
80 80
 	}
81 81
 
82 82
 	/**
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
 		$sparql = "SELECT ?item WHERE {"
87 87
 			. " ?item wdt:" . Edition::PROP_EDITION_OR_TRANSLATION_OF . " wd:" . $this->getId()
88 88
 			. "}";
89
-		$query = new Query( $sparql, $this->lang, $this->cache );
89
+		$query = new Query($sparql, $this->lang, $this->cache);
90 90
 		$editions = $query->getItems();
91
-		usort( $editions, function ( Item $a, Item $b ) {
92
-			if ( $a instanceof EditionItem and $b instanceof EditionItem ) {
91
+		usort($editions, function(Item $a, Item $b) {
92
+			if ($a instanceof EditionItem and $b instanceof EditionItem) {
93 93
 				return $a->getPublicationYear() - $b->getPublicationYear();
94 94
 			}
95 95
 			return 0;
Please login to merge, or discard this patch.