Completed
Push — master ( 17657a...f01a3a )
by
unknown
08:59
created
src/ConstraintCheck/Helper/SparqlHelper.php 1 patch
Spacing   +130 added lines, -132 removed lines patch added patch discarded remove patch
@@ -91,18 +91,18 @@  discard block
 block discarded – undo
91 91
 		$this->cache = $cache;
92 92
 		$this->dataFactory = $dataFactory;
93 93
 
94
-		$this->entityPrefix = $rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY );
94
+		$this->entityPrefix = $rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY);
95 95
 		$this->prefixes = <<<EOT
96
-PREFIX wd: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY )}>
97
-PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}>
98
-PREFIX wdt: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_DIRECT_CLAIM )}>
99
-PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>
100
-PREFIX p: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM )}>
101
-PREFIX ps: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM_STATEMENT )}>
102
-PREFIX pq: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER )}>
103
-PREFIX pqv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER_VALUE )}>
104
-PREFIX pr: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE )}>
105
-PREFIX prv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE_VALUE )}>
96
+PREFIX wd: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY)}>
97
+PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}>
98
+PREFIX wdt: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_DIRECT_CLAIM)}>
99
+PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>
100
+PREFIX p: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM)}>
101
+PREFIX ps: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM_STATEMENT)}>
102
+PREFIX pq: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER)}>
103
+PREFIX pqv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER_VALUE)}>
104
+PREFIX pr: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE)}>
105
+PREFIX prv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE_VALUE)}>
106 106
 PREFIX wikibase: <http://wikiba.se/ontology#>
107 107
 PREFIX wikibase-beta: <http://wikiba.se/ontology-beta#>
108 108
 EOT;
@@ -117,21 +117,21 @@  discard block
 block discarded – undo
117 117
 	 * @return CachedBool
118 118
 	 * @throws SparqlHelperException if the query times out or some other error occurs
119 119
 	 */
120
-	public function hasType( $id, array $classes, $withInstance ) {
121
-		$instanceOfId = $this->config->get( 'WBQualityConstraintsInstanceOfId' );
122
-		$subclassOfId = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
120
+	public function hasType($id, array $classes, $withInstance) {
121
+		$instanceOfId = $this->config->get('WBQualityConstraintsInstanceOfId');
122
+		$subclassOfId = $this->config->get('WBQualityConstraintsSubclassOfId');
123 123
 
124
-		$path = ( $withInstance ? "wdt:$instanceOfId/" : "" ) . "wdt:$subclassOfId*";
124
+		$path = ($withInstance ? "wdt:$instanceOfId/" : "")."wdt:$subclassOfId*";
125 125
 
126 126
 		$metadatas = [];
127 127
 
128
-		foreach ( array_chunk( $classes, 20 ) as $classesChunk ) {
129
-			$classesValues = implode( ' ', array_map(
130
-				function( $class ) {
131
-					return 'wd:' . $class;
128
+		foreach (array_chunk($classes, 20) as $classesChunk) {
129
+			$classesValues = implode(' ', array_map(
130
+				function($class) {
131
+					return 'wd:'.$class;
132 132
 				},
133 133
 				$classesChunk
134
-			) );
134
+			));
135 135
 
136 136
 			$query = <<<EOF
137 137
 ASK {
@@ -142,19 +142,19 @@  discard block
 block discarded – undo
142 142
 EOF;
143 143
 			// TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually
144 144
 
145
-			$result = $this->runQuery( $query );
145
+			$result = $this->runQuery($query);
146 146
 			$metadatas[] = $result->getMetadata();
147
-			if ( $result->getArray()['boolean'] ) {
147
+			if ($result->getArray()['boolean']) {
148 148
 				return new CachedBool(
149 149
 					true,
150
-					Metadata::merge( $metadatas )
150
+					Metadata::merge($metadatas)
151 151
 				);
152 152
 			}
153 153
 		}
154 154
 
155 155
 		return new CachedBool(
156 156
 			false,
157
-			Metadata::merge( $metadatas )
157
+			Metadata::merge($metadatas)
158 158
 		);
159 159
 	}
160 160
 
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
 		$ignoreDeprecatedStatements
171 171
 	) {
172 172
 		$pid = $statement->getPropertyId()->serialize();
173
-		$guid = str_replace( '$', '-', $statement->getGuid() );
173
+		$guid = str_replace('$', '-', $statement->getGuid());
174 174
 
175 175
 		$deprecatedFilter = '';
176
-		if ( $ignoreDeprecatedStatements ) {
176
+		if ($ignoreDeprecatedStatements) {
177 177
 			$deprecatedFilter .= 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }';
178 178
 			$deprecatedFilter .= 'MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }';
179 179
 		}
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
 LIMIT 10
194 194
 EOF;
195 195
 
196
-		$result = $this->runQuery( $query );
196
+		$result = $this->runQuery($query);
197 197
 
198
-		return $this->getOtherEntities( $result );
198
+		return $this->getOtherEntities($result);
199 199
 	}
200 200
 
201 201
 	/**
@@ -220,16 +220,15 @@  discard block
 block discarded – undo
220 220
 		$dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty(
221 221
 			$snak->getPropertyId()
222 222
 		);
223
-		list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue );
224
-		if ( $isFullValue ) {
223
+		list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue);
224
+		if ($isFullValue) {
225 225
 			$prefix .= 'v';
226 226
 		}
227 227
 		$path = $type === Context::TYPE_QUALIFIER ?
228
-			"$prefix:$pid" :
229
-			"prov:wasDerivedFrom/$prefix:$pid";
228
+			"$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid";
230 229
 
231 230
 		$deprecatedFilter = '';
232
-		if ( $ignoreDeprecatedStatements ) {
231
+		if ($ignoreDeprecatedStatements) {
233 232
 			$deprecatedFilter = <<< EOF
234 233
   MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }
235 234
   MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }
@@ -250,9 +249,9 @@  discard block
 block discarded – undo
250 249
 LIMIT 10
251 250
 EOF;
252 251
 
253
-		$result = $this->runQuery( $query );
252
+		$result = $this->runQuery($query);
254 253
 
255
-		return $this->getOtherEntities( $result );
254
+		return $this->getOtherEntities($result);
256 255
 	}
257 256
 
258 257
 	/**
@@ -262,8 +261,8 @@  discard block
 block discarded – undo
262 261
 	 *
263 262
 	 * @return string
264 263
 	 */
265
-	private function stringLiteral( $text ) {
266
-		return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"';
264
+	private function stringLiteral($text) {
265
+		return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"';
267 266
 	}
268 267
 
269 268
 	/**
@@ -273,17 +272,17 @@  discard block
 block discarded – undo
273 272
 	 *
274 273
 	 * @return CachedEntityIds
275 274
 	 */
276
-	private function getOtherEntities( CachedQueryResults $results ) {
277
-		return new CachedEntityIds( array_map(
278
-			function ( $resultBindings ) {
275
+	private function getOtherEntities(CachedQueryResults $results) {
276
+		return new CachedEntityIds(array_map(
277
+			function($resultBindings) {
279 278
 				$entityIRI = $resultBindings['otherEntity']['value'];
280
-				$entityPrefixLength = strlen( $this->entityPrefix );
281
-				if ( substr( $entityIRI, 0, $entityPrefixLength ) === $this->entityPrefix ) {
279
+				$entityPrefixLength = strlen($this->entityPrefix);
280
+				if (substr($entityIRI, 0, $entityPrefixLength) === $this->entityPrefix) {
282 281
 					try {
283 282
 						return $this->entityIdParser->parse(
284
-							substr( $entityIRI, $entityPrefixLength )
283
+							substr($entityIRI, $entityPrefixLength)
285 284
 						);
286
-					} catch ( EntityIdParsingException $e ) {
285
+					} catch (EntityIdParsingException $e) {
287 286
 						// fall through
288 287
 					}
289 288
 				}
@@ -291,7 +290,7 @@  discard block
 block discarded – undo
291 290
 				return null;
292 291
 			},
293 292
 			$results->getArray()['results']['bindings']
294
-		), $results->getMetadata() );
293
+		), $results->getMetadata());
295 294
 	}
296 295
 
297 296
 	// @codingStandardsIgnoreStart cyclomatic complexity of this function is too high
@@ -304,47 +303,47 @@  discard block
 block discarded – undo
304 303
 	 * @return array the literal or IRI as a string in SPARQL syntax,
305 304
 	 * and a boolean indicating whether it refers to a full value node or not
306 305
 	 */
307
-	private function getRdfLiteral( $dataType, DataValue $dataValue ) {
308
-		switch ( $dataType ) {
306
+	private function getRdfLiteral($dataType, DataValue $dataValue) {
307
+		switch ($dataType) {
309 308
 			case 'string':
310 309
 			case 'external-id':
311
-				return [ $this->stringLiteral( $dataValue->getValue() ), false ];
310
+				return [$this->stringLiteral($dataValue->getValue()), false];
312 311
 			case 'commonsMedia':
313
-				$url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() );
314
-				return [ '<' . $url . '>', false ];
312
+				$url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue());
313
+				return ['<'.$url.'>', false];
315 314
 			case 'geo-shape':
316
-				$url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() );
317
-				return [ '<' . $url . '>', false ];
315
+				$url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue());
316
+				return ['<'.$url.'>', false];
318 317
 			case 'tabular-data':
319
-				$url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() );
320
-				return [ '<' . $url . '>', false ];
318
+				$url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue());
319
+				return ['<'.$url.'>', false];
321 320
 			case 'url':
322 321
 				$url = $dataValue->getValue();
323
-				if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) {
322
+				if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) {
324 323
 					// not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF)
325 324
 					// such an URL should never reach us, so just throw
326
-					throw new InvalidArgumentException( 'invalid URL: ' . $url );
325
+					throw new InvalidArgumentException('invalid URL: '.$url);
327 326
 				}
328
-				return [ '<' . $url . '>', false ];
327
+				return ['<'.$url.'>', false];
329 328
 			case 'wikibase-item':
330 329
 			case 'wikibase-property':
331 330
 				/** @var EntityIdValue $dataValue */
332
-				return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ];
331
+				return ['wd:'.$dataValue->getEntityId()->getSerialization(), false];
333 332
 			case 'monolingualtext':
334 333
 				/** @var MonolingualTextValue $dataValue */
335 334
 				$lang = $dataValue->getLanguageCode();
336
-				if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) {
335
+				if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) {
337 336
 					// not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG)
338 337
 					// such a language tag should never reach us, so just throw
339
-					throw new InvalidArgumentException( 'invalid language tag: ' . $lang );
338
+					throw new InvalidArgumentException('invalid language tag: '.$lang);
340 339
 				}
341
-				return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ];
340
+				return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false];
342 341
 			case 'globe-coordinate':
343 342
 			case 'quantity':
344 343
 			case 'time':
345
-				return [ 'wdv:' . $dataValue->getHash(), true ];
344
+				return ['wdv:'.$dataValue->getHash(), true];
346 345
 			default:
347
-				throw new InvalidArgumentException( 'unknown data type: ' . $dataType );
346
+				throw new InvalidArgumentException('unknown data type: '.$dataType);
348 347
 		}
349 348
 	}
350 349
 	// @codingStandardsIgnoreEnd
@@ -357,47 +356,47 @@  discard block
 block discarded – undo
357 356
 	 * @throws SparqlHelperException if the query times out or some other error occurs
358 357
 	 * @throws ConstraintParameterException if the $regex is invalid
359 358
 	 */
360
-	public function matchesRegularExpression( $text, $regex ) {
359
+	public function matchesRegularExpression($text, $regex) {
361 360
 		// caching wrapper around matchesRegularExpressionWithSparql
362 361
 
363
-		$textHash = hash( 'sha256', $text );
362
+		$textHash = hash('sha256', $text);
364 363
 		$cacheKey = $this->cache->makeKey(
365 364
 			'WikibaseQualityConstraints', // extension
366 365
 			'regex', // action
367 366
 			'WDQS-Java', // regex flavor
368
-			hash( 'sha256', $regex )
367
+			hash('sha256', $regex)
369 368
 		);
370
-		$cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' );
369
+		$cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize');
371 370
 
372 371
 		$cacheMapArray = $this->cache->getWithSetCallback(
373 372
 			$cacheKey,
374 373
 			WANObjectCache::TTL_DAY,
375
-			function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) {
374
+			function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) {
376 375
 				// Initialize the cache map if not set
377
-				if ( $cacheMapArray === false ) {
376
+				if ($cacheMapArray === false) {
378 377
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.init';
379
-					$this->dataFactory->increment( $key );
378
+					$this->dataFactory->increment($key);
380 379
 					return [];
381 380
 				}
382 381
 
383 382
 				$key = 'wikibase.quality.constraints.regex.cache.refresh';
384
-				$this->dataFactory->increment( $key );
385
-				$cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize );
386
-				if ( $cacheMap->has( $textHash ) ) {
383
+				$this->dataFactory->increment($key);
384
+				$cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize);
385
+				if ($cacheMap->has($textHash)) {
387 386
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.hit';
388
-					$this->dataFactory->increment( $key );
389
-					$cacheMap->get( $textHash ); // ping cache
387
+					$this->dataFactory->increment($key);
388
+					$cacheMap->get($textHash); // ping cache
390 389
 				} else {
391 390
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.miss';
392
-					$this->dataFactory->increment( $key );
391
+					$this->dataFactory->increment($key);
393 392
 					try {
394
-						$matches = $this->matchesRegularExpressionWithSparql( $text, $regex );
395
-					} catch ( ConstraintParameterException $e ) {
393
+						$matches = $this->matchesRegularExpressionWithSparql($text, $regex);
394
+					} catch (ConstraintParameterException $e) {
396 395
 						$matches = [
397 396
 							'type' => ConstraintParameterException::class,
398 397
 							'message' => $e->getMessage(),
399 398
 						];
400
-					} catch ( SparqlHelperException $e ) {
399
+					} catch (SparqlHelperException $e) {
401 400
 						// don’t cache this
402 401
 						return $cacheMap->toArray();
403 402
 					}
@@ -421,27 +420,27 @@  discard block
 block discarded – undo
421 420
 			]
422 421
 		);
423 422
 
424
-		if ( isset( $cacheMapArray[$textHash] ) ) {
423
+		if (isset($cacheMapArray[$textHash])) {
425 424
 			$key = 'wikibase.quality.constraints.regex.cache.hit';
426
-			$this->dataFactory->increment( $key );
425
+			$this->dataFactory->increment($key);
427 426
 			$matches = $cacheMapArray[$textHash];
428
-			if ( is_bool( $matches ) ) {
427
+			if (is_bool($matches)) {
429 428
 				return $matches;
430
-			} elseif ( is_array( $matches ) &&
431
-				$matches['type'] == ConstraintParameterException::class ) {
432
-				throw new ConstraintParameterException( $matches['message'] );
429
+			} elseif (is_array($matches) &&
430
+				$matches['type'] == ConstraintParameterException::class) {
431
+				throw new ConstraintParameterException($matches['message']);
433 432
 			} else {
434 433
 				throw new MWException(
435
-					'Value of unknown type in object cache (' .
436
-					'cache key: ' . $cacheKey . ', ' .
437
-					'cache map key: ' . $textHash . ', ' .
438
-					'value type: ' . gettype( $matches ) . ')'
434
+					'Value of unknown type in object cache ('.
435
+					'cache key: '.$cacheKey.', '.
436
+					'cache map key: '.$textHash.', '.
437
+					'value type: '.gettype($matches).')'
439 438
 				);
440 439
 			}
441 440
 		} else {
442 441
 			$key = 'wikibase.quality.constraints.regex.cache.miss';
443
-			$this->dataFactory->increment( $key );
444
-			return $this->matchesRegularExpressionWithSparql( $text, $regex );
442
+			$this->dataFactory->increment($key);
443
+			return $this->matchesRegularExpressionWithSparql($text, $regex);
445 444
 		}
446 445
 	}
447 446
 
@@ -456,26 +455,26 @@  discard block
 block discarded – undo
456 455
 	 * @throws SparqlHelperException if the query times out or some other error occurs
457 456
 	 * @throws ConstraintParameterException if the $regex is invalid
458 457
 	 */
459
-	public function matchesRegularExpressionWithSparql( $text, $regex ) {
460
-		$textStringLiteral = $this->stringLiteral( $text );
461
-		$regexStringLiteral = $this->stringLiteral( '^' . $regex . '$' );
458
+	public function matchesRegularExpressionWithSparql($text, $regex) {
459
+		$textStringLiteral = $this->stringLiteral($text);
460
+		$regexStringLiteral = $this->stringLiteral('^'.$regex.'$');
462 461
 
463 462
 		$query = <<<EOF
464 463
 SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {}
465 464
 EOF;
466 465
 
467
-		$result = $this->runQuery( $query );
466
+		$result = $this->runQuery($query);
468 467
 
469 468
 		$vars = $result->getArray()['results']['bindings'][0];
470
-		if ( array_key_exists( 'matches', $vars ) ) {
469
+		if (array_key_exists('matches', $vars)) {
471 470
 			// true or false ⇒ regex okay, text matches or not
472 471
 			return $vars['matches']['value'] === 'true';
473 472
 		} else {
474 473
 			// empty result: regex broken
475 474
 			throw new ConstraintParameterException(
476
-				wfMessage( 'wbqc-violation-message-parameter-regex' )
477
-					->rawParams( ConstraintParameterRenderer::formatByRole( Role::CONSTRAINT_PARAMETER_VALUE,
478
-						'<code><nowiki>' . htmlspecialchars( $regex ) . '</nowiki></code>' ) )
475
+				wfMessage('wbqc-violation-message-parameter-regex')
476
+					->rawParams(ConstraintParameterRenderer::formatByRole(Role::CONSTRAINT_PARAMETER_VALUE,
477
+						'<code><nowiki>'.htmlspecialchars($regex).'</nowiki></code>'))
479 478
 					->escaped()
480 479
 			);
481 480
 		}
@@ -488,14 +487,14 @@  discard block
 block discarded – undo
488 487
 	 *
489 488
 	 * @return boolean
490 489
 	 */
491
-	public function isTimeout( $responseContent ) {
492
-		$timeoutRegex = implode( '|', array_map(
493
-			function ( $fqn ) {
494
-				return preg_quote( $fqn, '/' );
490
+	public function isTimeout($responseContent) {
491
+		$timeoutRegex = implode('|', array_map(
492
+			function($fqn) {
493
+				return preg_quote($fqn, '/');
495 494
 			},
496
-			$this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' )
497
-		) );
498
-		return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent );
495
+			$this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses')
496
+		));
497
+		return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent);
499 498
 	}
500 499
 
501 500
 	/**
@@ -507,17 +506,17 @@  discard block
 block discarded – undo
507 506
 	 * @return integer|boolean the max-age (in seconds)
508 507
 	 * or a plain boolean if no max-age can be determined
509 508
 	 */
510
-	public function getCacheMaxAge( $responseHeaders ) {
509
+	public function getCacheMaxAge($responseHeaders) {
511 510
 		if (
512
-			array_key_exists( 'x-cache-status', $responseHeaders ) &&
513
-			preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] )
511
+			array_key_exists('x-cache-status', $responseHeaders) &&
512
+			preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0])
514 513
 		) {
515 514
 			$maxage = [];
516 515
 			if (
517
-				array_key_exists( 'cache-control', $responseHeaders ) &&
518
-				preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage )
516
+				array_key_exists('cache-control', $responseHeaders) &&
517
+				preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage)
519 518
 			) {
520
-				return intval( $maxage[1] );
519
+				return intval($maxage[1]);
521 520
 			} else {
522 521
 				return true;
523 522
 			}
@@ -535,59 +534,58 @@  discard block
 block discarded – undo
535 534
 	 *
536 535
 	 * @throws SparqlHelperException if the query times out or some other error occurs
537 536
 	 */
538
-	public function runQuery( $query ) {
537
+	public function runQuery($query) {
539 538
 
540
-		$endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' );
541
-		$maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' );
542
-		$url = $endpoint . '?' . http_build_query(
539
+		$endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint');
540
+		$maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis');
541
+		$url = $endpoint.'?'.http_build_query(
543 542
 			[
544
-				'query' => "#wbqc\n" . $this->prefixes . $query,
543
+				'query' => "#wbqc\n".$this->prefixes.$query,
545 544
 				'format' => 'json',
546 545
 				'maxQueryTimeMillis' => $maxQueryTimeMillis,
547 546
 			],
548
-			null, ini_get( 'arg_separator.output' ),
547
+			null, ini_get('arg_separator.output'),
549 548
 			// encode spaces with %20, not +
550 549
 			PHP_QUERY_RFC3986
551 550
 		);
552 551
 
553 552
 		$options = [
554 553
 			'method' => 'GET',
555
-			'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ),
554
+			'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000),
556 555
 			'connectTimeout' => 'default',
557 556
 		];
558
-		$request = MWHttpRequest::factory( $url, $options );
559
-		$startTime = microtime( true );
557
+		$request = MWHttpRequest::factory($url, $options);
558
+		$startTime = microtime(true);
560 559
 		$status = $request->execute();
561
-		$endTime = microtime( true );
560
+		$endTime = microtime(true);
562 561
 		$this->dataFactory->timing(
563 562
 			'wikibase.quality.constraints.sparql.timing',
564
-			( $endTime - $startTime ) * 1000
563
+			($endTime - $startTime) * 1000
565 564
 		);
566 565
 
567
-		$maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() );
568
-		if ( $maxAge ) {
569
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' );
566
+		$maxAge = $this->getCacheMaxAge($request->getResponseHeaders());
567
+		if ($maxAge) {
568
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.cached');
570 569
 		}
571 570
 
572
-		if ( $status->isOK() ) {
571
+		if ($status->isOK()) {
573 572
 			$json = $request->getContent();
574
-			$arr = json_decode( $json, true );
573
+			$arr = json_decode($json, true);
575 574
 			return new CachedQueryResults(
576 575
 				$arr,
577 576
 				Metadata::ofCachingMetadata(
578 577
 					$maxAge ?
579
-						CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) :
580
-						CachingMetadata::fresh()
578
+						CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh()
581 579
 				)
582 580
 			);
583 581
 		} else {
584
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' );
582
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.error');
585 583
 
586 584
 			$this->dataFactory->increment(
587 585
 				"wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}"
588 586
 			);
589 587
 
590
-			if ( $this->isTimeout( $request->getContent() ) ) {
588
+			if ($this->isTimeout($request->getContent())) {
591 589
 				$this->dataFactory->increment(
592 590
 					'wikibase.quality.constraints.sparql.error.timeout'
593 591
 				);
Please login to merge, or discard this patch.
src/ConstraintCheck/Context/AbstractContext.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
 	 */
24 24
 	protected $snak;
25 25
 
26
-	public function __construct( EntityDocument $entity, Snak $snak ) {
26
+	public function __construct(EntityDocument $entity, Snak $snak) {
27 27
 		$this->entity = $entity;
28 28
 		$this->snak = $snak;
29 29
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Context/QualifierContext.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 		Statement $statement,
24 24
 		Snak $snak
25 25
 	) {
26
-		parent::__construct( $entity, $snak );
26
+		parent::__construct($entity, $snak);
27 27
 		$this->statement = $statement;
28 28
 	}
29 29
 
@@ -33,10 +33,10 @@  discard block
 block discarded – undo
33 33
 
34 34
 	public function getSnakGroup() {
35 35
 		$snaks = $this->statement->getQualifiers();
36
-		return array_values( $snaks->getArrayCopy() );
36
+		return array_values($snaks->getArrayCopy());
37 37
 	}
38 38
 
39
-	protected function &getMainArray( array &$container ) {
39
+	protected function &getMainArray(array &$container) {
40 40
 		$statementArray = &$this->getStatementArray(
41 41
 			$container,
42 42
 			$this->entity->getId()->getSerialization(),
@@ -44,25 +44,25 @@  discard block
 block discarded – undo
44 44
 			$this->statement->getGuid()
45 45
 		);
46 46
 
47
-		if ( !array_key_exists( 'qualifiers', $statementArray ) ) {
47
+		if (!array_key_exists('qualifiers', $statementArray)) {
48 48
 			$statementArray['qualifiers'] = [];
49 49
 		}
50 50
 		$qualifiersArray = &$statementArray['qualifiers'];
51 51
 
52 52
 		$propertyId = $this->getSnak()->getPropertyId()->getSerialization();
53
-		if ( !array_key_exists( $propertyId, $qualifiersArray ) ) {
53
+		if (!array_key_exists($propertyId, $qualifiersArray)) {
54 54
 			$qualifiersArray[$propertyId] = [];
55 55
 		}
56 56
 		$propertyArray = &$qualifiersArray[$propertyId];
57 57
 
58
-		foreach ( $propertyArray as &$potentialQualifierArray ) {
59
-			if ( $potentialQualifierArray['hash'] === $this->getSnak()->getHash() ) {
58
+		foreach ($propertyArray as &$potentialQualifierArray) {
59
+			if ($potentialQualifierArray['hash'] === $this->getSnak()->getHash()) {
60 60
 				$qualifierArray = &$potentialQualifierArray;
61 61
 				break;
62 62
 			}
63 63
 		}
64
-		if ( !isset( $qualifierArray ) ) {
65
-			$qualifierArray = [ 'hash' => $this->getSnak()->getHash() ];
64
+		if (!isset($qualifierArray)) {
65
+			$qualifierArray = ['hash' => $this->getSnak()->getHash()];
66 66
 			$propertyArray[] = &$qualifierArray;
67 67
 		}
68 68
 
Please login to merge, or discard this patch.
src/ConstraintCheck/Context/ReferenceContext.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 		Reference $reference,
31 31
 		Snak $snak
32 32
 	) {
33
-		parent::__construct( $entity, $snak );
33
+		parent::__construct($entity, $snak);
34 34
 		$this->statement = $statement;
35 35
 		$this->reference = $reference;
36 36
 	}
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
 
42 42
 	public function getSnakGroup() {
43 43
 		$snaks = $this->reference->getSnaks();
44
-		return array_values( $snaks->getArrayCopy() );
44
+		return array_values($snaks->getArrayCopy());
45 45
 	}
46 46
 
47
-	protected function &getMainArray( array &$container ) {
47
+	protected function &getMainArray(array &$container) {
48 48
 		$statementArray = &$this->getStatementArray(
49 49
 			$container,
50 50
 			$this->entity->getId()->getSerialization(),
@@ -52,38 +52,38 @@  discard block
 block discarded – undo
52 52
 			$this->statement->getGuid()
53 53
 		);
54 54
 
55
-		if ( !array_key_exists( 'references', $statementArray ) ) {
55
+		if (!array_key_exists('references', $statementArray)) {
56 56
 			$statementArray['references'] = [];
57 57
 		}
58 58
 		$referencesArray = &$statementArray['references'];
59 59
 
60
-		foreach ( $referencesArray as &$potentialReferenceArray ) {
61
-			if ( $potentialReferenceArray['hash'] === $this->reference->getHash() ) {
60
+		foreach ($referencesArray as &$potentialReferenceArray) {
61
+			if ($potentialReferenceArray['hash'] === $this->reference->getHash()) {
62 62
 				$referenceArray = &$potentialReferenceArray;
63 63
 				break;
64 64
 			}
65 65
 		}
66
-		if ( !isset( $referenceArray ) ) {
67
-			$referenceArray = [ 'hash' => $this->reference->getHash(), 'snaks' => [] ];
66
+		if (!isset($referenceArray)) {
67
+			$referenceArray = ['hash' => $this->reference->getHash(), 'snaks' => []];
68 68
 			$referencesArray[] = &$referenceArray;
69 69
 		}
70 70
 
71 71
 		$snaksArray = &$referenceArray['snaks'];
72 72
 
73 73
 		$propertyId = $this->getSnak()->getPropertyId()->getSerialization();
74
-		if ( !array_key_exists( $propertyId, $snaksArray ) ) {
74
+		if (!array_key_exists($propertyId, $snaksArray)) {
75 75
 			$snaksArray[$propertyId] = [];
76 76
 		}
77 77
 		$propertyArray = &$snaksArray[$propertyId];
78 78
 
79
-		foreach ( $propertyArray as &$potentialSnakArray ) {
80
-			if ( $potentialSnakArray['hash'] === $this->getSnak()->getHash() ) {
79
+		foreach ($propertyArray as &$potentialSnakArray) {
80
+			if ($potentialSnakArray['hash'] === $this->getSnak()->getHash()) {
81 81
 				$snakArray = &$potentialSnakArray;
82 82
 				break;
83 83
 			}
84 84
 		}
85
-		if ( !isset( $snakArray ) ) {
86
-			$snakArray = [ 'hash' => $this->getSnak()->getHash() ];
85
+		if (!isset($snakArray)) {
86
+			$snakArray = ['hash' => $this->getSnak()->getHash()];
87 87
 			$propertyArray[] = &$snakArray;
88 88
 		}
89 89
 
Please login to merge, or discard this patch.
src/ConstraintCheck/Context/MainSnakContext.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -20,9 +20,9 @@  discard block
 block discarded – undo
20 20
 	 */
21 21
 	private $statement;
22 22
 
23
-	public function __construct( EntityDocument $entity, Statement $statement ) {
24
-		Assert::parameterType( StatementListProvider::class, $entity, '$entity' );
25
-		parent::__construct( $entity, $statement->getMainSnak() );
23
+	public function __construct(EntityDocument $entity, Statement $statement) {
24
+		Assert::parameterType(StatementListProvider::class, $entity, '$entity');
25
+		parent::__construct($entity, $statement->getMainSnak());
26 26
 
27 27
 		$this->statement = $statement;
28 28
 	}
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
 		/** @var StatementList $statements */
44 44
 		$statements = $this->entity->getStatements();
45 45
 		return $statements
46
-			->getByRank( [ Statement::RANK_NORMAL, Statement::RANK_PREFERRED ] )
46
+			->getByRank([Statement::RANK_NORMAL, Statement::RANK_PREFERRED])
47 47
 			->getMainSnaks();
48 48
 	}
49 49
 
50
-	protected function &getMainArray( array &$container ) {
50
+	protected function &getMainArray(array &$container) {
51 51
 		$statementArray = &$this->getStatementArray(
52 52
 			$container,
53 53
 			$this->entity->getId()->getSerialization(),
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 			$this->statement->getGuid()
56 56
 		);
57 57
 
58
-		if ( !array_key_exists( 'mainsnak', $statementArray ) ) {
59
-			$statementArray['mainsnak'] = [ 'hash' => $this->statement->getMainSnak()->getHash() ];
58
+		if (!array_key_exists('mainsnak', $statementArray)) {
59
+			$statementArray['mainsnak'] = ['hash' => $this->statement->getMainSnak()->getHash()];
60 60
 		}
61 61
 		$mainsnakArray = &$statementArray['mainsnak'];
62 62
 
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/ValueCountCheckerHelper.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,13 +20,13 @@
 block discarded – undo
20 20
 	 * @param PropertyId $propertyId
21 21
 	 * @return int
22 22
 	 */
23
-	public function getPropertyCount( array $snaks, PropertyId $propertyId ) {
24
-		return count( array_filter(
23
+	public function getPropertyCount(array $snaks, PropertyId $propertyId) {
24
+		return count(array_filter(
25 25
 			$snaks,
26
-			function ( Snak $snak ) use ( $propertyId ) {
27
-				return $snak->getPropertyId()->equals( $propertyId );
26
+			function(Snak $snak) use ($propertyId) {
27
+				return $snak->getPropertyId()->equals($propertyId);
28 28
 			}
29
-		) );
29
+		));
30 30
 	}
31 31
 
32 32
 }
Please login to merge, or discard this patch.
src/WikibaseQualityConstraintsHooks.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -30,36 +30,36 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @return bool
32 32
 	 */
33
-	public static function onCreateSchema( DatabaseUpdater $updater ) {
34
-		$updater->addExtensionTable( 'wbqc_constraints', __DIR__ . '/../sql/create_wbqc_constraints.sql' );
33
+	public static function onCreateSchema(DatabaseUpdater $updater) {
34
+		$updater->addExtensionTable('wbqc_constraints', __DIR__.'/../sql/create_wbqc_constraints.sql');
35 35
 		return true;
36 36
 	}
37 37
 
38
-	public static function onWikibaseChange( Change $change ) {
38
+	public static function onWikibaseChange(Change $change) {
39 39
 		$config = MediaWikiServices::getInstance()->getMainConfig();
40
-		if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) &&
41
-			self::isConstraintStatementsChange( $config, $change )
40
+		if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') &&
41
+			self::isConstraintStatementsChange($config, $change)
42 42
 		) {
43 43
 			/** @var EntityChange $change */
44 44
 			$title = Title::newMainPage();
45
-			$params = [ 'propertyId' => $change->getEntityId()->getSerialization() ];
45
+			$params = ['propertyId' => $change->getEntityId()->getSerialization()];
46 46
 			JobQueueGroup::singleton()->push(
47
-				new JobSpecification( 'constraintsTableUpdate', $params, [], $title )
47
+				new JobSpecification('constraintsTableUpdate', $params, [], $title)
48 48
 			);
49 49
 		}
50 50
 	}
51 51
 
52
-	public static function isConstraintStatementsChange( Config $config, Change $change ) {
53
-		if ( !( $change instanceof EntityChange ) ||
52
+	public static function isConstraintStatementsChange(Config $config, Change $change) {
53
+		if (!($change instanceof EntityChange) ||
54 54
 			 $change->getAction() !== EntityChange::UPDATE ||
55
-			 !( $change->getEntityId() instanceof PropertyId )
55
+			 !($change->getEntityId() instanceof PropertyId)
56 56
 		) {
57 57
 			return false;
58 58
 		}
59 59
 
60 60
 		$info = $change->getInfo();
61 61
 
62
-		if ( !array_key_exists( 'compactDiff', $info ) ) {
62
+		if (!array_key_exists('compactDiff', $info)) {
63 63
 			// the non-compact diff ($info['diff']) does not contain statement diffs (T110996),
64 64
 			// so we only know that the change *might* affect the constraint statements
65 65
 			return true;
@@ -68,18 +68,18 @@  discard block
 block discarded – undo
68 68
 		/** @var EntityDiffChangedAspects $aspects */
69 69
 		$aspects = $info['compactDiff'];
70 70
 
71
-		$propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' );
72
-		return in_array( $propertyConstraintId, $aspects->getStatementChanges() );
71
+		$propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId');
72
+		return in_array($propertyConstraintId, $aspects->getStatementChanges());
73 73
 	}
74 74
 
75
-	public static function onArticlePurge( WikiPage $wikiPage ) {
75
+	public static function onArticlePurge(WikiPage $wikiPage) {
76 76
 		$repo = WikibaseRepo::getDefaultInstance();
77 77
 
78 78
 		$entityContentFactory = $repo->getEntityContentFactory();
79
-		if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) {
80
-			$entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() );
79
+		if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) {
80
+			$entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle());
81 81
 			$resultsCache = ResultsCache::getDefaultInstance();
82
-			$resultsCache->delete( $entityId );
82
+			$resultsCache->delete($entityId);
83 83
 		}
84 84
 	}
85 85
 
@@ -88,18 +88,18 @@  discard block
 block discarded – undo
88 88
 	 * @param int $timestamp UTC timestamp (seconds since the Epoch)
89 89
 	 * @return bool
90 90
 	 */
91
-	public static function isGadgetEnabledForUserName( $userName, $timestamp ) {
91
+	public static function isGadgetEnabledForUserName($userName, $timestamp) {
92 92
 		$initial = $userName[0];
93 93
 
94
-		if ( $initial === 'Z' ) {
94
+		if ($initial === 'Z') {
95 95
 			$firstWeek = 0;
96
-		} elseif ( $initial >= 'W' && $initial < 'Z' ) {
96
+		} elseif ($initial >= 'W' && $initial < 'Z') {
97 97
 			$firstWeek = 1;
98
-		} elseif ( $initial >= 'T' && $initial < 'W' ) {
98
+		} elseif ($initial >= 'T' && $initial < 'W') {
99 99
 			$firstWeek = 2;
100
-		} elseif ( $initial >= 'N' && $initial < 'T' ) {
100
+		} elseif ($initial >= 'N' && $initial < 'T') {
101 101
 			$firstWeek = 3;
102
-		} elseif ( $initial >= 'E' && $initial < 'N' ) {
102
+		} elseif ($initial >= 'E' && $initial < 'N') {
103 103
 			$firstWeek = 4;
104 104
 		} else {
105 105
 			$firstWeek = 5;
@@ -117,27 +117,27 @@  discard block
 block discarded – undo
117 117
 		return $timestamp >= $threshold;
118 118
 	}
119 119
 
120
-	public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {
120
+	public static function onBeforePageDisplay(OutputPage &$out, Skin &$skin) {
121 121
 		$repo = WikibaseRepo::getDefaultInstance();
122 122
 
123 123
 		$lookup = $repo->getEntityNamespaceLookup();
124 124
 		$title = $out->getTitle();
125
-		if ( $title === null ) {
125
+		if ($title === null) {
126 126
 			return;
127 127
 		}
128 128
 
129
-		if ( !$lookup->isEntityNamespace( $title->getNamespace() ) ) {
129
+		if (!$lookup->isEntityNamespace($title->getNamespace())) {
130 130
 			return;
131 131
 		}
132
-		if ( !$out->getUser()->isLoggedIn() ) {
132
+		if (!$out->getUser()->isLoggedIn()) {
133 133
 			return;
134 134
 		}
135
-		if ( !$out->getJsConfigVars()['wbIsEditView'] ) {
135
+		if (!$out->getJsConfigVars()['wbIsEditView']) {
136 136
 			return;
137 137
 		}
138 138
 
139
-		if ( self::isGadgetEnabledForUserName( $out->getUser()->getName(), time() ) ) {
140
-			$out->addModules( 'wikibase.quality.constraints.gadget' );
139
+		if (self::isGadgetEnabledForUserName($out->getUser()->getName(), time())) {
140
+			$out->addModules('wikibase.quality.constraints.gadget');
141 141
 		}
142 142
 	}
143 143
 
Please login to merge, or discard this patch.
src/Api/ResultsCache.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -19,10 +19,10 @@  discard block
 block discarded – undo
19 19
 	private $cache;
20 20
 
21 21
 	public static function getDefaultInstance() {
22
-		return new self( MediaWikiServices::getInstance()->getMainWANObjectCache() );
22
+		return new self(MediaWikiServices::getInstance()->getMainWANObjectCache());
23 23
 	}
24 24
 
25
-	public function __construct( WANObjectCache $cache ) {
25
+	public function __construct(WANObjectCache $cache) {
26 26
 		$this->cache = $cache;
27 27
 	}
28 28
 
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
 	 * @param string|null $languageCode defaults to user language
32 32
 	 * @return string cache key
33 33
 	 */
34
-	public function makeKey( EntityId $entityId, $languageCode = null ) {
34
+	public function makeKey(EntityId $entityId, $languageCode = null) {
35 35
 		global $wgLang, $wgContLang;
36
-		if ( $languageCode === null ) {
36
+		if ($languageCode === null) {
37 37
 			$languageCode = $wgLang->getCode();
38 38
 		}
39
-		if ( !Language::isKnownLanguageTag( $languageCode ) && $languageCode !== 'qqx' ) {
39
+		if (!Language::isKnownLanguageTag($languageCode) && $languageCode !== 'qqx') {
40 40
 			$languageCode = $wgContLang->getCode();
41 41
 		}
42 42
 		return $this->cache->makeKey(
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 	 * @param float &$asOf
56 56
 	 * @return mixed
57 57
 	 */
58
-	public function get( EntityId $key, &$curTTL = null, array $checkKeys = [], &$asOf = null ) {
59
-		return $this->cache->get( $this->makeKey( $key ), $curTTL, $checkKeys, $asOf );
58
+	public function get(EntityId $key, &$curTTL = null, array $checkKeys = [], &$asOf = null) {
59
+		return $this->cache->get($this->makeKey($key), $curTTL, $checkKeys, $asOf);
60 60
 	}
61 61
 
62 62
 	/**
@@ -66,20 +66,20 @@  discard block
 block discarded – undo
66 66
 	 * @param array $opts
67 67
 	 * @return bool
68 68
 	 */
69
-	public function set( EntityId $key, $value, $ttl = 0, array $opts = [] ) {
70
-		return $this->cache->set( $this->makeKey( $key ), $value, $ttl, $opts );
69
+	public function set(EntityId $key, $value, $ttl = 0, array $opts = []) {
70
+		return $this->cache->set($this->makeKey($key), $value, $ttl, $opts);
71 71
 	}
72 72
 
73 73
 	/**
74 74
 	 * @param EntityId $key
75 75
 	 * @return bool
76 76
 	 */
77
-	public function delete( EntityId $key ) {
77
+	public function delete(EntityId $key) {
78 78
 		$ok = true;
79
-		$languageCodes = array_keys( Language::fetchLanguageNames( null, 'all' ) );
79
+		$languageCodes = array_keys(Language::fetchLanguageNames(null, 'all'));
80 80
 		$languageCodes[] = 'qqx';
81
-		foreach ( $languageCodes as $languageCode ) {
82
-			$ok = $this->cache->delete( $this->makeKey( $key, $languageCode ) ) && $ok;
81
+		foreach ($languageCodes as $languageCode) {
82
+			$ok = $this->cache->delete($this->makeKey($key, $languageCode)) && $ok;
83 83
 		}
84 84
 		return $ok;
85 85
 	}
Please login to merge, or discard this patch.
src/ConstraintRepository.php 1 patch
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -20,23 +20,23 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @return Constraint[]
22 22
 	 */
23
-	public function queryConstraintsForProperty( PropertyId $propertyId ) {
24
-		$db = wfGetDB( DB_REPLICA );
23
+	public function queryConstraintsForProperty(PropertyId $propertyId) {
24
+		$db = wfGetDB(DB_REPLICA);
25 25
 
26 26
 		$results = $db->select(
27 27
 			'wbqc_constraints',
28 28
 			'*',
29
-			[ 'pid' => $propertyId->getNumericId() ]
29
+			['pid' => $propertyId->getNumericId()]
30 30
 		);
31 31
 
32
-		return $this->convertToConstraints( $results );
32
+		return $this->convertToConstraints($results);
33 33
 	}
34 34
 
35
-	private function encodeConstraintParameters( array $constraintParameters ) {
36
-		$json = json_encode( $constraintParameters, JSON_FORCE_OBJECT );
35
+	private function encodeConstraintParameters(array $constraintParameters) {
36
+		$json = json_encode($constraintParameters, JSON_FORCE_OBJECT);
37 37
 
38
-		if ( strlen( $json ) > 50000 ) {
39
-			$json = json_encode( [ '@error' => [ 'toolong' => true ] ] );
38
+		if (strlen($json) > 50000) {
39
+			$json = json_encode(['@error' => ['toolong' => true]]);
40 40
 		}
41 41
 
42 42
 		return $json;
@@ -48,21 +48,21 @@  discard block
 block discarded – undo
48 48
 	 * @throws DBUnexpectedError
49 49
 	 * @return bool
50 50
 	 */
51
-	public function insertBatch( array $constraints ) {
51
+	public function insertBatch(array $constraints) {
52 52
 		$accumulator = array_map(
53
-			function ( Constraint $constraint ) {
53
+			function(Constraint $constraint) {
54 54
 				return [
55 55
 					'constraint_guid' => $constraint->getConstraintId(),
56 56
 					'pid' => $constraint->getPropertyId()->getNumericId(),
57 57
 					'constraint_type_qid' => $constraint->getConstraintTypeItemId(),
58
-					'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() )
58
+					'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters())
59 59
 				];
60 60
 			},
61 61
 			$constraints
62 62
 		);
63 63
 
64
-		$db = wfGetDB( DB_MASTER );
65
-		return $db->insert( 'wbqc_constraints', $accumulator );
64
+		$db = wfGetDB(DB_MASTER);
65
+		return $db->insert('wbqc_constraints', $accumulator);
66 66
 	}
67 67
 
68 68
 	/**
@@ -70,13 +70,13 @@  discard block
 block discarded – undo
70 70
 	 *
71 71
 	 * @return array
72 72
 	 */
73
-	private function uuidPattern( LikeMatch $any ) {
73
+	private function uuidPattern(LikeMatch $any) {
74 74
 		return array_merge(
75
-			array_fill( 0, 8, $any ), [ '-' ],
76
-			array_fill( 0, 4, $any ), [ '-' ],
77
-			array_fill( 0, 4, $any ), [ '-' ],
78
-			array_fill( 0, 4, $any ), [ '-' ],
79
-			array_fill( 0, 12, $any )
75
+			array_fill(0, 8, $any), ['-'],
76
+			array_fill(0, 4, $any), ['-'],
77
+			array_fill(0, 4, $any), ['-'],
78
+			array_fill(0, 4, $any), ['-'],
79
+			array_fill(0, 12, $any)
80 80
 		);
81 81
 	}
82 82
 
@@ -87,11 +87,11 @@  discard block
 block discarded – undo
87 87
 	 * @throws DBUnexpectedError
88 88
 	 */
89 89
 	public function deleteWhereConstraintIdIsUuid() {
90
-		$db = wfGetDB( DB_MASTER );
90
+		$db = wfGetDB(DB_MASTER);
91 91
 		$db->delete(
92 92
 			'wbqc_constraints',
93 93
 			// WHERE constraint_guid LIKE ________-____-____-____-____________
94
-			'constraint_guid ' . $db->buildLike( $this->uuidPattern( $db->anyChar() ) )
94
+			'constraint_guid '.$db->buildLike($this->uuidPattern($db->anyChar()))
95 95
 		);
96 96
 	}
97 97
 
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
 	 *
104 104
 	 * @throws DBUnexpectedError
105 105
 	 */
106
-	public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) {
107
-		$db = wfGetDB( DB_MASTER );
106
+	public function deleteForPropertyWhereConstraintIdIsStatementId(PropertyId $propertyId) {
107
+		$db = wfGetDB(DB_MASTER);
108 108
 		$db->delete(
109 109
 			'wbqc_constraints',
110 110
 			[
111 111
 				'pid' => $propertyId->getNumericId(),
112 112
 				// AND constraint_guid LIKE %$________-____-____-____-____________
113
-				'constraint_guid ' . $db->buildLike( array_merge( [ $db->anyString(), '$' ], $this->uuidPattern( $db->anyChar() ) ) )
113
+				'constraint_guid '.$db->buildLike(array_merge([$db->anyString(), '$'], $this->uuidPattern($db->anyChar())))
114 114
 			]
115 115
 		);
116 116
 	}
@@ -121,20 +121,20 @@  discard block
 block discarded – undo
121 121
 	 * @throws InvalidArgumentException
122 122
 	 * @throws DBUnexpectedError
123 123
 	 */
124
-	public function deleteAll( $batchSize = 1000 ) {
125
-		if ( !is_int( $batchSize ) ) {
124
+	public function deleteAll($batchSize = 1000) {
125
+		if (!is_int($batchSize)) {
126 126
 			throw new InvalidArgumentException();
127 127
 		}
128
-		$db = wfGetDB( DB_MASTER );
129
-		if ( $db->getType() === 'sqlite' ) {
130
-			$db->delete( 'wbqc_constraints', '*' );
128
+		$db = wfGetDB(DB_MASTER);
129
+		if ($db->getType() === 'sqlite') {
130
+			$db->delete('wbqc_constraints', '*');
131 131
 		} else {
132 132
 			do {
133
-				$db->commit( __METHOD__, 'flush' );
133
+				$db->commit(__METHOD__, 'flush');
134 134
 				wfGetLBFactory()->waitForReplication();
135
-				$table = $db->tableName( 'wbqc_constraints' );
136
-				$db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) );
137
-			} while ( $db->affectedRows() > 0 );
135
+				$table = $db->tableName('wbqc_constraints');
136
+				$db->query(sprintf('DELETE FROM %s LIMIT %d', $table, $batchSize));
137
+			} while ($db->affectedRows() > 0);
138 138
 		}
139 139
 	}
140 140
 
@@ -143,26 +143,26 @@  discard block
 block discarded – undo
143 143
 	 *
144 144
 	 * @return Constraint[]
145 145
 	 */
146
-	private function convertToConstraints( IResultWrapper $results ) {
146
+	private function convertToConstraints(IResultWrapper $results) {
147 147
 		$constraints = [];
148
-		foreach ( $results as $result ) {
148
+		foreach ($results as $result) {
149 149
 			$constraintTypeItemId = $result->constraint_type_qid;
150
-			$constraintParameters = json_decode( $result->constraint_parameters, true );
150
+			$constraintParameters = json_decode($result->constraint_parameters, true);
151 151
 
152
-			if ( $constraintParameters === null ) {
152
+			if ($constraintParameters === null) {
153 153
 				// T171295
154
-				LoggerFactory::getInstance( 'WikibaseQualityConstraints' )
155
-					->warning( 'Constraint {constraintId} has invalid constraint parameters.', [
154
+				LoggerFactory::getInstance('WikibaseQualityConstraints')
155
+					->warning('Constraint {constraintId} has invalid constraint parameters.', [
156 156
 						'method' => __METHOD__,
157 157
 						'constraintId' => $result->constraint_guid,
158 158
 						'constraintParameters' => $result->constraint_parameters,
159
-					] );
160
-				$constraintParameters = [ '@error' => [ /* unknown */ ] ];
159
+					]);
160
+				$constraintParameters = ['@error' => [/* unknown */]];
161 161
 			}
162 162
 
163 163
 			$constraints[] = new Constraint(
164 164
 				$result->constraint_guid,
165
-				PropertyId::newFromNumber( $result->pid ),
165
+				PropertyId::newFromNumber($result->pid),
166 166
 				$constraintTypeItemId,
167 167
 				$constraintParameters
168 168
 			);
Please login to merge, or discard this patch.