Passed
Push — master ( 3a7c7a...fe0bb9 )
by Sam
03:04
created
examples/humans.php 1 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 1 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/Work.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -18,45 +18,45 @@  discard block
 block discarded – undo
18 18
 	 * @param CacheItemPoolInterface $cache The cache.
19 19
 	 * @return array|Item[]
20 20
 	 */
21
-	public static function getBookTypes( $lang = 'en', $cache ) {
21
+	public static function getBookTypes($lang = 'en', $cache) {
22 22
 		$sparql = "SELECT ?item WHERE {
23 23
 			?item wdt:P279 wd:Q571 .
24 24
 			?item rdfs:label ?label .
25 25
 			FILTER(LANG(?label) = '$lang') .
26 26
 			} ORDER BY ?label ";
27
-		$query = new Query( $sparql, $lang );
28
-		$query->setCache( $cache );
29
-		$bookType = Item::factory( self::ITEM_WORK, $lang, $cache );
30
-		return [ $bookType ] + $query->getItems();
27
+		$query = new Query($sparql, $lang);
28
+		$query->setCache($cache);
29
+		$bookType = Item::factory(self::ITEM_WORK, $lang, $cache);
30
+		return [$bookType] + $query->getItems();
31 31
 	}
32 32
 
33 33
 	/**
34 34
 	 * @return bool|string
35 35
 	 */
36 36
 	public function getSubtitle() {
37
-		return $this->getPropertyOfTypeText( self::PROP_SUBTITLE );
37
+		return $this->getPropertyOfTypeText(self::PROP_SUBTITLE);
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * @param string $subtitle The new subtitle.
42 42
 	 */
43
-	public function setSubtitle( $subtitle ) {
44
-		$this->setPropertyOfTypeText( self::PROP_SUBTITLE, $subtitle );
43
+	public function setSubtitle($subtitle) {
44
+		$this->setPropertyOfTypeText(self::PROP_SUBTITLE, $subtitle);
45 45
 	}
46 46
 
47 47
 	/**
48 48
 	 * @param string $property A property identifier.
49 49
 	 * @return array
50 50
 	 */
51
-	public function getPropertyOfTypeItems( $property ) {
52
-		$entity = $this->getEntity( $this->id );
53
-		if ( ! isset( $entity['claims'][ $property ] ) ) {
51
+	public function getPropertyOfTypeItems($property) {
52
+		$entity = $this->getEntity($this->id);
53
+		if (!isset($entity['claims'][$property])) {
54 54
 			return [];
55 55
 		}
56 56
 		$items = [];
57
-		foreach ( $entity['claims'][ $property ] as $authorClaim ) {
58
-			$item_id  = $authorClaim['mainsnak']['datavalue']['value']['id'];
59
-			$items[] = Item::factory( $item_id, $this->lang, $this->cache );
57
+		foreach ($entity['claims'][$property] as $authorClaim) {
58
+			$item_id = $authorClaim['mainsnak']['datavalue']['value']['id'];
59
+			$items[] = Item::factory($item_id, $this->lang, $this->cache);
60 60
 		}
61 61
 
62 62
 		return $items;
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
 	 * @return array
67 67
 	 */
68 68
 	public function getAuthors() {
69
-		return $this->getPropertyOfTypeItems( self::PROP_AUTHOR );
69
+		return $this->getPropertyOfTypeItems(self::PROP_AUTHOR);
70 70
 	}
71 71
 
72 72
 	/**
73 73
 	 * @return Item[]
74 74
 	 */
75 75
 	public function getSubjects() {
76
-		return $this->getPropertyOfTypeItems( self::PROP_SUBJECT );
76
+		return $this->getPropertyOfTypeItems(self::PROP_SUBJECT);
77 77
 	}
78 78
 
79 79
 	/**
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 		$sparql = "SELECT ?item WHERE {"
84 84
 			. " ?item wdt:" . self::PROP_EDITION_OR_TRANSLATION_OF . " wd:" . $this->getId()
85 85
 			. "}";
86
-		$query = new Query( $sparql, $this->lang );
87
-		$query->setCache( $this->cache );
86
+		$query = new Query($sparql, $this->lang);
87
+		$query->setCache($this->cache);
88 88
 		$editions = $query->getItems();
89
-		usort( $editions, function ( Item $a, Item $b ) {
90
-			if ( $a instanceof EditionItem and $b instanceof EditionItem ) {
89
+		usort($editions, function(Item $a, Item $b) {
90
+			if ($a instanceof EditionItem and $b instanceof EditionItem) {
91 91
 				return $a->getPublicationYear() - $b->getPublicationYear();
92 92
 			}
93 93
 			return 0;
Please login to merge, or discard this patch.
src/Items/Edition.php 1 patch
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.
src/Items/Human.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,14 +10,14 @@
 block discarded – undo
10 10
 	const PROP_FATHER = 'P22';
11 11
 
12 12
 		public function getDatesOfBirth() {
13
-		return $this->getPropertyOfTypeTime( self::PROP_DATE_OF_BIRTH );
13
+		return $this->getPropertyOfTypeTime(self::PROP_DATE_OF_BIRTH);
14 14
 	 }
15 15
 
16 16
 	/**
17 17
 	 * @return Item[]
18 18
 	 */
19 19
 	public function fathers() {
20
-		return $this->getPropertyOfTypeItem( self::PROP_FATHER );
20
+		return $this->getPropertyOfTypeItem(self::PROP_FATHER);
21 21
 	}
22 22
 
23 23
 }
Please login to merge, or discard this patch.
src/Properties/Time.php 1 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 1 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 1 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 1 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.