Completed
Push — master ( 4b4be4...297c09 )
by
unknown
02:25 queued 12s
created
src/Html/HtmlTableBuilder.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 	/**
33 33
 	 * @param array $headers
34 34
 	 */
35
-	public function __construct( array $headers ) {
36
-		foreach ( $headers as $header ) {
37
-			$this->addHeader( $header );
35
+	public function __construct(array $headers) {
36
+		foreach ($headers as $header) {
37
+			$this->addHeader($header);
38 38
 		}
39 39
 	}
40 40
 
@@ -43,16 +43,16 @@  discard block
 block discarded – undo
43 43
 	 *
44 44
 	 * @throws InvalidArgumentException
45 45
 	 */
46
-	private function addHeader( $header ) {
47
-		Assert::parameterType( 'string|' . HtmlTableHeaderBuilder::class, $header, '$header' );
46
+	private function addHeader($header) {
47
+		Assert::parameterType('string|'.HtmlTableHeaderBuilder::class, $header, '$header');
48 48
 
49
-		if ( is_string( $header ) ) {
50
-			$header = new HtmlTableHeaderBuilder( $header );
49
+		if (is_string($header)) {
50
+			$header = new HtmlTableHeaderBuilder($header);
51 51
 		}
52 52
 
53 53
 		$this->headers[] = $header;
54 54
 
55
-		if ( $header->getIsSortable() ) {
55
+		if ($header->getIsSortable()) {
56 56
 			$this->isSortable = true;
57 57
 		}
58 58
 	}
@@ -85,12 +85,12 @@  discard block
 block discarded – undo
85 85
 	 *
86 86
 	 * @throws InvalidArgumentException
87 87
 	 */
88
-	public function appendRow( array $cells ) {
89
-		foreach ( $cells as $key => $cell ) {
90
-			if ( is_string( $cell ) ) {
91
-				$cells[$key] = new HtmlTableCellBuilder( $cell );
92
-			} elseif ( !( $cell instanceof HtmlTableCellBuilder ) ) {
93
-				throw new InvalidArgumentException( '$cells must be array of HtmlTableCell objects.' );
88
+	public function appendRow(array $cells) {
89
+		foreach ($cells as $key => $cell) {
90
+			if (is_string($cell)) {
91
+				$cells[$key] = new HtmlTableCellBuilder($cell);
92
+			} elseif (!($cell instanceof HtmlTableCellBuilder)) {
93
+				throw new InvalidArgumentException('$cells must be array of HtmlTableCell objects.');
94 94
 			}
95 95
 		}
96 96
 
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 	 *
105 105
 	 * @throws InvalidArgumentException
106 106
 	 */
107
-	public function appendRows( array $rows ) {
108
-		foreach ( $rows as $cells ) {
109
-			if ( !is_array( $cells ) ) {
110
-				throw new InvalidArgumentException( '$rows must be array of arrays of HtmlTableCell objects.' );
107
+	public function appendRows(array $rows) {
108
+		foreach ($rows as $cells) {
109
+			if (!is_array($cells)) {
110
+				throw new InvalidArgumentException('$rows must be array of arrays of HtmlTableCell objects.');
111 111
 			}
112 112
 
113
-			$this->appendRow( $cells );
113
+			$this->appendRow($cells);
114 114
 		}
115 115
 	}
116 116
 
@@ -122,38 +122,38 @@  discard block
 block discarded – undo
122 122
 	public function toHtml() {
123 123
 		// Open table
124 124
 		$tableClasses = 'wikitable';
125
-		if ( $this->isSortable ) {
125
+		if ($this->isSortable) {
126 126
 			$tableClasses .= ' sortable';
127 127
 		}
128
-		$html = Html::openElement( 'table', [ 'class' => $tableClasses ] );
128
+		$html = Html::openElement('table', ['class' => $tableClasses]);
129 129
 
130 130
 		// Write headers
131
-		$html .= Html::openElement( 'thead' );
132
-		$html .= Html::openElement( 'tr' );
133
-		foreach ( $this->headers as $header ) {
131
+		$html .= Html::openElement('thead');
132
+		$html .= Html::openElement('tr');
133
+		foreach ($this->headers as $header) {
134 134
 			$html .= $header->toHtml();
135 135
 		}
136
-		$html .= Html::closeElement( 'tr' );
137
-		$html .= Html::closeElement( 'thead' );
138
-		$html .= Html::openElement( 'tbody' );
136
+		$html .= Html::closeElement('tr');
137
+		$html .= Html::closeElement('thead');
138
+		$html .= Html::openElement('tbody');
139 139
 
140 140
 		// Write rows
141
-		foreach ( $this->rows as $row ) {
142
-			$html .= Html::openElement( 'tr' );
141
+		foreach ($this->rows as $row) {
142
+			$html .= Html::openElement('tr');
143 143
 
144 144
 			/**
145 145
 			 * @var HtmlTableCellBuilder $cell
146 146
 			 */
147
-			foreach ( $row as $cell ) {
147
+			foreach ($row as $cell) {
148 148
 				$html .= $cell->toHtml();
149 149
 			}
150 150
 
151
-			$html .= Html::closeElement( 'tr' );
151
+			$html .= Html::closeElement('tr');
152 152
 		}
153 153
 
154 154
 		// Close table
155
-		$html .= Html::closeElement( 'tbody' );
156
-		$html .= Html::closeElement( 'table' );
155
+		$html .= Html::closeElement('tbody');
156
+		$html .= Html::closeElement('table');
157 157
 
158 158
 		return $html;
159 159
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/SparqlHelper.php 1 patch
Spacing   +166 added lines, -169 removed lines patch added patch discarded remove patch
@@ -162,19 +162,19 @@  discard block
 block discarded – undo
162 162
 		$this->loggingHelper = $loggingHelper;
163 163
 		$this->defaultUserAgent = $defaultUserAgent;
164 164
 		$this->requestFactory = $requestFactory;
165
-		$this->entityPrefix = $rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY );
165
+		$this->entityPrefix = $rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY);
166 166
 		$this->prefixes = <<<EOT
167
-PREFIX wd: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY )}>
168
-PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}>
169
-PREFIX wdt: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_DIRECT_CLAIM )}>
170
-PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>
171
-PREFIX p: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM )}>
172
-PREFIX ps: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM_STATEMENT )}>
173
-PREFIX pq: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER )}>
174
-PREFIX pqv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER_VALUE )}>
175
-PREFIX pr: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE )}>
176
-PREFIX prv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE_VALUE )}>
177
-PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>
167
+PREFIX wd: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY)}>
168
+PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}>
169
+PREFIX wdt: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_DIRECT_CLAIM)}>
170
+PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>
171
+PREFIX p: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM)}>
172
+PREFIX ps: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM_STATEMENT)}>
173
+PREFIX pq: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER)}>
174
+PREFIX pqv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER_VALUE)}>
175
+PREFIX pr: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE)}>
176
+PREFIX prv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE_VALUE)}>
177
+PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>
178 178
 EOT;
179 179
 	}
180 180
 
@@ -185,22 +185,21 @@  discard block
 block discarded – undo
185 185
 	 * @return CachedBool
186 186
 	 * @throws SparqlHelperException if the query times out or some other error occurs
187 187
 	 */
188
-	public function hasType( $id, array $classes ) {
189
-		$subclassOfId = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
188
+	public function hasType($id, array $classes) {
189
+		$subclassOfId = $this->config->get('WBQualityConstraintsSubclassOfId');
190 190
 		// TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually
191
-		$gearingHint = $this->config->get( 'WBQualityConstraintsSparqlHasWikibaseSupport' ) ?
192
-			' hint:Prior hint:gearing "forward".' :
193
-			'';
191
+		$gearingHint = $this->config->get('WBQualityConstraintsSparqlHasWikibaseSupport') ?
192
+			' hint:Prior hint:gearing "forward".' : '';
194 193
 
195 194
 		$metadatas = [];
196 195
 
197
-		foreach ( array_chunk( $classes, 20 ) as $classesChunk ) {
198
-			$classesValues = implode( ' ', array_map(
199
-				function( $class ) {
200
-					return 'wd:' . $class;
196
+		foreach (array_chunk($classes, 20) as $classesChunk) {
197
+			$classesValues = implode(' ', array_map(
198
+				function($class) {
199
+					return 'wd:'.$class;
201 200
 				},
202 201
 				$classesChunk
203
-			) );
202
+			));
204 203
 
205 204
 			$query = <<<EOF
206 205
 ASK {
@@ -210,19 +209,19 @@  discard block
 block discarded – undo
210 209
 }
211 210
 EOF;
212 211
 
213
-			$result = $this->runQuery( $query );
212
+			$result = $this->runQuery($query);
214 213
 			$metadatas[] = $result->getMetadata();
215
-			if ( $result->getArray()['boolean'] ) {
214
+			if ($result->getArray()['boolean']) {
216 215
 				return new CachedBool(
217 216
 					true,
218
-					Metadata::merge( $metadatas )
217
+					Metadata::merge($metadatas)
219 218
 				);
220 219
 			}
221 220
 		}
222 221
 
223 222
 		return new CachedBool(
224 223
 			false,
225
-			Metadata::merge( $metadatas )
224
+			Metadata::merge($metadatas)
226 225
 		);
227 226
 	}
228 227
 
@@ -238,10 +237,10 @@  discard block
 block discarded – undo
238 237
 		$ignoreDeprecatedStatements
239 238
 	) {
240 239
 		$pid = $statement->getPropertyId()->serialize();
241
-		$guid = str_replace( '$', '-', $statement->getGuid() );
240
+		$guid = str_replace('$', '-', $statement->getGuid());
242 241
 
243 242
 		$deprecatedFilter = '';
244
-		if ( $ignoreDeprecatedStatements ) {
243
+		if ($ignoreDeprecatedStatements) {
245 244
 			$deprecatedFilter = 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }';
246 245
 		}
247 246
 
@@ -260,9 +259,9 @@  discard block
 block discarded – undo
260 259
 LIMIT 10
261 260
 EOF;
262 261
 
263
-		$result = $this->runQuery( $query );
262
+		$result = $this->runQuery($query);
264 263
 
265
-		return $this->getOtherEntities( $result );
264
+		return $this->getOtherEntities($result);
266 265
 	}
267 266
 
268 267
 	/**
@@ -287,16 +286,15 @@  discard block
 block discarded – undo
287 286
 		$dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty(
288 287
 			$snak->getPropertyId()
289 288
 		);
290
-		list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue );
291
-		if ( $isFullValue ) {
289
+		list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue);
290
+		if ($isFullValue) {
292 291
 			$prefix .= 'v';
293 292
 		}
294 293
 		$path = $type === Context::TYPE_QUALIFIER ?
295
-			"$prefix:$pid" :
296
-			"prov:wasDerivedFrom/$prefix:$pid";
294
+			"$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid";
297 295
 
298 296
 		$deprecatedFilter = '';
299
-		if ( $ignoreDeprecatedStatements ) {
297
+		if ($ignoreDeprecatedStatements) {
300 298
 			$deprecatedFilter = <<< EOF
301 299
   MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }
302 300
 EOF;
@@ -316,9 +314,9 @@  discard block
 block discarded – undo
316 314
 LIMIT 10
317 315
 EOF;
318 316
 
319
-		$result = $this->runQuery( $query );
317
+		$result = $this->runQuery($query);
320 318
 
321
-		return $this->getOtherEntities( $result );
319
+		return $this->getOtherEntities($result);
322 320
 	}
323 321
 
324 322
 	/**
@@ -328,8 +326,8 @@  discard block
 block discarded – undo
328 326
 	 *
329 327
 	 * @return string
330 328
 	 */
331
-	private function stringLiteral( $text ) {
332
-		return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"';
329
+	private function stringLiteral($text) {
330
+		return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"';
333 331
 	}
334 332
 
335 333
 	/**
@@ -339,17 +337,17 @@  discard block
 block discarded – undo
339 337
 	 *
340 338
 	 * @return CachedEntityIds
341 339
 	 */
342
-	private function getOtherEntities( CachedQueryResults $results ) {
343
-		return new CachedEntityIds( array_map(
344
-			function ( $resultBindings ) {
340
+	private function getOtherEntities(CachedQueryResults $results) {
341
+		return new CachedEntityIds(array_map(
342
+			function($resultBindings) {
345 343
 				$entityIRI = $resultBindings['otherEntity']['value'];
346
-				$entityPrefixLength = strlen( $this->entityPrefix );
347
-				if ( substr( $entityIRI, 0, $entityPrefixLength ) === $this->entityPrefix ) {
344
+				$entityPrefixLength = strlen($this->entityPrefix);
345
+				if (substr($entityIRI, 0, $entityPrefixLength) === $this->entityPrefix) {
348 346
 					try {
349 347
 						return $this->entityIdParser->parse(
350
-							substr( $entityIRI, $entityPrefixLength )
348
+							substr($entityIRI, $entityPrefixLength)
351 349
 						);
352
-					} catch ( EntityIdParsingException $e ) {
350
+					} catch (EntityIdParsingException $e) {
353 351
 						// fall through
354 352
 					}
355 353
 				}
@@ -357,7 +355,7 @@  discard block
 block discarded – undo
357 355
 				return null;
358 356
 			},
359 357
 			$results->getArray()['results']['bindings']
360
-		), $results->getMetadata() );
358
+		), $results->getMetadata());
361 359
 	}
362 360
 
363 361
 	// @codingStandardsIgnoreStart cyclomatic complexity of this function is too high
@@ -370,47 +368,47 @@  discard block
 block discarded – undo
370 368
 	 * @return array the literal or IRI as a string in SPARQL syntax,
371 369
 	 * and a boolean indicating whether it refers to a full value node or not
372 370
 	 */
373
-	private function getRdfLiteral( $dataType, DataValue $dataValue ) {
374
-		switch ( $dataType ) {
371
+	private function getRdfLiteral($dataType, DataValue $dataValue) {
372
+		switch ($dataType) {
375 373
 			case 'string':
376 374
 			case 'external-id':
377
-				return [ $this->stringLiteral( $dataValue->getValue() ), false ];
375
+				return [$this->stringLiteral($dataValue->getValue()), false];
378 376
 			case 'commonsMedia':
379
-				$url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() );
380
-				return [ '<' . $url . '>', false ];
377
+				$url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue());
378
+				return ['<'.$url.'>', false];
381 379
 			case 'geo-shape':
382
-				$url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() );
383
-				return [ '<' . $url . '>', false ];
380
+				$url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue());
381
+				return ['<'.$url.'>', false];
384 382
 			case 'tabular-data':
385
-				$url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() );
386
-				return [ '<' . $url . '>', false ];
383
+				$url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue());
384
+				return ['<'.$url.'>', false];
387 385
 			case 'url':
388 386
 				$url = $dataValue->getValue();
389
-				if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) {
387
+				if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) {
390 388
 					// not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF)
391 389
 					// such an URL should never reach us, so just throw
392
-					throw new InvalidArgumentException( 'invalid URL: ' . $url );
390
+					throw new InvalidArgumentException('invalid URL: '.$url);
393 391
 				}
394
-				return [ '<' . $url . '>', false ];
392
+				return ['<'.$url.'>', false];
395 393
 			case 'wikibase-item':
396 394
 			case 'wikibase-property':
397 395
 				/** @var EntityIdValue $dataValue */
398
-				return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ];
396
+				return ['wd:'.$dataValue->getEntityId()->getSerialization(), false];
399 397
 			case 'monolingualtext':
400 398
 				/** @var MonolingualTextValue $dataValue */
401 399
 				$lang = $dataValue->getLanguageCode();
402
-				if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) {
400
+				if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) {
403 401
 					// not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG)
404 402
 					// such a language tag should never reach us, so just throw
405
-					throw new InvalidArgumentException( 'invalid language tag: ' . $lang );
403
+					throw new InvalidArgumentException('invalid language tag: '.$lang);
406 404
 				}
407
-				return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ];
405
+				return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false];
408 406
 			case 'globe-coordinate':
409 407
 			case 'quantity':
410 408
 			case 'time':
411
-				return [ 'wdv:' . $dataValue->getHash(), true ];
409
+				return ['wdv:'.$dataValue->getHash(), true];
412 410
 			default:
413
-				throw new InvalidArgumentException( 'unknown data type: ' . $dataType );
411
+				throw new InvalidArgumentException('unknown data type: '.$dataType);
414 412
 		}
415 413
 	}
416 414
 	// @codingStandardsIgnoreEnd
@@ -423,44 +421,44 @@  discard block
 block discarded – undo
423 421
 	 * @throws SparqlHelperException if the query times out or some other error occurs
424 422
 	 * @throws ConstraintParameterException if the $regex is invalid
425 423
 	 */
426
-	public function matchesRegularExpression( $text, $regex ) {
424
+	public function matchesRegularExpression($text, $regex) {
427 425
 		// caching wrapper around matchesRegularExpressionWithSparql
428 426
 
429
-		$textHash = hash( 'sha256', $text );
427
+		$textHash = hash('sha256', $text);
430 428
 		$cacheKey = $this->cache->makeKey(
431 429
 			'WikibaseQualityConstraints', // extension
432 430
 			'regex', // action
433 431
 			'WDQS-Java', // regex flavor
434
-			hash( 'sha256', $regex )
432
+			hash('sha256', $regex)
435 433
 		);
436
-		$cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' );
434
+		$cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize');
437 435
 
438 436
 		$cacheMapArray = $this->cache->getWithSetCallback(
439 437
 			$cacheKey,
440 438
 			WANObjectCache::TTL_DAY,
441
-			function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) {
439
+			function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) {
442 440
 				// Initialize the cache map if not set
443
-				if ( $cacheMapArray === false ) {
441
+				if ($cacheMapArray === false) {
444 442
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.init';
445
-					$this->dataFactory->increment( $key );
443
+					$this->dataFactory->increment($key);
446 444
 					return [];
447 445
 				}
448 446
 
449 447
 				$key = 'wikibase.quality.constraints.regex.cache.refresh';
450
-				$this->dataFactory->increment( $key );
451
-				$cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize );
452
-				if ( $cacheMap->has( $textHash ) ) {
448
+				$this->dataFactory->increment($key);
449
+				$cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize);
450
+				if ($cacheMap->has($textHash)) {
453 451
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.hit';
454
-					$this->dataFactory->increment( $key );
455
-					$cacheMap->get( $textHash ); // ping cache
452
+					$this->dataFactory->increment($key);
453
+					$cacheMap->get($textHash); // ping cache
456 454
 				} else {
457 455
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.miss';
458
-					$this->dataFactory->increment( $key );
456
+					$this->dataFactory->increment($key);
459 457
 					try {
460
-						$matches = $this->matchesRegularExpressionWithSparql( $text, $regex );
461
-					} catch ( ConstraintParameterException $e ) {
462
-						$matches = $this->serializeConstraintParameterException( $e );
463
-					} catch ( SparqlHelperException $e ) {
458
+						$matches = $this->matchesRegularExpressionWithSparql($text, $regex);
459
+					} catch (ConstraintParameterException $e) {
460
+						$matches = $this->serializeConstraintParameterException($e);
461
+					} catch (SparqlHelperException $e) {
464 462
 						// don’t cache this
465 463
 						return $cacheMap->toArray();
466 464
 					}
@@ -484,42 +482,42 @@  discard block
 block discarded – undo
484 482
 			]
485 483
 		);
486 484
 
487
-		if ( isset( $cacheMapArray[$textHash] ) ) {
485
+		if (isset($cacheMapArray[$textHash])) {
488 486
 			$key = 'wikibase.quality.constraints.regex.cache.hit';
489
-			$this->dataFactory->increment( $key );
487
+			$this->dataFactory->increment($key);
490 488
 			$matches = $cacheMapArray[$textHash];
491
-			if ( is_bool( $matches ) ) {
489
+			if (is_bool($matches)) {
492 490
 				return $matches;
493
-			} elseif ( is_array( $matches ) &&
494
-				$matches['type'] == ConstraintParameterException::class ) {
495
-				throw $this->deserializeConstraintParameterException( $matches );
491
+			} elseif (is_array($matches) &&
492
+				$matches['type'] == ConstraintParameterException::class) {
493
+				throw $this->deserializeConstraintParameterException($matches);
496 494
 			} else {
497 495
 				throw new MWException(
498
-					'Value of unknown type in object cache (' .
499
-					'cache key: ' . $cacheKey . ', ' .
500
-					'cache map key: ' . $textHash . ', ' .
501
-					'value type: ' . gettype( $matches ) . ')'
496
+					'Value of unknown type in object cache ('.
497
+					'cache key: '.$cacheKey.', '.
498
+					'cache map key: '.$textHash.', '.
499
+					'value type: '.gettype($matches).')'
502 500
 				);
503 501
 			}
504 502
 		} else {
505 503
 			$key = 'wikibase.quality.constraints.regex.cache.miss';
506
-			$this->dataFactory->increment( $key );
507
-			return $this->matchesRegularExpressionWithSparql( $text, $regex );
504
+			$this->dataFactory->increment($key);
505
+			return $this->matchesRegularExpressionWithSparql($text, $regex);
508 506
 		}
509 507
 	}
510 508
 
511
-	private function serializeConstraintParameterException( ConstraintParameterException $cpe ) {
509
+	private function serializeConstraintParameterException(ConstraintParameterException $cpe) {
512 510
 		return [
513 511
 			'type' => ConstraintParameterException::class,
514
-			'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ),
512
+			'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()),
515 513
 		];
516 514
 	}
517 515
 
518
-	private function deserializeConstraintParameterException( array $serialization ) {
516
+	private function deserializeConstraintParameterException(array $serialization) {
519 517
 		$message = $this->violationMessageDeserializer->deserialize(
520 518
 			$serialization['violationMessage']
521 519
 		);
522
-		return new ConstraintParameterException( $message );
520
+		return new ConstraintParameterException($message);
523 521
 	}
524 522
 
525 523
 	/**
@@ -533,25 +531,25 @@  discard block
 block discarded – undo
533 531
 	 * @throws SparqlHelperException if the query times out or some other error occurs
534 532
 	 * @throws ConstraintParameterException if the $regex is invalid
535 533
 	 */
536
-	public function matchesRegularExpressionWithSparql( $text, $regex ) {
537
-		$textStringLiteral = $this->stringLiteral( $text );
538
-		$regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' );
534
+	public function matchesRegularExpressionWithSparql($text, $regex) {
535
+		$textStringLiteral = $this->stringLiteral($text);
536
+		$regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$');
539 537
 
540 538
 		$query = <<<EOF
541 539
 SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {}
542 540
 EOF;
543 541
 
544
-		$result = $this->runQuery( $query, false );
542
+		$result = $this->runQuery($query, false);
545 543
 
546 544
 		$vars = $result->getArray()['results']['bindings'][0];
547
-		if ( array_key_exists( 'matches', $vars ) ) {
545
+		if (array_key_exists('matches', $vars)) {
548 546
 			// true or false ⇒ regex okay, text matches or not
549 547
 			return $vars['matches']['value'] === 'true';
550 548
 		} else {
551 549
 			// empty result: regex broken
552 550
 			throw new ConstraintParameterException(
553
-				( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) )
554
-					->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE )
551
+				(new ViolationMessage('wbqc-violation-message-parameter-regex'))
552
+					->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE)
555 553
 			);
556 554
 		}
557 555
 	}
@@ -563,14 +561,14 @@  discard block
 block discarded – undo
563 561
 	 *
564 562
 	 * @return boolean
565 563
 	 */
566
-	public function isTimeout( $responseContent ) {
567
-		$timeoutRegex = implode( '|', array_map(
568
-			function ( $fqn ) {
569
-				return preg_quote( $fqn, '/' );
564
+	public function isTimeout($responseContent) {
565
+		$timeoutRegex = implode('|', array_map(
566
+			function($fqn) {
567
+				return preg_quote($fqn, '/');
570 568
 			},
571
-			$this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' )
572
-		) );
573
-		return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent );
569
+			$this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses')
570
+		));
571
+		return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent);
574 572
 	}
575 573
 
576 574
 	/**
@@ -582,17 +580,17 @@  discard block
 block discarded – undo
582 580
 	 * @return int|boolean the max-age (in seconds)
583 581
 	 * or a plain boolean if no max-age can be determined
584 582
 	 */
585
-	public function getCacheMaxAge( $responseHeaders ) {
583
+	public function getCacheMaxAge($responseHeaders) {
586 584
 		if (
587
-			array_key_exists( 'x-cache-status', $responseHeaders ) &&
588
-			preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] )
585
+			array_key_exists('x-cache-status', $responseHeaders) &&
586
+			preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0])
589 587
 		) {
590 588
 			$maxage = [];
591 589
 			if (
592
-				array_key_exists( 'cache-control', $responseHeaders ) &&
593
-				preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage )
590
+				array_key_exists('cache-control', $responseHeaders) &&
591
+				preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage)
594 592
 			) {
595
-				return intval( $maxage[1] );
593
+				return intval($maxage[1]);
596 594
 			} else {
597 595
 				return true;
598 596
 			}
@@ -613,34 +611,34 @@  discard block
 block discarded – undo
613 611
 	 * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After
614 612
 	 * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format
615 613
 	 */
616
-	public function getThrottling( MWHttpRequest $request ) {
617
-		$retryAfterValue = $request->getResponseHeader( 'Retry-After' );
618
-		if ( $retryAfterValue === null ) {
614
+	public function getThrottling(MWHttpRequest $request) {
615
+		$retryAfterValue = $request->getResponseHeader('Retry-After');
616
+		if ($retryAfterValue === null) {
619 617
 			return self::NO_RETRY_AFTER;
620 618
 		}
621 619
 
622
-		$trimmedRetryAfterValue = trim( $retryAfterValue );
623
-		if ( empty( $trimmedRetryAfterValue ) ) {
620
+		$trimmedRetryAfterValue = trim($retryAfterValue);
621
+		if (empty($trimmedRetryAfterValue)) {
624 622
 			return self::EMPTY_RETRY_AFTER;
625 623
 		}
626 624
 
627
-		if ( is_numeric( $trimmedRetryAfterValue ) ) {
628
-			$delaySeconds = (int)$trimmedRetryAfterValue;
629
-			if ( $delaySeconds >= 0 ) {
630
-				return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) );
625
+		if (is_numeric($trimmedRetryAfterValue)) {
626
+			$delaySeconds = (int) $trimmedRetryAfterValue;
627
+			if ($delaySeconds >= 0) {
628
+				return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S'));
631 629
 			}
632 630
 		} else {
633
-			$return = strtotime( $trimmedRetryAfterValue );
634
-			if ( !empty( $return ) ) {
635
-				return new ConvertibleTimestamp( $return );
631
+			$return = strtotime($trimmedRetryAfterValue);
632
+			if (!empty($return)) {
633
+				return new ConvertibleTimestamp($return);
636 634
 			}
637 635
 		}
638 636
 		return self::INVALID_RETRY_AFTER;
639 637
 	}
640 638
 
641
-	private function getTimestampInFuture( DateInterval $delta ) {
639
+	private function getTimestampInFuture(DateInterval $delta) {
642 640
 		$now = new ConvertibleTimestamp();
643
-		return new ConvertibleTimestamp( $now->timestamp->add( $delta ) );
641
+		return new ConvertibleTimestamp($now->timestamp->add($delta));
644 642
 	}
645 643
 
646 644
 	/**
@@ -654,97 +652,96 @@  discard block
 block discarded – undo
654 652
 	 *
655 653
 	 * @throws SparqlHelperException if the query times out or some other error occurs
656 654
 	 */
657
-	public function runQuery( $query, $needsPrefixes = true ) {
655
+	public function runQuery($query, $needsPrefixes = true) {
658 656
 
659
-		if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) {
660
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' );
657
+		if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) {
658
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling');
661 659
 			throw new TooManySparqlRequestsException();
662 660
 		}
663 661
 
664
-		$endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' );
665
-		$maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' );
666
-		$fallbackBlockDuration = (int)$this->config->get( 'WBQualityConstraintsSparqlThrottlingFallbackDuration' );
662
+		$endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint');
663
+		$maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis');
664
+		$fallbackBlockDuration = (int) $this->config->get('WBQualityConstraintsSparqlThrottlingFallbackDuration');
667 665
 
668
-		if ( $fallbackBlockDuration < 0 ) {
669
-			throw new InvalidArgumentException( 'Fallback duration must be positive int but is: '.
670
-				$fallbackBlockDuration );
666
+		if ($fallbackBlockDuration < 0) {
667
+			throw new InvalidArgumentException('Fallback duration must be positive int but is: '.
668
+				$fallbackBlockDuration);
671 669
 		}
672 670
 
673
-		if ( $this->config->get( 'WBQualityConstraintsSparqlHasWikibaseSupport' ) ) {
671
+		if ($this->config->get('WBQualityConstraintsSparqlHasWikibaseSupport')) {
674 672
 			$needsPrefixes = false;
675 673
 		}
676 674
 
677
-		if ( $needsPrefixes ) {
678
-			$query = $this->prefixes . $query;
675
+		if ($needsPrefixes) {
676
+			$query = $this->prefixes.$query;
679 677
 		}
680
-		$query = "#wbqc\n" . $query;
678
+		$query = "#wbqc\n".$query;
681 679
 
682
-		$url = $endpoint . '?' . http_build_query(
680
+		$url = $endpoint.'?'.http_build_query(
683 681
 			[
684 682
 				'query' => $query,
685 683
 				'format' => 'json',
686 684
 				'maxQueryTimeMillis' => $maxQueryTimeMillis,
687 685
 			],
688
-			null, ini_get( 'arg_separator.output' ),
686
+			null, ini_get('arg_separator.output'),
689 687
 			// encode spaces with %20, not +
690 688
 			PHP_QUERY_RFC3986
691 689
 		);
692 690
 
693 691
 		$options = [
694 692
 			'method' => 'GET',
695
-			'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ),
693
+			'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000),
696 694
 			'connectTimeout' => 'default',
697 695
 			'userAgent' => $this->defaultUserAgent,
698 696
 		];
699
-		$request = $this->requestFactory->create( $url, $options );
700
-		$startTime = microtime( true );
697
+		$request = $this->requestFactory->create($url, $options);
698
+		$startTime = microtime(true);
701 699
 		$status = $request->execute();
702
-		$endTime = microtime( true );
700
+		$endTime = microtime(true);
703 701
 		$this->dataFactory->timing(
704 702
 			'wikibase.quality.constraints.sparql.timing',
705
-			( $endTime - $startTime ) * 1000
703
+			($endTime - $startTime) * 1000
706 704
 		);
707 705
 
708
-		if ( $request->getStatus() === self::HTTP_TOO_MANY_REQUESTS ) {
709
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' );
710
-			$throttlingUntil = $this->getThrottling( $request );
711
-			if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) {
712
-				$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request );
706
+		if ($request->getStatus() === self::HTTP_TOO_MANY_REQUESTS) {
707
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling');
708
+			$throttlingUntil = $this->getThrottling($request);
709
+			if (!($throttlingUntil instanceof ConvertibleTimestamp)) {
710
+				$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request);
713 711
 				$this->throttlingLock->lock(
714 712
 					self::EXPIRY_LOCK_ID,
715
-					$this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) )
713
+					$this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S'))
716 714
 				);
717 715
 			} else {
718
-				$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request );
719
-				$this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil );
716
+				$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request);
717
+				$this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil);
720 718
 			}
721 719
 			throw new TooManySparqlRequestsException();
722 720
 		}
723 721
 
724
-		$maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() );
725
-		if ( $maxAge ) {
726
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' );
722
+		$maxAge = $this->getCacheMaxAge($request->getResponseHeaders());
723
+		if ($maxAge) {
724
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.cached');
727 725
 		}
728 726
 
729
-		if ( $status->isOK() ) {
727
+		if ($status->isOK()) {
730 728
 			$json = $request->getContent();
731
-			$arr = json_decode( $json, true );
729
+			$arr = json_decode($json, true);
732 730
 			return new CachedQueryResults(
733 731
 				$arr,
734 732
 				Metadata::ofCachingMetadata(
735 733
 					$maxAge ?
736
-						CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) :
737
-						CachingMetadata::fresh()
734
+						CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh()
738 735
 				)
739 736
 			);
740 737
 		} else {
741
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' );
738
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.error');
742 739
 
743 740
 			$this->dataFactory->increment(
744 741
 				"wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}"
745 742
 			);
746 743
 
747
-			if ( $this->isTimeout( $request->getContent() ) ) {
744
+			if ($this->isTimeout($request->getContent())) {
748 745
 				$this->dataFactory->increment(
749 746
 					'wikibase.quality.constraints.sparql.error.timeout'
750 747
 				);
Please login to merge, or discard this patch.
src/ServiceWiring-ConstraintCheckers.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -36,196 +36,196 @@
 block discarded – undo
36 36
 use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker;
37 37
 
38 38
 return [
39
-	ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => function( MediaWikiServices $services ) {
39
+	ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => function(MediaWikiServices $services) {
40 40
 		return new ConflictsWithChecker(
41
-			WikibaseServices::getEntityLookup( $services ),
42
-			ConstraintsServices::getConstraintParameterParser( $services ),
43
-			ConstraintsServices::getConnectionCheckerHelper( $services )
41
+			WikibaseServices::getEntityLookup($services),
42
+			ConstraintsServices::getConstraintParameterParser($services),
43
+			ConstraintsServices::getConnectionCheckerHelper($services)
44 44
 		);
45 45
 	},
46 46
 
47
-	ConstraintCheckerServices::ITEM_CHECKER => function( MediaWikiServices $services ) {
47
+	ConstraintCheckerServices::ITEM_CHECKER => function(MediaWikiServices $services) {
48 48
 		return new ItemChecker(
49
-			WikibaseServices::getEntityLookup( $services ),
50
-			ConstraintsServices::getConstraintParameterParser( $services ),
51
-			ConstraintsServices::getConnectionCheckerHelper( $services )
49
+			WikibaseServices::getEntityLookup($services),
50
+			ConstraintsServices::getConstraintParameterParser($services),
51
+			ConstraintsServices::getConnectionCheckerHelper($services)
52 52
 		);
53 53
 	},
54 54
 
55
-	ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => function( MediaWikiServices $services ) {
55
+	ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => function(MediaWikiServices $services) {
56 56
 		return new TargetRequiredClaimChecker(
57
-			WikibaseServices::getEntityLookup( $services ),
58
-			ConstraintsServices::getConstraintParameterParser( $services ),
59
-			ConstraintsServices::getConnectionCheckerHelper( $services )
57
+			WikibaseServices::getEntityLookup($services),
58
+			ConstraintsServices::getConstraintParameterParser($services),
59
+			ConstraintsServices::getConnectionCheckerHelper($services)
60 60
 		);
61 61
 	},
62 62
 
63
-	ConstraintCheckerServices::SYMMETRIC_CHECKER => function( MediaWikiServices $services ) {
63
+	ConstraintCheckerServices::SYMMETRIC_CHECKER => function(MediaWikiServices $services) {
64 64
 		return new SymmetricChecker(
65
-			WikibaseServices::getEntityLookup( $services ),
66
-			ConstraintsServices::getConnectionCheckerHelper( $services )
65
+			WikibaseServices::getEntityLookup($services),
66
+			ConstraintsServices::getConnectionCheckerHelper($services)
67 67
 		);
68 68
 	},
69 69
 
70
-	ConstraintCheckerServices::INVERSE_CHECKER => function( MediaWikiServices $services ) {
70
+	ConstraintCheckerServices::INVERSE_CHECKER => function(MediaWikiServices $services) {
71 71
 		return new InverseChecker(
72
-			WikibaseServices::getEntityLookup( $services ),
73
-			ConstraintsServices::getConstraintParameterParser( $services ),
74
-			ConstraintsServices::getConnectionCheckerHelper( $services )
72
+			WikibaseServices::getEntityLookup($services),
73
+			ConstraintsServices::getConstraintParameterParser($services),
74
+			ConstraintsServices::getConnectionCheckerHelper($services)
75 75
 		);
76 76
 	},
77 77
 
78
-	ConstraintCheckerServices::QUALIFIER_CHECKER => function( MediaWikiServices $services ) {
78
+	ConstraintCheckerServices::QUALIFIER_CHECKER => function(MediaWikiServices $services) {
79 79
 		return new QualifierChecker();
80 80
 	},
81 81
 
82
-	ConstraintCheckerServices::QUALIFIERS_CHECKER => function( MediaWikiServices $services ) {
82
+	ConstraintCheckerServices::QUALIFIERS_CHECKER => function(MediaWikiServices $services) {
83 83
 		return new QualifiersChecker(
84
-			ConstraintsServices::getConstraintParameterParser( $services )
84
+			ConstraintsServices::getConstraintParameterParser($services)
85 85
 		);
86 86
 	},
87 87
 
88
-	ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => function( MediaWikiServices $services ) {
88
+	ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => function(MediaWikiServices $services) {
89 89
 		return new MandatoryQualifiersChecker(
90
-			ConstraintsServices::getConstraintParameterParser( $services )
90
+			ConstraintsServices::getConstraintParameterParser($services)
91 91
 		);
92 92
 	},
93 93
 
94
-	ConstraintCheckerServices::RANGE_CHECKER => function( MediaWikiServices $services ) {
94
+	ConstraintCheckerServices::RANGE_CHECKER => function(MediaWikiServices $services) {
95 95
 		return new RangeChecker(
96
-			WikibaseServices::getPropertyDataTypeLookup( $services ),
97
-			ConstraintsServices::getConstraintParameterParser( $services ),
98
-			ConstraintsServices::getRangeCheckerHelper( $services )
96
+			WikibaseServices::getPropertyDataTypeLookup($services),
97
+			ConstraintsServices::getConstraintParameterParser($services),
98
+			ConstraintsServices::getRangeCheckerHelper($services)
99 99
 		);
100 100
 	},
101 101
 
102
-	ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => function( MediaWikiServices $services ) {
102
+	ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => function(MediaWikiServices $services) {
103 103
 		return new DiffWithinRangeChecker(
104
-			ConstraintsServices::getConstraintParameterParser( $services ),
105
-			ConstraintsServices::getRangeCheckerHelper( $services ),
104
+			ConstraintsServices::getConstraintParameterParser($services),
105
+			ConstraintsServices::getRangeCheckerHelper($services),
106 106
 			$services->getMainConfig()
107 107
 		);
108 108
 	},
109 109
 
110
-	ConstraintCheckerServices::TYPE_CHECKER => function( MediaWikiServices $services ) {
110
+	ConstraintCheckerServices::TYPE_CHECKER => function(MediaWikiServices $services) {
111 111
 		return new TypeChecker(
112
-			WikibaseServices::getEntityLookup( $services ),
113
-			ConstraintsServices::getConstraintParameterParser( $services ),
114
-			ConstraintsServices::getTypeCheckerHelper( $services ),
112
+			WikibaseServices::getEntityLookup($services),
113
+			ConstraintsServices::getConstraintParameterParser($services),
114
+			ConstraintsServices::getTypeCheckerHelper($services),
115 115
 			$services->getMainConfig()
116 116
 		);
117 117
 	},
118 118
 
119
-	ConstraintCheckerServices::VALUE_TYPE_CHECKER => function( MediaWikiServices $services ) {
119
+	ConstraintCheckerServices::VALUE_TYPE_CHECKER => function(MediaWikiServices $services) {
120 120
 		return new ValueTypeChecker(
121
-			WikibaseServices::getEntityLookup( $services ),
122
-			ConstraintsServices::getConstraintParameterParser( $services ),
123
-			ConstraintsServices::getTypeCheckerHelper( $services ),
121
+			WikibaseServices::getEntityLookup($services),
122
+			ConstraintsServices::getConstraintParameterParser($services),
123
+			ConstraintsServices::getTypeCheckerHelper($services),
124 124
 			$services->getMainConfig()
125 125
 		);
126 126
 	},
127 127
 
128
-	ConstraintCheckerServices::SINGLE_VALUE_CHECKER => function( MediaWikiServices $services ) {
128
+	ConstraintCheckerServices::SINGLE_VALUE_CHECKER => function(MediaWikiServices $services) {
129 129
 		return new SingleValueChecker(
130
-			ConstraintsServices::getConstraintParameterParser( $services )
130
+			ConstraintsServices::getConstraintParameterParser($services)
131 131
 		);
132 132
 	},
133 133
 
134
-	ConstraintCheckerServices::MULTI_VALUE_CHECKER => function( MediaWikiServices $services ) {
134
+	ConstraintCheckerServices::MULTI_VALUE_CHECKER => function(MediaWikiServices $services) {
135 135
 		return new MultiValueChecker(
136
-			ConstraintsServices::getConstraintParameterParser( $services )
136
+			ConstraintsServices::getConstraintParameterParser($services)
137 137
 		);
138 138
 	},
139 139
 
140
-	ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => function( MediaWikiServices $services ) {
140
+	ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => function(MediaWikiServices $services) {
141 141
 		// TODO return a different, dummy implementation if SPARQL is not available
142 142
 		return new UniqueValueChecker(
143
-			ConstraintsServices::getSparqlHelper( $services )
143
+			ConstraintsServices::getSparqlHelper($services)
144 144
 		);
145 145
 	},
146 146
 
147
-	ConstraintCheckerServices::FORMAT_CHECKER => function( MediaWikiServices $services ) {
147
+	ConstraintCheckerServices::FORMAT_CHECKER => function(MediaWikiServices $services) {
148 148
 		// TODO return a different, dummy implementation if SPARQL is not available
149 149
 		return new FormatChecker(
150
-			ConstraintsServices::getConstraintParameterParser( $services ),
150
+			ConstraintsServices::getConstraintParameterParser($services),
151 151
 			$services->getMainConfig(),
152
-			ConstraintsServices::getSparqlHelper( $services )
152
+			ConstraintsServices::getSparqlHelper($services)
153 153
 		);
154 154
 	},
155 155
 
156
-	ConstraintCheckerServices::COMMONS_LINK_CHECKER => function( MediaWikiServices $services ) {
156
+	ConstraintCheckerServices::COMMONS_LINK_CHECKER => function(MediaWikiServices $services) {
157 157
 		$pageNameNormalizer = new MediaWikiPageNameNormalizer();
158 158
 		return new CommonsLinkChecker(
159
-			ConstraintsServices::getConstraintParameterParser( $services ),
159
+			ConstraintsServices::getConstraintParameterParser($services),
160 160
 			$pageNameNormalizer
161 161
 		);
162 162
 	},
163 163
 
164
-	ConstraintCheckerServices::ONE_OF_CHECKER => function( MediaWikiServices $services ) {
164
+	ConstraintCheckerServices::ONE_OF_CHECKER => function(MediaWikiServices $services) {
165 165
 		return new OneOfChecker(
166
-			ConstraintsServices::getConstraintParameterParser( $services )
166
+			ConstraintsServices::getConstraintParameterParser($services)
167 167
 		);
168 168
 	},
169 169
 
170
-	ConstraintCheckerServices::VALUE_ONLY_CHECKER => function( MediaWikiServices $services ) {
170
+	ConstraintCheckerServices::VALUE_ONLY_CHECKER => function(MediaWikiServices $services) {
171 171
 		return new ValueOnlyChecker();
172 172
 	},
173 173
 
174
-	ConstraintCheckerServices::REFERENCE_CHECKER => function( MediaWikiServices $services ) {
174
+	ConstraintCheckerServices::REFERENCE_CHECKER => function(MediaWikiServices $services) {
175 175
 		return new ReferenceChecker();
176 176
 	},
177 177
 
178
-	ConstraintCheckerServices::NO_BOUNDS_CHECKER => function( MediaWikiServices $services ) {
178
+	ConstraintCheckerServices::NO_BOUNDS_CHECKER => function(MediaWikiServices $services) {
179 179
 		return new NoBoundsChecker();
180 180
 	},
181 181
 
182
-	ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => function( MediaWikiServices $services ) {
182
+	ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => function(MediaWikiServices $services) {
183 183
 		// TODO in the future, get UnitConverter from $services?
184 184
 		$repo = WikibaseRepo::getDefaultInstance();
185 185
 		$unitConverter = $repo->getUnitConverter();
186 186
 
187 187
 		return new AllowedUnitsChecker(
188
-			ConstraintsServices::getConstraintParameterParser( $services ),
188
+			ConstraintsServices::getConstraintParameterParser($services),
189 189
 			$unitConverter
190 190
 		);
191 191
 	},
192 192
 
193
-	ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => function( MediaWikiServices $services ) {
193
+	ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => function(MediaWikiServices $services) {
194 194
 		return new SingleBestValueChecker(
195
-			ConstraintsServices::getConstraintParameterParser( $services )
195
+			ConstraintsServices::getConstraintParameterParser($services)
196 196
 		);
197 197
 	},
198 198
 
199
-	ConstraintCheckerServices::ENTITY_TYPE_CHECKER => function( MediaWikiServices $services ) {
199
+	ConstraintCheckerServices::ENTITY_TYPE_CHECKER => function(MediaWikiServices $services) {
200 200
 		return new EntityTypeChecker(
201
-			ConstraintsServices::getConstraintParameterParser( $services )
201
+			ConstraintsServices::getConstraintParameterParser($services)
202 202
 		);
203 203
 	},
204 204
 
205
-	ConstraintCheckerServices::NONE_OF_CHECKER => function( MediaWikiServices $services ) {
205
+	ConstraintCheckerServices::NONE_OF_CHECKER => function(MediaWikiServices $services) {
206 206
 		return new NoneOfChecker(
207
-			ConstraintsServices::getConstraintParameterParser( $services )
207
+			ConstraintsServices::getConstraintParameterParser($services)
208 208
 		);
209 209
 	},
210 210
 
211
-	ConstraintCheckerServices::INTEGER_CHECKER => function( MediaWikiServices $services ) {
211
+	ConstraintCheckerServices::INTEGER_CHECKER => function(MediaWikiServices $services) {
212 212
 		return new IntegerChecker();
213 213
 	},
214 214
 
215
-	ConstraintCheckerServices::CITATION_NEEDED_CHECKER => function( MediaWikiServices $services ) {
215
+	ConstraintCheckerServices::CITATION_NEEDED_CHECKER => function(MediaWikiServices $services) {
216 216
 		return new CitationNeededChecker();
217 217
 	},
218 218
 
219
-	ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => function( MediaWikiServices $services ) {
219
+	ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => function(MediaWikiServices $services) {
220 220
 		return new PropertyScopeChecker(
221
-			ConstraintsServices::getConstraintParameterParser( $services )
221
+			ConstraintsServices::getConstraintParameterParser($services)
222 222
 		);
223 223
 	},
224 224
 
225
-	ConstraintCheckerServices::CONTEMPORARY_CHECKER => function( MediaWikiServices $services ) {
225
+	ConstraintCheckerServices::CONTEMPORARY_CHECKER => function(MediaWikiServices $services) {
226 226
 		return new ContemporaryChecker(
227
-			WikibaseServices::getEntityLookup( $services ),
228
-			ConstraintsServices::getRangeCheckerHelper( $services ),
227
+			WikibaseServices::getEntityLookup($services),
228
+			ConstraintsServices::getRangeCheckerHelper($services),
229 229
 			$services->getMainConfig()
230 230
 		);
231 231
 	},
Please login to merge, or discard this patch.
src/Api/CheckConstraints.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -79,19 +79,19 @@  discard block
 block discarded – undo
79 79
 	 *
80 80
 	 * @return self
81 81
 	 */
82
-	public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) {
82
+	public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') {
83 83
 		$repo = WikibaseRepo::getDefaultInstance();
84 84
 
85 85
 		$language = $repo->getUserLanguage();
86 86
 		$formatterOptions = new FormatterOptions();
87
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
87
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
88 88
 		$valueFormatterFactory = $repo->getValueFormatterFactory();
89
-		$valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
89
+		$valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
90 90
 
91 91
 		$entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory();
92
-		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $language );
92
+		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($language);
93 93
 		$entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory();
94
-		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $language );
94
+		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($language);
95 95
 		$config = MediaWikiServices::getInstance()->getMainConfig();
96 96
 		$dataFactory = MediaWikiServices::getInstance()->getStatsdDataFactory();
97 97
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 			$prefix,
114 114
 			$repo->getEntityIdParser(),
115 115
 			$repo->getStatementGuidValidator(),
116
-			$repo->getApiHelperFactory( RequestContext::getMain() ),
116
+			$repo->getApiHelperFactory(RequestContext::getMain()),
117 117
 			$resultsSource,
118 118
 			$checkResultsRenderer,
119 119
 			$dataFactory
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 		CheckResultsRenderer $checkResultsRenderer,
143 143
 		IBufferingStatsdDataFactory $dataFactory
144 144
 	) {
145
-		parent::__construct( $main, $name, $prefix );
145
+		parent::__construct($main, $name, $prefix);
146 146
 		$this->entityIdParser = $entityIdParser;
147 147
 		$this->statementGuidValidator = $statementGuidValidator;
148
-		$this->resultBuilder = $apiHelperFactory->getResultBuilder( $this );
149
-		$this->errorReporter = $apiHelperFactory->getErrorReporter( $this );
148
+		$this->resultBuilder = $apiHelperFactory->getResultBuilder($this);
149
+		$this->errorReporter = $apiHelperFactory->getErrorReporter($this);
150 150
 		$this->resultsSource = $resultsSource;
151 151
 		$this->checkResultsRenderer = $checkResultsRenderer;
152 152
 		$this->dataFactory = $dataFactory;
@@ -162,9 +162,9 @@  discard block
 block discarded – undo
162 162
 
163 163
 		$params = $this->extractRequestParams();
164 164
 
165
-		$this->validateParameters( $params );
166
-		$entityIds = $this->parseEntityIds( $params );
167
-		$claimIds = $this->parseClaimIds( $params );
165
+		$this->validateParameters($params);
166
+		$entityIds = $this->parseEntityIds($params);
167
+		$claimIds = $this->parseClaimIds($params);
168 168
 		$constraintIDs = $params[self::PARAM_CONSTRAINT_ID];
169 169
 		$statuses = $params[self::PARAM_STATUS];
170 170
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 				)
181 181
 			)->getArray()
182 182
 		);
183
-		$this->resultBuilder->markSuccess( 1 );
183
+		$this->resultBuilder->markSuccess(1);
184 184
 	}
185 185
 
186 186
 	/**
@@ -188,24 +188,24 @@  discard block
 block discarded – undo
188 188
 	 *
189 189
 	 * @return EntityId[]
190 190
 	 */
191
-	private function parseEntityIds( array $params ) {
191
+	private function parseEntityIds(array $params) {
192 192
 		$ids = $params[self::PARAM_ID];
193 193
 
194
-		if ( $ids === null ) {
194
+		if ($ids === null) {
195 195
 			return [];
196
-		} elseif ( $ids === [] ) {
196
+		} elseif ($ids === []) {
197 197
 			$this->errorReporter->dieError(
198
-				'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' );
198
+				'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' );
199 199
 		}
200 200
 
201
-		return array_map( function ( $id ) {
201
+		return array_map(function($id) {
202 202
 			try {
203
-				return $this->entityIdParser->parse( $id );
204
-			} catch ( EntityIdParsingException $e ) {
203
+				return $this->entityIdParser->parse($id);
204
+			} catch (EntityIdParsingException $e) {
205 205
 				$this->errorReporter->dieError(
206
-					"Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] );
206
+					"Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] );
207 207
 			}
208
-		}, $ids );
208
+		}, $ids);
209 209
 	}
210 210
 
211 211
 	/**
@@ -213,35 +213,35 @@  discard block
 block discarded – undo
213 213
 	 *
214 214
 	 * @return string[]
215 215
 	 */
216
-	private function parseClaimIds( array $params ) {
216
+	private function parseClaimIds(array $params) {
217 217
 		$ids = $params[self::PARAM_CLAIM_ID];
218 218
 
219
-		if ( $ids === null ) {
219
+		if ($ids === null) {
220 220
 			return [];
221
-		} elseif ( $ids === [] ) {
221
+		} elseif ($ids === []) {
222 222
 			$this->errorReporter->dieError(
223
-				'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' );
223
+				'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' );
224 224
 		}
225 225
 
226
-		foreach ( $ids as $id ) {
227
-			if ( !$this->statementGuidValidator->validate( $id ) ) {
226
+		foreach ($ids as $id) {
227
+			if (!$this->statementGuidValidator->validate($id)) {
228 228
 				$this->errorReporter->dieError(
229
-					"Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] );
229
+					"Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] );
230 230
 			}
231 231
 		}
232 232
 
233 233
 		return $ids;
234 234
 	}
235 235
 
236
-	private function validateParameters( array $params ) {
237
-		if ( $params[self::PARAM_CONSTRAINT_ID] !== null
238
-			 && empty( $params[self::PARAM_CONSTRAINT_ID] )
236
+	private function validateParameters(array $params) {
237
+		if ($params[self::PARAM_CONSTRAINT_ID] !== null
238
+			 && empty($params[self::PARAM_CONSTRAINT_ID])
239 239
 		) {
240 240
 			$paramConstraintId = self::PARAM_CONSTRAINT_ID;
241 241
 			$this->errorReporter->dieError(
242 242
 				"If $paramConstraintId is specified, it must be nonempty.", 'no-data' );
243 243
 		}
244
-		if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) {
244
+		if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) {
245 245
 			$paramId = self::PARAM_ID;
246 246
 			$paramClaimId = self::PARAM_CLAIM_ID;
247 247
 			$this->errorReporter->dieError(
@@ -282,12 +282,12 @@  discard block
 block discarded – undo
282 282
 				],
283 283
 				ApiBase::PARAM_ISMULTI => true,
284 284
 				ApiBase::PARAM_ALL => true,
285
-				ApiBase::PARAM_DFLT => implode( '|', [
285
+				ApiBase::PARAM_DFLT => implode('|', [
286 286
 					CheckResult::STATUS_VIOLATION,
287 287
 					CheckResult::STATUS_WARNING,
288 288
 					CheckResult::STATUS_SUGGESTION,
289 289
 					CheckResult::STATUS_BAD_PARAMETERS,
290
-				] ),
290
+				]),
291 291
 				ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
292 292
 			],
293 293
 		];
Please login to merge, or discard this patch.
src/Specials/SpecialConstraintReport.php 1 patch
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		Config $config,
137 137
 		IBufferingStatsdDataFactory $dataFactory
138 138
 	) {
139
-		parent::__construct( 'ConstraintReport' );
139
+		parent::__construct('ConstraintReport');
140 140
 
141 141
 		$this->entityLookup = $entityLookup;
142 142
 		$this->entityTitleLookup = $entityTitleLookup;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		$language = $this->getLanguage();
146 146
 
147 147
 		$formatterOptions = new FormatterOptions();
148
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
148
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
149 149
 		$this->dataValueFormatter = $valueFormatterFactory->getValueFormatter(
150 150
 			SnakFormatter::FORMAT_HTML,
151 151
 			$formatterOptions
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	 * @return string
206 206
 	 */
207 207
 	public function getDescription() {
208
-		return $this->msg( 'wbqc-constraintreport' )->escaped();
208
+		return $this->msg('wbqc-constraintreport')->escaped();
209 209
 	}
210 210
 
211 211
 	/**
@@ -217,43 +217,43 @@  discard block
 block discarded – undo
217 217
 	 * @throws EntityIdParsingException
218 218
 	 * @throws UnexpectedValueException
219 219
 	 */
220
-	public function execute( $subPage ) {
220
+	public function execute($subPage) {
221 221
 		$out = $this->getOutput();
222 222
 
223
-		$postRequest = $this->getContext()->getRequest()->getVal( 'entityid' );
224
-		if ( $postRequest ) {
225
-			$out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() );
223
+		$postRequest = $this->getContext()->getRequest()->getVal('entityid');
224
+		if ($postRequest) {
225
+			$out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL());
226 226
 			return;
227 227
 		}
228 228
 
229 229
 		$out->enableOOUI();
230
-		$out->addModules( $this->getModules() );
230
+		$out->addModules($this->getModules());
231 231
 
232 232
 		$this->setHeaders();
233 233
 
234
-		$out->addHTML( $this->getExplanationText() );
234
+		$out->addHTML($this->getExplanationText());
235 235
 		$this->buildEntityIdForm();
236 236
 
237
-		if ( !$subPage ) {
237
+		if (!$subPage) {
238 238
 			return;
239 239
 		}
240 240
 
241
-		if ( !is_string( $subPage ) ) {
242
-			throw new InvalidArgumentException( '$subPage must be string.' );
241
+		if (!is_string($subPage)) {
242
+			throw new InvalidArgumentException('$subPage must be string.');
243 243
 		}
244 244
 
245 245
 		try {
246
-			$entityId = $this->entityIdParser->parse( $subPage );
247
-		} catch ( EntityIdParsingException $e ) {
246
+			$entityId = $this->entityIdParser->parse($subPage);
247
+		} catch (EntityIdParsingException $e) {
248 248
 			$out->addHTML(
249
-				$this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true )
249
+				$this->buildNotice('wbqc-constraintreport-invalid-entity-id', true)
250 250
 			);
251 251
 			return;
252 252
 		}
253 253
 
254
-		if ( !$this->entityLookup->hasEntity( $entityId ) ) {
254
+		if (!$this->entityLookup->hasEntity($entityId)) {
255 255
 			$out->addHTML(
256
-				$this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true )
256
+				$this->buildNotice('wbqc-constraintreport-not-existent-entity', true)
257 257
 			);
258 258
 			return;
259 259
 		}
@@ -261,18 +261,18 @@  discard block
 block discarded – undo
261 261
 		$this->dataFactory->increment(
262 262
 			'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck'
263 263
 		);
264
-		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId );
264
+		$results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId);
265 265
 
266
-		if ( $results !== [] ) {
266
+		if ($results !== []) {
267 267
 			$out->addHTML(
268
-				$this->buildResultHeader( $entityId )
269
-				. $this->buildSummary( $results )
270
-				. $this->buildResultTable( $entityId, $results )
268
+				$this->buildResultHeader($entityId)
269
+				. $this->buildSummary($results)
270
+				. $this->buildResultTable($entityId, $results)
271 271
 			);
272 272
 		} else {
273 273
 			$out->addHTML(
274
-				$this->buildResultHeader( $entityId )
275
-				. $this->buildNotice( 'wbqc-constraintreport-empty-result' )
274
+				$this->buildResultHeader($entityId)
275
+				. $this->buildNotice('wbqc-constraintreport-empty-result')
276 276
 			);
277 277
 		}
278 278
 	}
@@ -288,15 +288,15 @@  discard block
 block discarded – undo
288 288
 				'name' => 'entityid',
289 289
 				'label-message' => 'wbqc-constraintreport-form-entityid-label',
290 290
 				'cssclass' => 'wbqc-constraintreport-form-entity-id',
291
-				'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped()
291
+				'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped()
292 292
 			]
293 293
 		];
294
-		$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' );
295
-		$htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() );
296
-		$htmlForm->setSubmitCallback( function() {
294
+		$htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form');
295
+		$htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped());
296
+		$htmlForm->setSubmitCallback(function() {
297 297
 			return false;
298 298
 		} );
299
-		$htmlForm->setMethod( 'post' );
299
+		$htmlForm->setMethod('post');
300 300
 		$htmlForm->show();
301 301
 	}
302 302
 
@@ -310,16 +310,16 @@  discard block
 block discarded – undo
310 310
 	 *
311 311
 	 * @return string HTML
312 312
 	 */
313
-	private function buildNotice( $messageKey, $error = false ) {
314
-		if ( !is_string( $messageKey ) ) {
315
-			throw new InvalidArgumentException( '$message must be string.' );
313
+	private function buildNotice($messageKey, $error = false) {
314
+		if (!is_string($messageKey)) {
315
+			throw new InvalidArgumentException('$message must be string.');
316 316
 		}
317
-		if ( !is_bool( $error ) ) {
318
-			throw new InvalidArgumentException( '$error must be bool.' );
317
+		if (!is_bool($error)) {
318
+			throw new InvalidArgumentException('$error must be bool.');
319 319
 		}
320 320
 
321 321
 		$cssClasses = 'wbqc-constraintreport-notice';
322
-		if ( $error ) {
322
+		if ($error) {
323 323
 			$cssClasses .= ' wbqc-constraintreport-notice-error';
324 324
 		}
325 325
 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 				[
329 329
 					'class' => $cssClasses
330 330
 				],
331
-				$this->msg( $messageKey )->escaped()
331
+				$this->msg($messageKey)->escaped()
332 332
 			);
333 333
 	}
334 334
 
@@ -338,16 +338,16 @@  discard block
 block discarded – undo
338 338
 	private function getExplanationText() {
339 339
 		return Html::rawElement(
340 340
 			'div',
341
-			[ 'class' => 'wbqc-explanation' ],
341
+			['class' => 'wbqc-explanation'],
342 342
 			Html::rawElement(
343 343
 				'p',
344 344
 				[],
345
-				$this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped()
345
+				$this->msg('wbqc-constraintreport-explanation-part-one')->escaped()
346 346
 			)
347 347
 			. Html::rawElement(
348 348
 				'p',
349 349
 				[],
350
-				$this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped()
350
+				$this->msg('wbqc-constraintreport-explanation-part-two')->escaped()
351 351
 			)
352 352
 		);
353 353
 	}
@@ -358,72 +358,72 @@  discard block
 block discarded – undo
358 358
 	 *
359 359
 	 * @return string HTML
360 360
 	 */
361
-	private function buildResultTable( EntityId $entityId, array $results ) {
361
+	private function buildResultTable(EntityId $entityId, array $results) {
362 362
 		// Set table headers
363 363
 		$table = new HtmlTableBuilder(
364 364
 			[
365 365
 				new HtmlTableHeaderBuilder(
366
-					$this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(),
366
+					$this->msg('wbqc-constraintreport-result-table-header-status')->escaped(),
367 367
 					true
368 368
 				),
369 369
 				new HtmlTableHeaderBuilder(
370
-					$this->msg( 'wbqc-constraintreport-result-table-header-property' )->escaped(),
370
+					$this->msg('wbqc-constraintreport-result-table-header-property')->escaped(),
371 371
 					true
372 372
 				),
373 373
 				new HtmlTableHeaderBuilder(
374
-					$this->msg( 'wbqc-constraintreport-result-table-header-message' )->escaped(),
374
+					$this->msg('wbqc-constraintreport-result-table-header-message')->escaped(),
375 375
 					true
376 376
 				),
377 377
 				new HtmlTableHeaderBuilder(
378
-					$this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(),
378
+					$this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(),
379 379
 					true
380 380
 				)
381 381
 			]
382 382
 		);
383 383
 
384
-		foreach ( $results as $result ) {
385
-			$table = $this->appendToResultTable( $table, $entityId, $result );
384
+		foreach ($results as $result) {
385
+			$table = $this->appendToResultTable($table, $entityId, $result);
386 386
 		}
387 387
 
388 388
 		return $table->toHtml();
389 389
 	}
390 390
 
391
-	private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) {
391
+	private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) {
392 392
 		$message = $result->getMessage();
393
-		if ( $message === null ) {
393
+		if ($message === null) {
394 394
 			// no row for this result
395 395
 			return $table;
396 396
 		}
397 397
 
398 398
 		// Status column
399
-		$statusColumn = $this->formatStatus( $result->getStatus() );
399
+		$statusColumn = $this->formatStatus($result->getStatus());
400 400
 
401 401
 		// Property column
402
-		$propertyId = new PropertyId( $result->getContextCursor()->getSnakPropertyId() );
402
+		$propertyId = new PropertyId($result->getContextCursor()->getSnakPropertyId());
403 403
 		$propertyColumn = $this->getClaimLink(
404 404
 			$entityId,
405 405
 			$propertyId,
406
-			$this->entityIdLabelFormatter->formatEntityId( $propertyId )
406
+			$this->entityIdLabelFormatter->formatEntityId($propertyId)
407 407
 		);
408 408
 
409 409
 		// Message column
410
-		$messageColumn = $this->violationMessageRenderer->render( $message );
410
+		$messageColumn = $this->violationMessageRenderer->render($message);
411 411
 
412 412
 		// Constraint column
413 413
 		$constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId();
414 414
 		try {
415
-			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) );
416
-		} catch ( InvalidArgumentException $e ) {
417
-			$constraintTypeLabel = htmlspecialchars( $constraintTypeItemId );
415
+			$constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId));
416
+		} catch (InvalidArgumentException $e) {
417
+			$constraintTypeLabel = htmlspecialchars($constraintTypeItemId);
418 418
 		}
419 419
 		$constraintLink = $this->getClaimLink(
420 420
 			$propertyId,
421
-			new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ),
421
+			new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')),
422 422
 			$constraintTypeLabel
423 423
 		);
424 424
 		$constraintColumn = $this->buildExpandableElement(
425 425
 			$constraintLink,
426
-			$this->constraintParameterRenderer->formatParameters( $result->getParameters() ),
426
+			$this->constraintParameterRenderer->formatParameters($result->getParameters()),
427 427
 			'[...]'
428 428
 		);
429 429
 
@@ -463,15 +463,15 @@  discard block
 block discarded – undo
463 463
 	 *
464 464
 	 * @return string HTML
465 465
 	 */
466
-	protected function buildResultHeader( EntityId $entityId ) {
467
-		$entityLink = sprintf( '%s (%s)',
468
-							   $this->entityIdLinkFormatter->formatEntityId( $entityId ),
469
-							   htmlspecialchars( $entityId->getSerialization() ) );
466
+	protected function buildResultHeader(EntityId $entityId) {
467
+		$entityLink = sprintf('%s (%s)',
468
+							   $this->entityIdLinkFormatter->formatEntityId($entityId),
469
+							   htmlspecialchars($entityId->getSerialization()));
470 470
 
471 471
 		return Html::rawElement(
472 472
 			'h3',
473 473
 			[],
474
-			sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink )
474
+			sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink)
475 475
 		);
476 476
 	}
477 477
 
@@ -482,24 +482,24 @@  discard block
 block discarded – undo
482 482
 	 *
483 483
 	 * @return string HTML
484 484
 	 */
485
-	protected function buildSummary( array $results ) {
485
+	protected function buildSummary(array $results) {
486 486
 		$statuses = [];
487
-		foreach ( $results as $result ) {
488
-			$status = strtolower( $result->getStatus() );
489
-			$statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1;
487
+		foreach ($results as $result) {
488
+			$status = strtolower($result->getStatus());
489
+			$statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1;
490 490
 		}
491 491
 
492 492
 		$statusElements = [];
493
-		foreach ( $statuses as $status => $count ) {
494
-			if ( $count > 0 ) {
493
+		foreach ($statuses as $status => $count) {
494
+			if ($count > 0) {
495 495
 				$statusElements[] =
496
-					$this->formatStatus( $status )
496
+					$this->formatStatus($status)
497 497
 					. ': '
498 498
 					. $count;
499 499
 			}
500 500
 		}
501 501
 
502
-		return Html::rawElement( 'p', [], implode( ', ', $statusElements ) );
502
+		return Html::rawElement('p', [], implode(', ', $statusElements));
503 503
 	}
504 504
 
505 505
 	/**
@@ -514,15 +514,15 @@  discard block
 block discarded – undo
514 514
 	 *
515 515
 	 * @return string HTML
516 516
 	 */
517
-	protected function buildExpandableElement( $content, $expandableContent, $indicator ) {
518
-		if ( !is_string( $content ) ) {
519
-			throw new InvalidArgumentException( '$content has to be string.' );
517
+	protected function buildExpandableElement($content, $expandableContent, $indicator) {
518
+		if (!is_string($content)) {
519
+			throw new InvalidArgumentException('$content has to be string.');
520 520
 		}
521
-		if ( $expandableContent && ( !is_string( $expandableContent ) ) ) {
522
-			throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' );
521
+		if ($expandableContent && (!is_string($expandableContent))) {
522
+			throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.');
523 523
 		}
524 524
 
525
-		if ( empty( $expandableContent ) ) {
525
+		if (empty($expandableContent)) {
526 526
 			return $content;
527 527
 		}
528 528
 
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 			$expandableContent
543 543
 		);
544 544
 
545
-		return sprintf( '%s %s %s', $content, $tooltipIndicator, $expandableContent );
545
+		return sprintf('%s %s %s', $content, $tooltipIndicator, $expandableContent);
546 546
 	}
547 547
 
548 548
 	/**
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
 	 *
555 555
 	 * @return string HTML
556 556
 	 */
557
-	private function formatStatus( $status ) {
558
-		$messageName = "wbqc-constraintreport-status-" . strtolower( $status );
557
+	private function formatStatus($status) {
558
+		$messageName = "wbqc-constraintreport-status-".strtolower($status);
559 559
 		$statusIcons = [
560 560
 			CheckResult::STATUS_SUGGESTION => [
561 561
 				'icon' => 'suggestion-constraint-violation',
@@ -572,25 +572,25 @@  discard block
 block discarded – undo
572 572
 			],
573 573
 		];
574 574
 
575
-		if ( array_key_exists( $status, $statusIcons ) ) {
576
-			$iconWidget = new IconWidget( $statusIcons[$status] );
577
-			$iconHtml = $iconWidget->toString() . ' ';
575
+		if (array_key_exists($status, $statusIcons)) {
576
+			$iconWidget = new IconWidget($statusIcons[$status]);
577
+			$iconHtml = $iconWidget->toString().' ';
578 578
 		} else {
579 579
 			$iconHtml = '';
580 580
 		}
581 581
 
582
-		$labelWidget = new LabelWidget( [
583
-			'label' => $this->msg( $messageName )->text(),
584
-		] );
582
+		$labelWidget = new LabelWidget([
583
+			'label' => $this->msg($messageName)->text(),
584
+		]);
585 585
 		$labelHtml = $labelWidget->toString();
586 586
 
587 587
 		$formattedStatus =
588 588
 			Html::rawElement(
589 589
 				'span',
590 590
 				[
591
-					'class' => 'wbqc-status wbqc-status-' . $status
591
+					'class' => 'wbqc-status wbqc-status-'.$status
592 592
 				],
593
-				$iconHtml . $labelHtml
593
+				$iconHtml.$labelHtml
594 594
 			);
595 595
 
596 596
 		return $formattedStatus;
@@ -606,26 +606,26 @@  discard block
 block discarded – undo
606 606
 	 *
607 607
 	 * @return string HTML
608 608
 	 */
609
-	protected function formatDataValues( $dataValues, $separator = ', ' ) {
610
-		if ( $dataValues instanceof DataValue ) {
611
-			$dataValues = [ $dataValues ];
612
-		} elseif ( !is_array( $dataValues ) ) {
613
-			throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' );
609
+	protected function formatDataValues($dataValues, $separator = ', ') {
610
+		if ($dataValues instanceof DataValue) {
611
+			$dataValues = [$dataValues];
612
+		} elseif (!is_array($dataValues)) {
613
+			throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.');
614 614
 		}
615 615
 
616 616
 		$formattedDataValues = [];
617
-		foreach ( $dataValues as $dataValue ) {
618
-			if ( !( $dataValue instanceof DataValue ) ) {
619
-				throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' );
617
+		foreach ($dataValues as $dataValue) {
618
+			if (!($dataValue instanceof DataValue)) {
619
+				throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.');
620 620
 			}
621
-			if ( $dataValue instanceof EntityIdValue ) {
622
-				$formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() );
621
+			if ($dataValue instanceof EntityIdValue) {
622
+				$formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId());
623 623
 			} else {
624
-				$formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue );
624
+				$formattedDataValues[] = $this->dataValueFormatter->format($dataValue);
625 625
 			}
626 626
 		}
627 627
 
628
-		return implode( $separator, $formattedDataValues );
628
+		return implode($separator, $formattedDataValues);
629 629
 	}
630 630
 
631 631
 	/**
@@ -637,11 +637,11 @@  discard block
 block discarded – undo
637 637
 	 *
638 638
 	 * @return string HTML
639 639
 	 */
640
-	private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) {
640
+	private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) {
641 641
 		return Html::rawElement(
642 642
 			'a',
643 643
 			[
644
-				'href' => $this->getClaimUrl( $entityId, $propertyId ),
644
+				'href' => $this->getClaimUrl($entityId, $propertyId),
645 645
 				'target' => '_blank'
646 646
 			],
647 647
 			$text
@@ -656,9 +656,9 @@  discard block
 block discarded – undo
656 656
 	 *
657 657
 	 * @return string
658 658
 	 */
659
-	private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) {
660
-		$title = $this->entityTitleLookup->getTitleForId( $entityId );
661
-		$entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() );
659
+	private function getClaimUrl(EntityId $entityId, PropertyId $propertyId) {
660
+		$title = $this->entityTitleLookup->getTitleForId($entityId);
661
+		$entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization());
662 662
 
663 663
 		return $entityUrl;
664 664
 	}
Please login to merge, or discard this patch.
src/Api/CheckConstraintParameters.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -74,19 +74,19 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return self
76 76
 	 */
77
-	public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) {
77
+	public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') {
78 78
 		$repo = WikibaseRepo::getDefaultInstance();
79
-		$helperFactory = $repo->getApiHelperFactory( RequestContext::getMain() );
79
+		$helperFactory = $repo->getApiHelperFactory(RequestContext::getMain());
80 80
 		$language = $repo->getUserLanguage();
81 81
 
82 82
 		$entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory();
83 83
 		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory
84
-			->getEntityIdFormatter( $language );
84
+			->getEntityIdFormatter($language);
85 85
 		$formatterOptions = new FormatterOptions();
86
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
86
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
87 87
 		$valueFormatterFactory = $repo->getValueFormatterFactory();
88 88
 		$dataValueFormatter = $valueFormatterFactory
89
-			->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
89
+			->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
90 90
 		$config = MediaWikiServices::getInstance()->getMainConfig();
91 91
 		$violationMessageRenderer = new MultilingualTextViolationMessageRenderer(
92 92
 			$entityIdHtmlLinkFormatter,
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 		StatementGuidParser $statementGuidParser,
127 127
 		IBufferingStatsdDataFactory $dataFactory
128 128
 	) {
129
-		parent::__construct( $main, $name, $prefix );
129
+		parent::__construct($main, $name, $prefix);
130 130
 
131
-		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this );
131
+		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this);
132 132
 		$this->delegatingConstraintChecker = $delegatingConstraintChecker;
133 133
 		$this->violationMessageRenderer = $violationMessageRenderer;
134 134
 		$this->statementGuidParser = $statementGuidParser;
@@ -143,39 +143,39 @@  discard block
 block discarded – undo
143 143
 		$params = $this->extractRequestParams();
144 144
 		$result = $this->getResult();
145 145
 
146
-		$propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] );
147
-		$constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] );
146
+		$propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]);
147
+		$constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]);
148 148
 
149
-		$this->checkPropertyIds( $propertyIds, $result );
150
-		$this->checkConstraintIds( $constraintIds, $result );
149
+		$this->checkPropertyIds($propertyIds, $result);
150
+		$this->checkConstraintIds($constraintIds, $result);
151 151
 
152
-		$result->addValue( null, 'success', 1 );
152
+		$result->addValue(null, 'success', 1);
153 153
 	}
154 154
 
155 155
 	/**
156 156
 	 * @param array|null $propertyIdSerializations
157 157
 	 * @return PropertyId[]
158 158
 	 */
159
-	private function parsePropertyIds( $propertyIdSerializations ) {
160
-		if ( $propertyIdSerializations === null ) {
159
+	private function parsePropertyIds($propertyIdSerializations) {
160
+		if ($propertyIdSerializations === null) {
161 161
 			return [];
162
-		} elseif ( empty( $propertyIdSerializations ) ) {
162
+		} elseif (empty($propertyIdSerializations)) {
163 163
 			$this->apiErrorReporter->dieError(
164
-				'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.',
164
+				'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.',
165 165
 				'no-data'
166 166
 			);
167 167
 		}
168 168
 
169 169
 		return array_map(
170
-			function( $propertyIdSerialization ) {
170
+			function($propertyIdSerialization) {
171 171
 				try {
172
-					return new PropertyId( $propertyIdSerialization );
173
-				} catch ( InvalidArgumentException $e ) {
172
+					return new PropertyId($propertyIdSerialization);
173
+				} catch (InvalidArgumentException $e) {
174 174
 					$this->apiErrorReporter->dieError(
175 175
 						"Invalid id: $propertyIdSerialization",
176 176
 						'invalid-property-id',
177 177
 						0, // default argument
178
-						[ self::PARAM_PROPERTY_ID => $propertyIdSerialization ]
178
+						[self::PARAM_PROPERTY_ID => $propertyIdSerialization]
179 179
 					);
180 180
 				}
181 181
 			},
@@ -187,35 +187,35 @@  discard block
 block discarded – undo
187 187
 	 * @param array|null $constraintIds
188 188
 	 * @return string[]
189 189
 	 */
190
-	private function parseConstraintIds( $constraintIds ) {
191
-		if ( $constraintIds === null ) {
190
+	private function parseConstraintIds($constraintIds) {
191
+		if ($constraintIds === null) {
192 192
 			return [];
193
-		} elseif ( empty( $constraintIds ) ) {
193
+		} elseif (empty($constraintIds)) {
194 194
 			$this->apiErrorReporter->dieError(
195
-				'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.',
195
+				'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.',
196 196
 				'no-data'
197 197
 			);
198 198
 		}
199 199
 
200 200
 		return array_map(
201
-			function( $constraintId ) {
201
+			function($constraintId) {
202 202
 				try {
203
-					$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
204
-					if ( !$propertyId instanceof PropertyId ) {
203
+					$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
204
+					if (!$propertyId instanceof PropertyId) {
205 205
 						$this->apiErrorReporter->dieError(
206 206
 							"Invalid property ID: {$propertyId->getSerialization()}",
207 207
 							'invalid-property-id',
208 208
 							0, // default argument
209
-							[ self::PARAM_CONSTRAINT_ID => $constraintId ]
209
+							[self::PARAM_CONSTRAINT_ID => $constraintId]
210 210
 						);
211 211
 					}
212 212
 					return $constraintId;
213
-				} catch ( StatementGuidParsingException $e ) {
213
+				} catch (StatementGuidParsingException $e) {
214 214
 					$this->apiErrorReporter->dieError(
215 215
 						"Invalid statement GUID: $constraintId",
216 216
 						'invalid-guid',
217 217
 						0, // default argument
218
-						[ self::PARAM_CONSTRAINT_ID => $constraintId ]
218
+						[self::PARAM_CONSTRAINT_ID => $constraintId]
219 219
 					);
220 220
 				}
221 221
 			},
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
 	 * @param PropertyId[] $propertyIds
228 228
 	 * @param ApiResult $result
229 229
 	 */
230
-	private function checkPropertyIds( array $propertyIds, ApiResult $result ) {
231
-		foreach ( $propertyIds as $propertyId ) {
232
-			$result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' );
230
+	private function checkPropertyIds(array $propertyIds, ApiResult $result) {
231
+		foreach ($propertyIds as $propertyId) {
232
+			$result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc');
233 233
 			$allConstraintExceptions = $this->delegatingConstraintChecker
234
-				->checkConstraintParametersOnPropertyId( $propertyId );
235
-			foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) {
234
+				->checkConstraintParametersOnPropertyId($propertyId);
235
+			foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) {
236 236
 				$this->addConstraintParameterExceptionsToResult(
237 237
 					$constraintId,
238 238
 					$constraintParameterExceptions,
@@ -246,15 +246,15 @@  discard block
 block discarded – undo
246 246
 	 * @param string[] $constraintIds
247 247
 	 * @param ApiResult $result
248 248
 	 */
249
-	private function checkConstraintIds( array $constraintIds, ApiResult $result ) {
250
-		foreach ( $constraintIds as $constraintId ) {
251
-			if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) {
249
+	private function checkConstraintIds(array $constraintIds, ApiResult $result) {
250
+		foreach ($constraintIds as $constraintId) {
251
+			if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) {
252 252
 				// already checked as part of checkPropertyIds()
253 253
 				continue;
254 254
 			}
255 255
 			$constraintParameterExceptions = $this->delegatingConstraintChecker
256
-				->checkConstraintParametersOnConstraintId( $constraintId );
257
-			$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
256
+				->checkConstraintParametersOnConstraintId($constraintId);
257
+			$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
258 258
 		}
259 259
 	}
260 260
 
@@ -262,17 +262,17 @@  discard block
 block discarded – undo
262 262
 	 * @param PropertyId $propertyId
263 263
 	 * @return string[]
264 264
 	 */
265
-	private function getResultPathForPropertyId( PropertyId $propertyId ) {
266
-		return [ $this->getModuleName(), $propertyId->getSerialization() ];
265
+	private function getResultPathForPropertyId(PropertyId $propertyId) {
266
+		return [$this->getModuleName(), $propertyId->getSerialization()];
267 267
 	}
268 268
 
269 269
 	/**
270 270
 	 * @param string $constraintId
271 271
 	 * @return string[]
272 272
 	 */
273
-	private function getResultPathForConstraintId( $constraintId ) {
274
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
275
-		return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] );
273
+	private function getResultPathForConstraintId($constraintId) {
274
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
275
+		return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]);
276 276
 	}
277 277
 
278 278
 	/**
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
 		$constraintParameterExceptions,
288 288
 		ApiResult $result
289 289
 	) {
290
-		$path = $this->getResultPathForConstraintId( $constraintId );
291
-		if ( $constraintParameterExceptions === null ) {
290
+		$path = $this->getResultPathForConstraintId($constraintId);
291
+		if ($constraintParameterExceptions === null) {
292 292
 			$result->addValue(
293 293
 				$path,
294 294
 				self::KEY_STATUS,
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
 			$result->addValue(
299 299
 				$path,
300 300
 				self::KEY_STATUS,
301
-				empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY
301
+				empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY
302 302
 			);
303 303
 			$result->addValue(
304 304
 				$path,
305 305
 				self::KEY_PROBLEMS,
306
-				array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions )
306
+				array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions)
307 307
 			);
308 308
 		}
309 309
 	}
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 * @param ConstraintParameterException $e
315 315
 	 * @return string[]
316 316
 	 */
317
-	private function formatConstraintParameterException( ConstraintParameterException $e ) {
317
+	private function formatConstraintParameterException(ConstraintParameterException $e) {
318 318
 		return [
319 319
 			self::KEY_MESSAGE_HTML => $this->violationMessageRenderer->render(
320 320
 				$e->getViolationMessage()
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
 		return [
348 348
 			'action=wbcheckconstraintparameters&propertyid=P247'
349 349
 				=> 'apihelp-wbcheckconstraintparameters-example-propertyid-1',
350
-			'action=wbcheckconstraintparameters&' .
351
-			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' .
350
+			'action=wbcheckconstraintparameters&'.
351
+			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'.
352 352
 			'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f'
353 353
 				=> 'apihelp-wbcheckconstraintparameters-example-constraintid-2',
354 354
 		];
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/TypeChecker.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 	 * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs
84 84
 	 * @return CheckResult
85 85
 	 */
86
-	public function checkConstraint( Context $context, Constraint $constraint ) {
87
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
88
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
86
+	public function checkConstraint(Context $context, Constraint $constraint) {
87
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
88
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
89 89
 		}
90
-		if ( $context->getType() === Context::TYPE_REFERENCE ) {
91
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE );
90
+		if ($context->getType() === Context::TYPE_REFERENCE) {
91
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE);
92 92
 		}
93 93
 
94 94
 		$parameters = [];
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
 			$constraintTypeItemId
101 101
 		);
102 102
 		$parameters['class'] = array_map(
103
-			function( $id ) {
104
-				return new ItemId( $id );
103
+			function($id) {
104
+				return new ItemId($id);
105 105
 			},
106 106
 			$classes
107 107
 		);
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
 			$constraintTypeItemId
112 112
 		);
113 113
 		$relationIds = [];
114
-		if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) {
115
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' );
114
+		if ($relation === 'instance' || $relation === 'instanceOrSubclass') {
115
+			$relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId');
116 116
 		}
117
-		if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) {
118
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
117
+		if ($relation === 'subclass' || $relation === 'instanceOrSubclass') {
118
+			$relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId');
119 119
 		}
120
-		$parameters['relation'] = [ $relation ];
120
+		$parameters['relation'] = [$relation];
121 121
 
122 122
 		$result = $this->typeCheckerHelper->hasClassInRelation(
123 123
 			$context->getEntity()->getStatements(),
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 			$classes
126 126
 		);
127 127
 
128
-		if ( $result->getBool() ) {
128
+		if ($result->getBool()) {
129 129
 			$message = null;
130 130
 			$status = CheckResult::STATUS_COMPLIANCE;
131 131
 		} else {
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
 			$status = CheckResult::STATUS_VIOLATION;
140 140
 		}
141 141
 
142
-		return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) )
143
-			->withMetadata( $result->getMetadata() );
142
+		return (new CheckResult($context, $constraint, $parameters, $status, $message))
143
+			->withMetadata($result->getMetadata());
144 144
 	}
145 145
 
146
-	public function checkConstraintParameters( Constraint $constraint ) {
146
+	public function checkConstraintParameters(Constraint $constraint) {
147 147
 		$constraintParameters = $constraint->getConstraintParameters();
148 148
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
149 149
 		$exceptions = [];
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 				$constraintParameters,
153 153
 				$constraintTypeItemId
154 154
 			);
155
-		} catch ( ConstraintParameterException $e ) {
155
+		} catch (ConstraintParameterException $e) {
156 156
 			$exceptions[] = $e;
157 157
 		}
158 158
 		try {
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 				$constraintParameters,
161 161
 				$constraintTypeItemId
162 162
 			);
163
-		} catch ( ConstraintParameterException $e ) {
163
+		} catch (ConstraintParameterException $e) {
164 164
 			$exceptions[] = $e;
165 165
 		}
166 166
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/NoneOfChecker.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
 	 * @throws ConstraintParameterException
61 61
 	 * @return CheckResult
62 62
 	 */
63
-	public function checkConstraint( Context $context, Constraint $constraint ) {
64
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
65
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
63
+	public function checkConstraint(Context $context, Constraint $constraint) {
64
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
65
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
66 66
 		}
67 67
 
68 68
 		$parameters = [];
@@ -81,20 +81,20 @@  discard block
 block discarded – undo
81 81
 		$message = null;
82 82
 		$status = CheckResult::STATUS_COMPLIANCE;
83 83
 
84
-		foreach ( $items as $item ) {
85
-			if ( $item->matchesSnak( $snak ) ) {
86
-				$message = ( new ViolationMessage( 'wbqc-violation-message-none-of' ) )
87
-					->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE )
88
-					->withItemIdSnakValueList( $items, Role::OBJECT );
84
+		foreach ($items as $item) {
85
+			if ($item->matchesSnak($snak)) {
86
+				$message = (new ViolationMessage('wbqc-violation-message-none-of'))
87
+					->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE)
88
+					->withItemIdSnakValueList($items, Role::OBJECT);
89 89
 				$status = CheckResult::STATUS_VIOLATION;
90 90
 				break;
91 91
 			}
92 92
 		}
93 93
 
94
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
94
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
95 95
 	}
96 96
 
97
-	public function checkConstraintParameters( Constraint $constraint ) {
97
+	public function checkConstraintParameters(Constraint $constraint) {
98 98
 		$constraintParameters = $constraint->getConstraintParameters();
99 99
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
100 100
 		$exceptions = [];
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 				$constraintTypeItemId,
105 105
 				true
106 106
 			);
107
-		} catch ( ConstraintParameterException $e ) {
107
+		} catch (ConstraintParameterException $e) {
108 108
 			$exceptions[] = $e;
109 109
 		}
110 110
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/FormatChecker.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 * @throws ConstraintParameterException
86 86
 	 * @return CheckResult
87 87
 	 */
88
-	public function checkConstraint( Context $context, Constraint $constraint ) {
88
+	public function checkConstraint(Context $context, Constraint $constraint) {
89 89
 		$parameters = [];
90 90
 		$constraintParameters = $constraint->getConstraintParameters();
91 91
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 			$constraintParameters,
95 95
 			$constraintTypeItemId
96 96
 		);
97
-		$parameters['pattern'] = [ $format ];
97
+		$parameters['pattern'] = [$format];
98 98
 
99 99
 		$syntaxClarifications = $this->constraintParameterParser->parseSyntaxClarificationParameter(
100 100
 			$constraintParameters
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
 		$snak = $context->getSnak();
104 104
 
105
-		if ( !$snak instanceof PropertyValueSnak ) {
105
+		if (!$snak instanceof PropertyValueSnak) {
106 106
 			// nothing to check
107
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
107
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
108 108
 		}
109 109
 
110 110
 		$dataValue = $snak->getDataValue();
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		 * error handling:
114 114
 		 *   type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext'
115 115
 		 */
116
-		switch ( $dataValue->getType() ) {
116
+		switch ($dataValue->getType()) {
117 117
 			case 'string':
118 118
 				$text = $dataValue->getValue();
119 119
 				break;
@@ -122,37 +122,37 @@  discard block
 block discarded – undo
122 122
 				$text = $dataValue->getText();
123 123
 				break;
124 124
 			default:
125
-				$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) )
126
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
127
-					->withDataValueType( 'string' )
128
-					->withDataValueType( 'monolingualtext' );
129
-				return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
125
+				$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2'))
126
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
127
+					->withDataValueType('string')
128
+					->withDataValueType('monolingualtext');
129
+				return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
130 130
 		}
131 131
 
132 132
 		if (
133
-			!( $this->sparqlHelper instanceof DummySparqlHelper ) &&
134
-			$this->config->get( 'WBQualityConstraintsCheckFormatConstraint' )
133
+			!($this->sparqlHelper instanceof DummySparqlHelper) &&
134
+			$this->config->get('WBQualityConstraintsCheckFormatConstraint')
135 135
 		) {
136
-			if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) {
136
+			if ($this->sparqlHelper->matchesRegularExpression($text, $format)) {
137 137
 				$message = null;
138 138
 				$status = CheckResult::STATUS_COMPLIANCE;
139 139
 			} else {
140
-				$message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) )
141
-					->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY )
142
-					->withDataValue( new StringValue( $text ), Role::OBJECT )
143
-					->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE )
144
-					->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE );
140
+				$message = (new ViolationMessage('wbqc-violation-message-format-clarification'))
141
+					->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY)
142
+					->withDataValue(new StringValue($text), Role::OBJECT)
143
+					->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE)
144
+					->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE);
145 145
 				$status = CheckResult::STATUS_VIOLATION;
146 146
 			}
147 147
 		} else {
148
-			$message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) )
149
-				->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM );
148
+			$message = (new ViolationMessage('wbqc-violation-message-security-reason'))
149
+				->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM);
150 150
 			$status = CheckResult::STATUS_TODO;
151 151
 		}
152
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
152
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
153 153
 	}
154 154
 
155
-	public function checkConstraintParameters( Constraint $constraint ) {
155
+	public function checkConstraintParameters(Constraint $constraint) {
156 156
 		$constraintParameters = $constraint->getConstraintParameters();
157 157
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
158 158
 		$exceptions = [];
@@ -161,14 +161,14 @@  discard block
 block discarded – undo
161 161
 				$constraintParameters,
162 162
 				$constraintTypeItemId
163 163
 			);
164
-		} catch ( ConstraintParameterException $e ) {
164
+		} catch (ConstraintParameterException $e) {
165 165
 			$exceptions[] = $e;
166 166
 		}
167 167
 		try {
168 168
 			$this->constraintParameterParser->parseSyntaxClarificationParameter(
169 169
 				$constraintParameters
170 170
 			);
171
-		} catch ( ConstraintParameterException $e ) {
171
+		} catch (ConstraintParameterException $e) {
172 172
 			$exceptions[] = $e;
173 173
 		}
174 174
 		return $exceptions;
Please login to merge, or discard this patch.