Passed
Push — master ( e27b5b...ca43c6 )
by Sam
02:55
created
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/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.
src/Reference.php 1 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/Human.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,41 +24,41 @@
 block discarded – undo
24 24
 	 * @return bool|\Samwilson\SimpleWikidata\Properties\Time[]
25 25
 	 */
26 26
 	public function getDatesOfBirth() {
27
-		return $this->getPropertyOfTypeTime( self::PROP_DATE_OF_BIRTH );
27
+		return $this->getPropertyOfTypeTime(self::PROP_DATE_OF_BIRTH);
28 28
 	}
29 29
 
30 30
 	/**
31 31
 	 * @return bool|\Samwilson\SimpleWikidata\Properties\Time[]
32 32
 	 */
33 33
 	public function getDatesOfDeath() {
34
-		return $this->getPropertyOfTypeTime( self::PROP_DATE_OF_DEATH );
34
+		return $this->getPropertyOfTypeTime(self::PROP_DATE_OF_DEATH);
35 35
 	}
36 36
 
37 37
 	/**
38 38
 	 * @return \Samwilson\SimpleWikidata\Properties\Item[]
39 39
 	 */
40 40
 	public function fathers() {
41
-		return $this->getPropertyOfTypeItem( self::PROP_FATHER );
41
+		return $this->getPropertyOfTypeItem(self::PROP_FATHER);
42 42
 	}
43 43
 
44 44
 	/**
45 45
 	 * @return \Samwilson\SimpleWikidata\Properties\Item[]
46 46
 	 */
47 47
 	public function mothers() {
48
-		return $this->getPropertyOfTypeItem( self::PROP_FATHER );
48
+		return $this->getPropertyOfTypeItem(self::PROP_FATHER);
49 49
 	}
50 50
 
51 51
 	/**
52 52
 	 * @return \Samwilson\SimpleWikidata\Properties\Item[]
53 53
 	 */
54 54
 	public function spouses() {
55
-		return $this->getPropertyOfTypeItem( self::PROP_SPOUSE );
55
+		return $this->getPropertyOfTypeItem(self::PROP_SPOUSE);
56 56
 	}
57 57
 
58 58
 	/**
59 59
 	 * @return \Samwilson\SimpleWikidata\Properties\Item[]
60 60
 	 */
61 61
 	public function children() {
62
-		return $this->getPropertyOfTypeItem( self::PROP_CHILD );
62
+		return $this->getPropertyOfTypeItem(self::PROP_CHILD);
63 63
 	}
64 64
 }
Please login to merge, or discard this patch.
src/Search.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 * @param string $lang Language to use for the search results.
21 21
 	 * @param CacheItemPoolInterface $cache The cache to use.
22 22
 	 */
23
-	public function __construct( $searchTerm, $lang, CacheItemPoolInterface $cache ) {
23
+	public function __construct($searchTerm, $lang, CacheItemPoolInterface $cache) {
24 24
 		$this->searchTerm = $searchTerm;
25 25
 		$this->lang = $lang;
26 26
 		$this->cache = $cache;
@@ -30,20 +30,20 @@  discard block
 block discarded – undo
30 30
 	 * @param string $limit The number of search results to return.
31 31
 	 * @return Item[]
32 32
 	 */
33
-	public function getItems( $limit = 'max' ) {
34
-		$api = MediawikiApi::newFromApiEndpoint( 'https://www.wikidata.org/w/api.php' );
33
+	public function getItems($limit = 'max') {
34
+		$api = MediawikiApi::newFromApiEndpoint('https://www.wikidata.org/w/api.php');
35 35
 		$req = FluentRequest::factory()
36
-			->setAction( 'wbsearchentities' )
37
-			->addParams( [
36
+			->setAction('wbsearchentities')
37
+			->addParams([
38 38
 				'search' => $this->searchTerm,
39 39
 				'type' => 'item',
40 40
 				'limit' => $limit,
41 41
 				'language' => 'en',
42
-			] );
42
+			]);
43 43
 		$results = [];
44
-		$response = $api->getRequest( $req );
45
-		foreach ( $response['search'] as $info ) {
46
-			$item = Item::factory( $info['id'], $this->lang, $this->cache );
44
+		$response = $api->getRequest($req);
45
+		foreach ($response['search'] as $info) {
46
+			$item = Item::factory($info['id'], $this->lang, $this->cache);
47 47
 			$results[] = $item;
48 48
 		}
49 49
 		return $results;
Please login to merge, or discard this patch.
src/Item.php 1 patch
Spacing   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -38,12 +38,12 @@  discard block
 block discarded – undo
38 38
 	/** @var string The base URL of Wikidata, with trailing slash. */
39 39
 	protected $wikidataUrlBase = 'https://www.wikidata.org/wiki/';
40 40
 
41
-	private function __construct( $id, $lang, CacheItemPoolInterface $cache ) {
42
-		if ( !is_string( $id ) || preg_match( '/[QP][0-9]*/i', $id ) !== 1 ) {
43
-			throw new Exception( "Not a valid ID: " . var_export( $id, true ) );
41
+	private function __construct($id, $lang, CacheItemPoolInterface $cache) {
42
+		if (!is_string($id) || preg_match('/[QP][0-9]*/i', $id) !== 1) {
43
+			throw new Exception("Not a valid ID: " . var_export($id, true));
44 44
 		}
45 45
 		$this->id = $id;
46
-		$this->wdApi = new MediawikiApi( 'https://www.wikidata.org/w/api.php' );
46
+		$this->wdApi = new MediawikiApi('https://www.wikidata.org/w/api.php');
47 47
 		$this->entities = [];
48 48
 		$this->lang = $lang;
49 49
 		$this->cache = $cache;
@@ -57,21 +57,21 @@  discard block
 block discarded – undo
57 57
 	 * @param CacheItemPoolInterface $cache The cache to use.
58 58
 	 * @return Item
59 59
 	 */
60
-	public static function factory( $id, $lang, CacheItemPoolInterface $cache ) {
61
-		$item = new Item( $id, $lang, $cache );
62
-		foreach ( $item->getPropertyOfTypeItem( self::PROP_INSTANCE_OF ) as $instanceOf ) {
60
+	public static function factory($id, $lang, CacheItemPoolInterface $cache) {
61
+		$item = new Item($id, $lang, $cache);
62
+		foreach ($item->getPropertyOfTypeItem(self::PROP_INSTANCE_OF) as $instanceOf) {
63 63
 			// Try to find a class matching the registered 'instance of'.
64
-			foreach ( static::$registeredClasses as $classId => $className ) {
64
+			foreach (static::$registeredClasses as $classId => $className) {
65 65
 				// If this 'instance of' is registered, use it.
66
-				if ( $classId === $instanceOf->getItem()->getId() ) {
66
+				if ($classId === $instanceOf->getItem()->getId()) {
67 67
 					// This won't re-request the metadata, because that's cached.
68
-					return new $className( $id, $lang, $cache );
68
+					return new $className($id, $lang, $cache);
69 69
 				}
70 70
 			}
71 71
 		}
72 72
 
73 73
 		// If we're here, just leave it as a basic Item.
74
-		$item->setCache( $cache );
74
+		$item->setCache($cache);
75 75
 		return $item;
76 76
 	}
77 77
 
@@ -81,19 +81,19 @@  discard block
 block discarded – undo
81 81
 	 * @throws Exception if called on Item or the registering class does not have INSTANCE_OF set.
82 82
 	 */
83 83
 	public static function register() {
84
-		if ( static::class === self::class ) {
85
-			throw new Exception( __METHOD__ . ' should only be called on subclasses of Item' );
84
+		if (static::class === self::class) {
85
+			throw new Exception(__METHOD__ . ' should only be called on subclasses of Item');
86 86
 		}
87
-		if ( !static::INSTANCE_OF ) {
88
-			throw new Exception( 'Please set INSTANCE_OF for ' . static::class );
87
+		if (!static::INSTANCE_OF) {
88
+			throw new Exception('Please set INSTANCE_OF for ' . static::class);
89 89
 		}
90
-		static::$registeredClasses[ static::INSTANCE_OF ] = static::class;
90
+		static::$registeredClasses[static::INSTANCE_OF] = static::class;
91 91
 	}
92 92
 
93 93
 	/**
94 94
 	 * @param CacheItemPoolInterface $cache The cache to use.
95 95
 	 */
96
-	public function setCache( CacheItemPoolInterface $cache ) {
96
+	public function setCache(CacheItemPoolInterface $cache) {
97 97
 		$this->cache = $cache;
98 98
 	}
99 99
 
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
 	 * @return string|bool The ID or false if it couldn't be determined.
103 103
 	 */
104 104
 	public function getId() {
105
-		$entity = $this->getEntity( $this->id );
106
-		return isset( $entity['id'] ) ? $entity['id'] : false;
105
+		$entity = $this->getEntity($this->id);
106
+		return isset($entity['id']) ? $entity['id'] : false;
107 107
 	}
108 108
 
109 109
 	/**
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
 	 * @return string
112 112
 	 */
113 113
 	public function getLabel() {
114
-		$entity = $this->getEntity( $this->id );
115
-		if ( !empty( $entity['labels'][ $this->lang ]['value'] ) ) {
114
+		$entity = $this->getEntity($this->id);
115
+		if (!empty($entity['labels'][$this->lang]['value'])) {
116 116
 			// Use the label if there is one.
117
-			return $entity['labels'][ $this->lang ]['value'];
117
+			return $entity['labels'][$this->lang]['value'];
118 118
 		}
119 119
 		// Or just use the ID.
120 120
 		return $entity['id'];
@@ -139,33 +139,33 @@  discard block
 block discarded – undo
139 139
 	 * @param string $type
140 140
 	 * @return array
141 141
 	 */
142
-	public function getStandardProperties( $wikiProject = 'WikiProject_Books', $type = 'work' ) {
143
-		if ( $type !== 'work' ) {
142
+	public function getStandardProperties($wikiProject = 'WikiProject_Books', $type = 'work') {
143
+		if ($type !== 'work') {
144 144
 			$type = 'edition';
145 145
 		}
146 146
 		$cacheKey = $type . '_item_property_IDs';
147
-		if ( $this->cache->hasItem( $cacheKey ) ) {
148
-			$propIds = $this->cache->getItem( $cacheKey )->get();
147
+		if ($this->cache->hasItem($cacheKey)) {
148
+			$propIds = $this->cache->getItem($cacheKey)->get();
149 149
 		} else {
150 150
 			$domCrawler = new Crawler();
151 151
 			$wikiProjectUrl = 'https://www.wikidata.org/wiki/Wikidata:' . $wikiProject;
152
-			$domCrawler->addHtmlContent( file_get_contents( $wikiProjectUrl ) );
153
-			$propAncors = "//h3/span[@id='" . ucfirst( $type ) . "_item_properties']"
152
+			$domCrawler->addHtmlContent(file_get_contents($wikiProjectUrl));
153
+			$propAncors = "//h3/span[@id='" . ucfirst($type) . "_item_properties']"
154 154
 				. "/../following-sibling::table[1]//td[2]/a";
155
-			$propCells = $domCrawler->filterXPath( $propAncors );
155
+			$propCells = $domCrawler->filterXPath($propAncors);
156 156
 			$propIds = [];
157
-			$propCells->each( function ( Crawler $node, $i ) use ( &$propIds ) {
157
+			$propCells->each(function(Crawler $node, $i) use (&$propIds) {
158 158
 				$propId = $node->text();
159 159
 				$propIds[] = $propId;
160 160
 			} );
161
-			$cacheItem = $this->cache->getItem( $cacheKey )
162
-				->expiresAfter( new DateInterval( 'PT1H' ) )
163
-				->set( $propIds );
164
-			$this->cache->save( $cacheItem );
161
+			$cacheItem = $this->cache->getItem($cacheKey)
162
+				->expiresAfter(new DateInterval('PT1H'))
163
+				->set($propIds);
164
+			$this->cache->save($cacheItem);
165 165
 		}
166 166
 		$workProperties = [];
167
-		foreach ( $propIds as $propId ) {
168
-			$workProperties[] = self::factory( $propId, $this->lang, $this->cache );
167
+		foreach ($propIds as $propId) {
168
+			$workProperties[] = self::factory($propId, $this->lang, $this->cache);
169 169
 		}
170 170
 
171 171
 		return $workProperties;
@@ -175,17 +175,17 @@  discard block
 block discarded – undo
175 175
 	 * @param string $propertyId
176 176
 	 * @return bool|Time[]
177 177
 	 */
178
-	public function getPropertyOfTypeTime( $propertyId ) {
178
+	public function getPropertyOfTypeTime($propertyId) {
179 179
 		$times = [];
180 180
 		$entity = $this->getEntity();
181
-		if ( !isset( $entity['claims'][$propertyId] ) ) {
181
+		if (!isset($entity['claims'][$propertyId])) {
182 182
 			// No statements for this property.
183 183
 			return $times;
184 184
 		}
185 185
 		// print_r($entity['claims'][$propertyId]);exit();
186
-		foreach ( $entity['claims'][$propertyId] as $claim ) {
186
+		foreach ($entity['claims'][$propertyId] as $claim) {
187 187
 			// print_r($claim);
188
-			$times[] = new Time( $claim, $this->lang, $this->cache );
188
+			$times[] = new Time($claim, $this->lang, $this->cache);
189 189
 //
190 190
 // $timeValue = $claim['datavalue']['value']['time'];
191 191
 // // Ugly workaround for imprecise dates. :-(
@@ -207,14 +207,14 @@  discard block
 block discarded – undo
207 207
 	 *
208 208
 	 * @return \Samwilson\SimpleWikidata\Properties\Item[]
209 209
 	 */
210
-	public function getPropertyOfTypeItem( $propertyId ) {
211
-		$entity = $this->getEntity( $this->id );
212
-		if ( !isset( $entity['claims'][$propertyId] ) ) {
210
+	public function getPropertyOfTypeItem($propertyId) {
211
+		$entity = $this->getEntity($this->id);
212
+		if (!isset($entity['claims'][$propertyId])) {
213 213
 			return [];
214 214
 		}
215 215
 		$items = [];
216
-		foreach ( $entity['claims'][$propertyId] as $claim ) {
217
-			$items[] = new Properties\Item( $claim, $this->lang, $this->cache );
216
+		foreach ($entity['claims'][$propertyId] as $claim) {
217
+			$items[] = new Properties\Item($claim, $this->lang, $this->cache);
218 218
 		}
219 219
 
220 220
 		return $items;
@@ -225,15 +225,15 @@  discard block
 block discarded – undo
225 225
 	 * @param string $property Property ID, with 'P'.
226 226
 	 * @param string $itemId Item ID with 'Q'.
227 227
 	 */
228
-	public function setPropertyOfTypeItem( $property, $itemId ) {
229
-		$itemIdNumeric = substr( $itemId, 1 );
228
+	public function setPropertyOfTypeItem($property, $itemId) {
229
+		$itemIdNumeric = substr($itemId, 1);
230 230
 
231 231
 		// First see if this property already exists, and that it is different from what's being set.
232
-		$entity = $this->getEntity( $this->id );
233
-		if ( !empty( $entity['claims'][$property] ) ) {
232
+		$entity = $this->getEntity($this->id);
233
+		if (!empty($entity['claims'][$property])) {
234 234
 			// Get the first claim, and update it if necessary.
235
-			$claim = array_shift( $entity['claims'][$property] );
236
-			if ( $claim['mainsnak']['datavalue']['value']['id'] == $itemId ) {
235
+			$claim = array_shift($entity['claims'][$property]);
236
+			if ($claim['mainsnak']['datavalue']['value']['id'] == $itemId) {
237 237
 				// Already is the required value, no need to change.
238 238
 				return;
239 239
 			}
@@ -241,25 +241,25 @@  discard block
 block discarded – undo
241 241
 			$claim['mainsnak']['datavalue']['value']['numeric-id'] = $itemIdNumeric;
242 242
 			$apiParams = [
243 243
 				'action' => 'wbsetclaim',
244
-				'claim' => json_encode( $claim ),
244
+				'claim' => json_encode($claim),
245 245
 			];
246 246
 		}
247 247
 
248 248
 		// If no claim was found (and modified) above, create a new claim.
249
-		if ( !isset( $apiParams ) ) {
249
+		if (!isset($apiParams)) {
250 250
 			$apiParams = [
251 251
 				'action' => 'wbcreateclaim',
252 252
 				'entity' => $this->getId(),
253 253
 				'property' => $property,
254 254
 				'snaktype' => 'value',
255
-				'value' => json_encode( [ 'entity-type' => 'item', 'numeric-id' => $itemIdNumeric ] ),
255
+				'value' => json_encode(['entity-type' => 'item', 'numeric-id' => $itemIdNumeric]),
256 256
 			];
257 257
 		}
258 258
 
259 259
 		// @TODO Save the property.
260 260
 
261 261
 		// Clear the cache.
262
-		$this->cache->deleteItem( $this->getEntityCacheKey( $this->id ) );
262
+		$this->cache->deleteItem($this->getEntityCacheKey($this->id));
263 263
 	}
264 264
 
265 265
 	/**
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
 	 * @param string $propertyId
268 268
 	 * @return array|bool
269 269
 	 */
270
-	public function getPropertyOfTypeUrl( $entityId, $propertyId ) {
271
-		$entity = $this->getEntity( $entityId );
272
-		if ( !isset( $entity['claims'][$propertyId] ) ) {
270
+	public function getPropertyOfTypeUrl($entityId, $propertyId) {
271
+		$entity = $this->getEntity($entityId);
272
+		if (!isset($entity['claims'][$propertyId])) {
273 273
 			return false;
274 274
 		}
275 275
 		$urls = [];
276
-		foreach ( $entity['claims'][$propertyId] as $claim ) {
276
+		foreach ($entity['claims'][$propertyId] as $claim) {
277 277
 			$urls[] = $claim['mainsnak']['datavalue']['value'];
278 278
 		}
279 279
 
@@ -285,22 +285,22 @@  discard block
 block discarded – undo
285 285
 	 * @param string $propertyId
286 286
 	 * @return array|bool
287 287
 	 */
288
-	public function getPropertyOfTypeExternalIdentifier( $entityId, $propertyId ) {
289
-		$entity = $this->getEntity( $entityId );
290
-		if ( !isset( $entity['claims'][$propertyId] ) ) {
288
+	public function getPropertyOfTypeExternalIdentifier($entityId, $propertyId) {
289
+		$entity = $this->getEntity($entityId);
290
+		if (!isset($entity['claims'][$propertyId])) {
291 291
 			return false;
292 292
 		}
293 293
 		$idents = [];
294
-		foreach ( $entity['claims'][$propertyId] as $claim ) {
294
+		foreach ($entity['claims'][$propertyId] as $claim) {
295 295
 			$qualifiers = [];
296
-			if ( !isset( $claim['qualifiers'] ) ) {
296
+			if (!isset($claim['qualifiers'])) {
297 297
 				continue;
298 298
 			}
299
-			foreach ( $claim['qualifiers'] as $qualsInfo ) {
300
-				foreach ( $qualsInfo as $qualInfo ) {
301
-					$qualProp = self::factory( $qualInfo['property'], $this->lang, $this->cache );
299
+			foreach ($claim['qualifiers'] as $qualsInfo) {
300
+				foreach ($qualsInfo as $qualInfo) {
301
+					$qualProp = self::factory($qualInfo['property'], $this->lang, $this->cache);
302 302
 					$propLabel = $qualProp->getLabel();
303
-					if ( !isset( $qualifiers[$propLabel] ) ) {
303
+					if (!isset($qualifiers[$propLabel])) {
304 304
 						$qualifiers[$propLabel] = [];
305 305
 					}
306 306
 					$qualifiers[$propLabel][] = $qualInfo['datavalue']['value'];
@@ -320,17 +320,17 @@  discard block
 block discarded – undo
320 320
 	 * @param string $property One of the PROP_* constants.
321 321
 	 * @return string|bool The value, or false if it can't be found.
322 322
 	 */
323
-	public function getPropertyOfTypeText( $property ) {
324
-		$entity = $this->getEntity( $this->id );
325
-		if ( isset( $entity['claims'][$property] ) ) {
323
+	public function getPropertyOfTypeText($property) {
324
+		$entity = $this->getEntity($this->id);
325
+		if (isset($entity['claims'][$property])) {
326 326
 			// Use the first title.
327
-			foreach ( $entity['claims'][$property] as $t ) {
328
-				if ( !isset( $t['mainsnak']['datavalue']['value']['language'] ) ) {
329
-					var_dump( $t['mainsnak']['datavalue']['value'] );
327
+			foreach ($entity['claims'][$property] as $t) {
328
+				if (!isset($t['mainsnak']['datavalue']['value']['language'])) {
329
+					var_dump($t['mainsnak']['datavalue']['value']);
330 330
 					exit();
331 331
 				}
332
-				if ( $t['mainsnak']['datavalue']['value']['language'] == $this->lang
333
-					&& !empty( $t['mainsnak']['datavalue']['value']['text'] )
332
+				if ($t['mainsnak']['datavalue']['value']['language'] == $this->lang
333
+					&& !empty($t['mainsnak']['datavalue']['value']['text'])
334 334
 				) {
335 335
 					return $t['mainsnak']['datavalue']['value']['text'];
336 336
 				}
@@ -350,16 +350,16 @@  discard block
 block discarded – undo
350 350
 	 * @param string $property
351 351
 	 * @return mixed[]|bool If it's not false it's an array with 'amount', 'unit', etc.
352 352
 	 */
353
-	public function getPropertyOfTypeQuantity( $property ) {
353
+	public function getPropertyOfTypeQuantity($property) {
354 354
 		$quantities = [];
355
-		$entity = $this->getEntity( $this->id );
356
-		if ( !isset( $entity['claims'][$property] ) ) {
355
+		$entity = $this->getEntity($this->id);
356
+		if (!isset($entity['claims'][$property])) {
357 357
 			return false;
358 358
 		}
359
-		foreach ( $entity['claims'][$property] as $t ) {
359
+		foreach ($entity['claims'][$property] as $t) {
360 360
 			$quantity = $t['mainsnak']['datavalue']['value'];
361
-			$unitId = substr( $quantity['unit'], strlen( $this->wikidataUrlBase ) + 1 );
362
-			$quantity['unit'] = self::factory( $unitId, $this->lang, $this->cache );
361
+			$unitId = substr($quantity['unit'], strlen($this->wikidataUrlBase) + 1);
362
+			$quantity['unit'] = self::factory($unitId, $this->lang, $this->cache);
363 363
 			$quantities[] = $quantity;
364 364
 		}
365 365
 		return $quantities;
@@ -370,19 +370,19 @@  discard block
 block discarded – undo
370 370
 	 * @param string $property One of the PROP_* constants.
371 371
 	 * @param string $value The value.
372 372
 	 */
373
-	public function setPropertyOfTypeText( $property, $value ) {
373
+	public function setPropertyOfTypeText($property, $value) {
374 374
 		// First see if this property already exists, and that it is different from what's being set.
375
-		$entity = $this->getEntity( $this->id );
376
-		if ( !empty( $entity['claims'][$property] ) ) {
375
+		$entity = $this->getEntity($this->id);
376
+		if (!empty($entity['claims'][$property])) {
377 377
 			// Find this language's claim (if there is one).
378
-			foreach ( $entity['claims'][$property] as $claim ) {
379
-				if ( $claim['mainsnak']['datavalue']['value']['language'] == $this->lang ) {
378
+			foreach ($entity['claims'][$property] as $claim) {
379
+				if ($claim['mainsnak']['datavalue']['value']['language'] == $this->lang) {
380 380
 					// Modify this claim's text value.
381 381
 					$titleClaim = $claim;
382 382
 					$titleClaim['mainsnak']['datavalue']['value']['text'] = $value;
383 383
 					$setTitleParams = [
384 384
 						'action' => 'wbsetclaim',
385
-						'claim' => \GuzzleHttp\json_encode( $titleClaim ),
385
+						'claim' => \GuzzleHttp\json_encode($titleClaim),
386 386
 					];
387 387
 					continue;
388 388
 				}
@@ -390,22 +390,22 @@  discard block
 block discarded – undo
390 390
 		}
391 391
 
392 392
 		// If no claim was found (and modified) above, create a new claim.
393
-		if ( !isset( $setTitleParams ) ) {
393
+		if (!isset($setTitleParams)) {
394 394
 			$setTitleParams = [
395 395
 				'action' => 'wbcreateclaim',
396 396
 				'entity' => $this->getId(),
397 397
 				'property' => $property,
398 398
 				'snaktype' => 'value',
399
-				'value' => \GuzzleHttp\json_encode( [ 'text' => $value, 'language' => $this->lang ] ),
399
+				'value' => \GuzzleHttp\json_encode(['text' => $value, 'language' => $this->lang]),
400 400
 			];
401 401
 		}
402 402
 
403 403
 		// Save the property.
404 404
 		$wdWpOauth = new WdWpOauth();
405
-		$wdWpOauth->makeCall( $setTitleParams, true );
405
+		$wdWpOauth->makeCall($setTitleParams, true);
406 406
 
407 407
 		// Clear the cache.
408
-		$this->cache->deleteItem( $this->getEntityCacheKey( $this->id ) );
408
+		$this->cache->deleteItem($this->getEntityCacheKey($this->id));
409 409
 	}
410 410
 
411 411
 	/**
@@ -421,31 +421,31 @@  discard block
 block discarded – undo
421 421
 	 */
422 422
 	public function getWikipediaIntro() {
423 423
 		$cacheKey = 'wikipedia-intro-' . $this->id . $this->lang;
424
-		if ( $this->cache->hasItem( $cacheKey ) ) {
425
-			return $this->cache->getItem( $cacheKey )->get();
424
+		if ($this->cache->hasItem($cacheKey)) {
425
+			return $this->cache->getItem($cacheKey)->get();
426 426
 		}
427
-		$entity = $this->getEntity( $this->id );
428
-		if ( !isset( $entity['sitelinks'] ) ) {
427
+		$entity = $this->getEntity($this->id);
428
+		if (!isset($entity['sitelinks'])) {
429 429
 			return [];
430 430
 		}
431
-		foreach ( $entity['sitelinks'] as $sitelink ) {
432
-			if ( $sitelink['site'] == $this->lang . 'wiki' ) {
433
-				$api = new MediawikiApi( 'https://' . $this->lang . '.wikipedia.org/w/api.php' );
434
-				$req = new SimpleRequest( 'query', [
431
+		foreach ($entity['sitelinks'] as $sitelink) {
432
+			if ($sitelink['site'] == $this->lang . 'wiki') {
433
+				$api = new MediawikiApi('https://' . $this->lang . '.wikipedia.org/w/api.php');
434
+				$req = new SimpleRequest('query', [
435 435
 					'prop' => 'extracts',
436 436
 					'exintro' => true,
437 437
 					'titles' => $sitelink['title'],
438
-				] );
439
-				$response = $api->getRequest( $req );
440
-				$page = array_shift( $response['query']['pages'] );
438
+				]);
439
+				$response = $api->getRequest($req);
440
+				$page = array_shift($response['query']['pages']);
441 441
 				$out = [
442 442
 					'title' => $page['title'],
443 443
 					'html' => $page['extract'],
444 444
 				];
445
-				$cacheItem = $this->cache->getItem( $cacheKey )
446
-					->expiresAfter( new DateInterval( 'P1D' ) )
447
-					->set( $out );
448
-				$this->cache->save( $cacheItem );
445
+				$cacheItem = $this->cache->getItem($cacheKey)
446
+					->expiresAfter(new DateInterval('P1D'))
447
+					->set($out);
448
+				$this->cache->save($cacheItem);
449 449
 
450 450
 				return $out;
451 451
 			}
@@ -460,22 +460,22 @@  discard block
 block discarded – undo
460 460
 	 * @param bool $ignoreCache
461 461
 	 * @return array|bool
462 462
 	 */
463
-	public function getEntity( $id = null, $ignoreCache = false ) {
463
+	public function getEntity($id = null, $ignoreCache = false) {
464 464
 		$idActual = $id ?: $this->id;
465
-		$cacheKey = $this->getEntityCacheKey( $idActual );
466
-		if ( !$ignoreCache && $this->cache->hasItem( $cacheKey ) ) {
467
-			return $this->cache->getItem( $cacheKey )->get();
465
+		$cacheKey = $this->getEntityCacheKey($idActual);
466
+		if (!$ignoreCache && $this->cache->hasItem($cacheKey)) {
467
+			return $this->cache->getItem($cacheKey)->get();
468 468
 		}
469
-		$metadataRequest = new SimpleRequest( 'wbgetentities', [ 'ids' => $idActual ] );
470
-		$itemResult = $this->wdApi->getRequest( $metadataRequest );
471
-		if ( !isset( $itemResult['success'] ) || !isset( $itemResult['entities'][$id] ) ) {
469
+		$metadataRequest = new SimpleRequest('wbgetentities', ['ids' => $idActual]);
470
+		$itemResult = $this->wdApi->getRequest($metadataRequest);
471
+		if (!isset($itemResult['success']) || !isset($itemResult['entities'][$id])) {
472 472
 			return false;
473 473
 		}
474 474
 		$metadata = $itemResult['entities'][$idActual];
475
-		$cacheItem = $this->cache->getItem( $cacheKey )
476
-			->expiresAfter( new DateInterval( 'PT10M' ) )
477
-			->set( $metadata );
478
-		$this->cache->save( $cacheItem );
475
+		$cacheItem = $this->cache->getItem($cacheKey)
476
+			->expiresAfter(new DateInterval('PT10M'))
477
+			->set($metadata);
478
+		$this->cache->save($cacheItem);
479 479
 		return $metadata;
480 480
 	}
481 481
 
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 	 *
485 485
 	 * @return string
486 486
 	 */
487
-	protected function getEntityCacheKey( $id ) {
487
+	protected function getEntityCacheKey($id) {
488 488
 		return 'entities' . $id;
489 489
 	}
490 490
 }
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
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 * @param string $lang The language code.
21 21
 	 * @param CacheItemPoolInterface $cache
22 22
 	 */
23
-	public function __construct( array $claim, $lang, CacheItemPoolInterface $cache ) {
23
+	public function __construct(array $claim, $lang, CacheItemPoolInterface $cache) {
24 24
 		$this->claim = $claim;
25 25
 		$this->lang = $lang;
26 26
 		$this->cache = $cache;
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	public function getReferences() {
33 33
 		$references = [];
34
-		if ( !isset( $this->claim['references'] ) ) {
34
+		if (!isset($this->claim['references'])) {
35 35
 			return $references;
36 36
 		}
37
-		foreach ( $this->claim['references'] as $ref ) {
38
-			$references[] = new Reference( $ref, $this->lang, $this->cache );
37
+		foreach ($this->claim['references'] as $ref) {
38
+			$references[] = new Reference($ref, $this->lang, $this->cache);
39 39
 		}
40 40
 		return $references;
41 41
 	}
Please login to merge, or discard this patch.
src/Items/Work.php 1 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 Edition && $b instanceof Edition ) {
91
+		usort($editions, function(Item $a, Item $b) {
92
+			if ($a instanceof Edition && $b instanceof Edition) {
93 93
 				return $a->getPublicationYear() - $b->getPublicationYear();
94 94
 			}
95 95
 			return 0;
Please login to merge, or discard this patch.