Passed
Branch master (39cfbc)
by Sam
04:07
created
src/WorkItem.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -4,73 +4,73 @@
 block discarded – undo
4 4
 
5 5
 class WorkItem extends Item {
6 6
 
7
-	const ITEM_WORK = 'Q386724';
8
-	const PROP_SUBTITLE = 'P1680';
9
-	const PROP_GENRE = 'P136';
10
-	const PROP_SUBJECT = 'P921';
7
+    const ITEM_WORK = 'Q386724';
8
+    const PROP_SUBTITLE = 'P1680';
9
+    const PROP_GENRE = 'P136';
10
+    const PROP_SUBJECT = 'P921';
11 11
 
12
-	public static function getBookTypes($lang = 'en', $cache) {
13
-		$sparql = "SELECT ?item WHERE {
12
+    public static function getBookTypes($lang = 'en', $cache) {
13
+        $sparql = "SELECT ?item WHERE {
14 14
 			?item wdt:P279 wd:Q571 .
15 15
 			?item rdfs:label ?label .
16 16
 			FILTER(LANG(?label) = '$lang') .
17 17
 			} ORDER BY ?label ";
18
-		$query = new Query($sparql, $lang);
19
-		$query->setCache($cache);
20
-		$bookType = Item::factory(self::ITEM_WORK, $lang, $cache);
21
-		return [$bookType] + $query->getItems();
22
-	}
18
+        $query = new Query($sparql, $lang);
19
+        $query->setCache($cache);
20
+        $bookType = Item::factory(self::ITEM_WORK, $lang, $cache);
21
+        return [$bookType] + $query->getItems();
22
+    }
23 23
 
24
-	public function getSubtitle() {
25
-		return $this->getPropertyOfTypeText(self::PROP_SUBTITLE);
26
-	}
24
+    public function getSubtitle() {
25
+        return $this->getPropertyOfTypeText(self::PROP_SUBTITLE);
26
+    }
27 27
 
28
-	public function setSubtitle( $subtitle ) {
29
-		$this->setPropertyOfTypeText( self::PROP_SUBTITLE, $subtitle );
30
-	}
28
+    public function setSubtitle( $subtitle ) {
29
+        $this->setPropertyOfTypeText( self::PROP_SUBTITLE, $subtitle );
30
+    }
31 31
 
32
-	public function getPropertyOfTypeItems( $property ) {
33
-		$entity = $this->getEntity( $this->id );
34
-		if ( ! isset( $entity['claims'][ $property ] ) ) {
35
-			return [];
36
-		}
37
-		$items = [];
38
-		foreach ( $entity['claims'][ $property ] as $authorClaim ) {
39
-			$item_id  = $authorClaim['mainsnak']['datavalue']['value']['id'];
40
-			$items[] = Item::factory( $item_id, $this->lang, $this->cache );
41
-		}
32
+    public function getPropertyOfTypeItems( $property ) {
33
+        $entity = $this->getEntity( $this->id );
34
+        if ( ! isset( $entity['claims'][ $property ] ) ) {
35
+            return [];
36
+        }
37
+        $items = [];
38
+        foreach ( $entity['claims'][ $property ] as $authorClaim ) {
39
+            $item_id  = $authorClaim['mainsnak']['datavalue']['value']['id'];
40
+            $items[] = Item::factory( $item_id, $this->lang, $this->cache );
41
+        }
42 42
 
43
-		return $items;
44
-	}
43
+        return $items;
44
+    }
45 45
 
46
-	public function getAuthors() {
47
-		return $this->getPropertyOfTypeItems( self::PROP_AUTHOR );
48
-	}
46
+    public function getAuthors() {
47
+        return $this->getPropertyOfTypeItems( self::PROP_AUTHOR );
48
+    }
49 49
 
50
-	/**
51
-	 * @return Item[]
52
-	 */
53
-	public function getSubjects() {
54
-		return $this->getPropertyOfTypeItems( self::PROP_SUBJECT );
55
-	}
50
+    /**
51
+     * @return Item[]
52
+     */
53
+    public function getSubjects() {
54
+        return $this->getPropertyOfTypeItems( self::PROP_SUBJECT );
55
+    }
56 56
 
57
-	public function getEditions() {
58
-		$sparql = "SELECT ?item WHERE { ?item wdt:" . self::PROP_EDITION_OR_TRANSLATION_OF . " wd:" . $this->getId() . " }";
59
-		$query = new Query( $sparql, $this->lang );
60
-		$query->setCache($this->cache);
61
-		$editions = $query->getItems();
62
-		usort( $editions, function ( Item $a, Item $b ) {
63
-			if ( $a instanceof EditionItem and $b instanceof EditionItem ) {
64
-				return $a->getPublicationYear() - $b->getPublicationYear();
65
-			}
66
-			return 0;
67
-		} );
57
+    public function getEditions() {
58
+        $sparql = "SELECT ?item WHERE { ?item wdt:" . self::PROP_EDITION_OR_TRANSLATION_OF . " wd:" . $this->getId() . " }";
59
+        $query = new Query( $sparql, $this->lang );
60
+        $query->setCache($this->cache);
61
+        $editions = $query->getItems();
62
+        usort( $editions, function ( Item $a, Item $b ) {
63
+            if ( $a instanceof EditionItem and $b instanceof EditionItem ) {
64
+                return $a->getPublicationYear() - $b->getPublicationYear();
65
+            }
66
+            return 0;
67
+        } );
68 68
 
69
-		return $editions;
70
-	}
69
+        return $editions;
70
+    }
71 71
 
72
-	public function newEdition() {
72
+    public function newEdition() {
73 73
 		
74
-	}
74
+    }
75 75
 
76 76
 }
77 77
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -25,42 +25,42 @@
 block discarded – undo
25 25
 		return $this->getPropertyOfTypeText(self::PROP_SUBTITLE);
26 26
 	}
27 27
 
28
-	public function setSubtitle( $subtitle ) {
29
-		$this->setPropertyOfTypeText( self::PROP_SUBTITLE, $subtitle );
28
+	public function setSubtitle($subtitle) {
29
+		$this->setPropertyOfTypeText(self::PROP_SUBTITLE, $subtitle);
30 30
 	}
31 31
 
32
-	public function getPropertyOfTypeItems( $property ) {
33
-		$entity = $this->getEntity( $this->id );
34
-		if ( ! isset( $entity['claims'][ $property ] ) ) {
32
+	public function getPropertyOfTypeItems($property) {
33
+		$entity = $this->getEntity($this->id);
34
+		if (!isset($entity['claims'][$property])) {
35 35
 			return [];
36 36
 		}
37 37
 		$items = [];
38
-		foreach ( $entity['claims'][ $property ] as $authorClaim ) {
39
-			$item_id  = $authorClaim['mainsnak']['datavalue']['value']['id'];
40
-			$items[] = Item::factory( $item_id, $this->lang, $this->cache );
38
+		foreach ($entity['claims'][$property] as $authorClaim) {
39
+			$item_id = $authorClaim['mainsnak']['datavalue']['value']['id'];
40
+			$items[] = Item::factory($item_id, $this->lang, $this->cache);
41 41
 		}
42 42
 
43 43
 		return $items;
44 44
 	}
45 45
 
46 46
 	public function getAuthors() {
47
-		return $this->getPropertyOfTypeItems( self::PROP_AUTHOR );
47
+		return $this->getPropertyOfTypeItems(self::PROP_AUTHOR);
48 48
 	}
49 49
 
50 50
 	/**
51 51
 	 * @return Item[]
52 52
 	 */
53 53
 	public function getSubjects() {
54
-		return $this->getPropertyOfTypeItems( self::PROP_SUBJECT );
54
+		return $this->getPropertyOfTypeItems(self::PROP_SUBJECT);
55 55
 	}
56 56
 
57 57
 	public function getEditions() {
58 58
 		$sparql = "SELECT ?item WHERE { ?item wdt:" . self::PROP_EDITION_OR_TRANSLATION_OF . " wd:" . $this->getId() . " }";
59
-		$query = new Query( $sparql, $this->lang );
59
+		$query = new Query($sparql, $this->lang);
60 60
 		$query->setCache($this->cache);
61 61
 		$editions = $query->getItems();
62
-		usort( $editions, function ( Item $a, Item $b ) {
63
-			if ( $a instanceof EditionItem and $b instanceof EditionItem ) {
62
+		usort($editions, function(Item $a, Item $b) {
63
+			if ($a instanceof EditionItem and $b instanceof EditionItem) {
64 64
 				return $a->getPublicationYear() - $b->getPublicationYear();
65 65
 			}
66 66
 			return 0;
Please login to merge, or discard this patch.
src/Item.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
      */
113 113
     public function getLabel()
114 114
     {
115
-        $entity = $this->getEntity( $this->id );
116
-        if ( ! empty( $entity['labels'][ $this->lang ]['value'] ) ) {
115
+        $entity = $this->getEntity($this->id);
116
+        if (!empty($entity['labels'][$this->lang]['value'])) {
117 117
             // Use the label if there is one.
118
-            return $entity['labels'][ $this->lang ]['value'];
118
+            return $entity['labels'][$this->lang]['value'];
119 119
         }
120 120
         // Or just use the ID.
121 121
         return $entity['id'];
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 
124 124
     public function getWikidataUrl()
125 125
     {
126
-        return $this->wikidataUrlBase.$this->id;
126
+        return $this->wikidataUrlBase . $this->id;
127 127
     }
128 128
 
129 129
     public function getStandardProperties($type = 'work')
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
             $domCrawler->addHtmlContent(file_get_contents('https://www.wikidata.org/wiki/Wikidata:WikiProject_Books'));
140 140
             $propCells = $domCrawler->filterXPath("//h3/span[@id='" . ucfirst($type) . "_item_properties']/../following-sibling::table[1]//td[2]/a");
141 141
             $propIds = [];
142
-            $propCells->each(function (Crawler $node, $i) use (&$propIds) {
142
+            $propCells->each(function(Crawler $node, $i) use (&$propIds) {
143 143
                 $propId = $node->text();
144 144
                 $propIds[] = $propId;
145 145
             });
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
         }
338 338
         foreach ($entity['claims'][$property] as $t) {
339 339
             $quantity = $t['mainsnak']['datavalue']['value'];
340
-            $unitId = substr($quantity['unit'], strlen($this->wikidataUrlBase)+1);
340
+            $unitId = substr($quantity['unit'], strlen($this->wikidataUrlBase) + 1);
341 341
             $quantity['unit'] = Item::factory($unitId, $this->lang, $this->cache);
342 342
             $quantities[] = $quantity;
343 343
         }
Please login to merge, or discard this patch.
src/EditionItem.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
                 $lang = substr($sitelink['site'], 0, strpos($sitelink['site'], 'wikisource'));
45 45
                 return [
46 46
                     'title' => $sitelink['title'],
47
-                    'url' => "https://$lang.wikisource.org/wiki/".$sitelink['title'],
47
+                    'url' => "https://$lang.wikisource.org/wiki/" . $sitelink['title'],
48 48
                     'lang' => $lang,
49 49
                 ];
50 50
             }
Please login to merge, or discard this patch.
examples/query.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@
 block discarded – undo
13 13
 foreach ($hills as $hill) {
14 14
     $heights = $hill->getPropertyOfTypeQuantity('P2044');
15 15
     if (!$heights) {
16
-        echo "No heights found for ".$hill->getLabel()."\n";
16
+        echo "No heights found for " . $hill->getLabel() . "\n";
17 17
         continue;
18 18
     }
19 19
     $height = array_shift($heights);
20
-    echo $hill->getLabel()." is ".$height['amount']." ".$height['unit']->getLabel()." high.\n";
20
+    echo $hill->getLabel() . " is " . $height['amount'] . " " . $height['unit']->getLabel() . " high.\n";
21 21
 }
Please login to merge, or discard this patch.