@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | private $lookup; |
23 | 23 | |
24 | - public function __construct( EntityLookup $lookup ) { |
|
24 | + public function __construct(EntityLookup $lookup) { |
|
25 | 25 | $this->lookup = $lookup; |
26 | 26 | } |
27 | 27 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | * @param EntityId $entityId |
33 | 33 | * @return EntityDocument|null |
34 | 34 | */ |
35 | - public function getEntity( EntityId $entityId ) { |
|
35 | + public function getEntity(EntityId $entityId) { |
|
36 | 36 | try { |
37 | - return $this->lookup->getEntity( $entityId ); |
|
38 | - } catch ( EntityLookupException $exception ) { |
|
37 | + return $this->lookup->getEntity($entityId); |
|
38 | + } catch (EntityLookupException $exception) { |
|
39 | 39 | return null; |
40 | 40 | } |
41 | 41 | } |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | * @param EntityId $entityId |
49 | 49 | * @return bool |
50 | 50 | */ |
51 | - public function hasEntity( EntityId $entityId ) { |
|
52 | - return $this->lookup->hasEntity( $entityId ); |
|
51 | + public function hasEntity(EntityId $entityId) { |
|
52 | + return $this->lookup->hasEntity($entityId); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | } |
@@ -32,9 +32,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -162,19 +162,19 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | ); |
@@ -36,196 +36,196 @@ |
||
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 | }, |
@@ -79,19 +79,19 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | ]; |
@@ -136,7 +136,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | * @param array $parameters |
79 | 79 | * @throws ConstraintParameterException |
80 | 80 | */ |
81 | - public function checkError( array $parameters ) { |
|
82 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
81 | + public function checkError(array $parameters) { |
|
82 | + if (array_key_exists('@error', $parameters)) { |
|
83 | 83 | $error = $parameters['@error']; |
84 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
84 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
85 | 85 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
86 | 86 | } else { |
87 | 87 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
88 | 88 | } |
89 | - throw new ConstraintParameterException( new ViolationMessage( $msg ) ); |
|
89 | + throw new ConstraintParameterException(new ViolationMessage($msg)); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | * @param string $parameterId |
97 | 97 | * @throws ConstraintParameterException |
98 | 98 | */ |
99 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
100 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
99 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
100 | + if (count($parameters[$parameterId]) !== 1) { |
|
101 | 101 | throw new ConstraintParameterException( |
102 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) ) |
|
103 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
102 | + (new ViolationMessage('wbqc-violation-message-parameter-single')) |
|
103 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
104 | 104 | ); |
105 | 105 | } |
106 | 106 | } |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * @return void |
113 | 113 | * @throws ConstraintParameterException |
114 | 114 | */ |
115 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
116 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
115 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
116 | + if (!($snak instanceof PropertyValueSnak)) { |
|
117 | 117 | throw new ConstraintParameterException( |
118 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
119 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
118 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
119 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
120 | 120 | ); |
121 | 121 | } |
122 | 122 | } |
@@ -128,17 +128,17 @@ discard block |
||
128 | 128 | * @throws ConstraintParameterException |
129 | 129 | * @return EntityId |
130 | 130 | */ |
131 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
132 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
133 | - $this->requireValueParameter( $snak, $parameterId ); |
|
131 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
132 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
133 | + $this->requireValueParameter($snak, $parameterId); |
|
134 | 134 | $value = $snak->getDataValue(); |
135 | - if ( $value instanceof EntityIdValue ) { |
|
135 | + if ($value instanceof EntityIdValue) { |
|
136 | 136 | return $value->getEntityId(); |
137 | 137 | } else { |
138 | 138 | throw new ConstraintParameterException( |
139 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) ) |
|
140 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
141 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
139 | + (new ViolationMessage('wbqc-violation-message-parameter-entity')) |
|
140 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
141 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
142 | 142 | ); |
143 | 143 | } |
144 | 144 | } |
@@ -149,20 +149,20 @@ discard block |
||
149 | 149 | * @throws ConstraintParameterException if the parameter is invalid or missing |
150 | 150 | * @return string[] class entity ID serializations |
151 | 151 | */ |
152 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
153 | - $this->checkError( $constraintParameters ); |
|
154 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
155 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
152 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
153 | + $this->checkError($constraintParameters); |
|
154 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
155 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
156 | 156 | throw new ConstraintParameterException( |
157 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
158 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
159 | - ->withEntityId( new PropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
157 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
158 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
159 | + ->withEntityId(new PropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
160 | 160 | ); |
161 | 161 | } |
162 | 162 | |
163 | 163 | $classes = []; |
164 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
165 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
164 | + foreach ($constraintParameters[$classId] as $class) { |
|
165 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
166 | 166 | } |
167 | 167 | return $classes; |
168 | 168 | } |
@@ -173,23 +173,23 @@ discard block |
||
173 | 173 | * @throws ConstraintParameterException if the parameter is invalid or missing |
174 | 174 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
175 | 175 | */ |
176 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
177 | - $this->checkError( $constraintParameters ); |
|
178 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
179 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
176 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
177 | + $this->checkError($constraintParameters); |
|
178 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
179 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
180 | 180 | throw new ConstraintParameterException( |
181 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
182 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
183 | - ->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
181 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
182 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
183 | + ->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
184 | 184 | ); |
185 | 185 | } |
186 | 186 | |
187 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
188 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
189 | - $instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ); |
|
190 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ); |
|
191 | - $instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ); |
|
192 | - switch ( $relationEntityId ) { |
|
187 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
188 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
189 | + $instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId'); |
|
190 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId'); |
|
191 | + $instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId'); |
|
192 | + switch ($relationEntityId) { |
|
193 | 193 | case $instanceId: |
194 | 194 | return 'instance'; |
195 | 195 | case $subclassId: |
@@ -198,13 +198,13 @@ discard block |
||
198 | 198 | return 'instanceOrSubclass'; |
199 | 199 | default: |
200 | 200 | throw new ConstraintParameterException( |
201 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
202 | - ->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
201 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
202 | + ->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
203 | 203 | ->withEntityIdList( |
204 | 204 | [ |
205 | - new ItemId( $instanceId ), |
|
206 | - new ItemId( $subclassId ), |
|
207 | - new ItemId( $instanceOrSubclassId ), |
|
205 | + new ItemId($instanceId), |
|
206 | + new ItemId($subclassId), |
|
207 | + new ItemId($instanceOrSubclassId), |
|
208 | 208 | ], |
209 | 209 | Role::CONSTRAINT_PARAMETER_VALUE |
210 | 210 | ) |
@@ -219,20 +219,20 @@ discard block |
||
219 | 219 | * @throws ConstraintParameterException |
220 | 220 | * @return PropertyId |
221 | 221 | */ |
222 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
223 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
224 | - $this->requireValueParameter( $snak, $parameterId ); |
|
222 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
223 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
224 | + $this->requireValueParameter($snak, $parameterId); |
|
225 | 225 | $value = $snak->getDataValue(); |
226 | - if ( $value instanceof EntityIdValue ) { |
|
226 | + if ($value instanceof EntityIdValue) { |
|
227 | 227 | $id = $value->getEntityId(); |
228 | - if ( $id instanceof PropertyId ) { |
|
228 | + if ($id instanceof PropertyId) { |
|
229 | 229 | return $id; |
230 | 230 | } |
231 | 231 | } |
232 | 232 | throw new ConstraintParameterException( |
233 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) ) |
|
234 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
235 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
233 | + (new ViolationMessage('wbqc-violation-message-parameter-property')) |
|
234 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
235 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
236 | 236 | ); |
237 | 237 | } |
238 | 238 | |
@@ -243,32 +243,32 @@ discard block |
||
243 | 243 | * @throws ConstraintParameterException if the parameter is invalid or missing |
244 | 244 | * @return PropertyId |
245 | 245 | */ |
246 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
247 | - $this->checkError( $constraintParameters ); |
|
248 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
249 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
246 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
247 | + $this->checkError($constraintParameters); |
|
248 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
249 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
250 | 250 | throw new ConstraintParameterException( |
251 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
252 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
253 | - ->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
251 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
252 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
253 | + ->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
254 | 254 | ); |
255 | 255 | } |
256 | 256 | |
257 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
258 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
257 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
258 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
259 | 259 | } |
260 | 260 | |
261 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
261 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
262 | 262 | $dataValue = $snak->getDataValue(); |
263 | - if ( $dataValue instanceof EntityIdValue && |
|
263 | + if ($dataValue instanceof EntityIdValue && |
|
264 | 264 | $dataValue->getEntityId() instanceof ItemId |
265 | 265 | ) { |
266 | - return ItemIdSnakValue::fromItemId( $dataValue->getEntityId() ); |
|
266 | + return ItemIdSnakValue::fromItemId($dataValue->getEntityId()); |
|
267 | 267 | } else { |
268 | 268 | throw new ConstraintParameterException( |
269 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
270 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
271 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
269 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
270 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
271 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
272 | 272 | ); |
273 | 273 | } |
274 | 274 | } |
@@ -287,16 +287,16 @@ discard block |
||
287 | 287 | $required, |
288 | 288 | $parameterId = null |
289 | 289 | ) { |
290 | - $this->checkError( $constraintParameters ); |
|
291 | - if ( $parameterId === null ) { |
|
292 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
290 | + $this->checkError($constraintParameters); |
|
291 | + if ($parameterId === null) { |
|
292 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
293 | 293 | } |
294 | - if ( !array_key_exists( $parameterId, $constraintParameters ) ) { |
|
295 | - if ( $required ) { |
|
294 | + if (!array_key_exists($parameterId, $constraintParameters)) { |
|
295 | + if ($required) { |
|
296 | 296 | throw new ConstraintParameterException( |
297 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
298 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
299 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
297 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
298 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
299 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
300 | 300 | ); |
301 | 301 | } else { |
302 | 302 | return []; |
@@ -304,11 +304,11 @@ discard block |
||
304 | 304 | } |
305 | 305 | |
306 | 306 | $values = []; |
307 | - foreach ( $constraintParameters[$parameterId] as $parameter ) { |
|
308 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
309 | - switch ( true ) { |
|
307 | + foreach ($constraintParameters[$parameterId] as $parameter) { |
|
308 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
309 | + switch (true) { |
|
310 | 310 | case $snak instanceof PropertyValueSnak: |
311 | - $values[] = $this->parseItemIdParameter( $snak, $parameterId ); |
|
311 | + $values[] = $this->parseItemIdParameter($snak, $parameterId); |
|
312 | 312 | break; |
313 | 313 | case $snak instanceof PropertySomeValueSnak: |
314 | 314 | $values[] = ItemIdSnakValue::someValue(); |
@@ -327,27 +327,27 @@ discard block |
||
327 | 327 | * @throws ConstraintParameterException if the parameter is invalid or missing |
328 | 328 | * @return PropertyId[] |
329 | 329 | */ |
330 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
331 | - $this->checkError( $constraintParameters ); |
|
332 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
333 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
330 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
331 | + $this->checkError($constraintParameters); |
|
332 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
333 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
334 | 334 | throw new ConstraintParameterException( |
335 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
336 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
337 | - ->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
335 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
336 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
337 | + ->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
338 | 338 | ); |
339 | 339 | } |
340 | 340 | |
341 | 341 | $parameters = $constraintParameters[$propertyId]; |
342 | - if ( count( $parameters ) === 1 && |
|
343 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
342 | + if (count($parameters) === 1 && |
|
343 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
344 | 344 | ) { |
345 | 345 | return []; |
346 | 346 | } |
347 | 347 | |
348 | 348 | $properties = []; |
349 | - foreach ( $parameters as $parameter ) { |
|
350 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
349 | + foreach ($parameters as $parameter) { |
|
350 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
351 | 351 | } |
352 | 352 | return $properties; |
353 | 353 | } |
@@ -358,16 +358,16 @@ discard block |
||
358 | 358 | * @throws ConstraintParameterException |
359 | 359 | * @return DataValue|null |
360 | 360 | */ |
361 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
362 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
363 | - if ( $snak instanceof PropertyValueSnak ) { |
|
361 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
362 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
363 | + if ($snak instanceof PropertyValueSnak) { |
|
364 | 364 | return $snak->getDataValue(); |
365 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
365 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
366 | 366 | return null; |
367 | 367 | } else { |
368 | 368 | throw new ConstraintParameterException( |
369 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
370 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
369 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
370 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
371 | 371 | ); |
372 | 372 | } |
373 | 373 | } |
@@ -377,10 +377,10 @@ discard block |
||
377 | 377 | * @param string $parameterId |
378 | 378 | * @return DataValue|null |
379 | 379 | */ |
380 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
380 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
381 | 381 | try { |
382 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
383 | - } catch ( ConstraintParameterException $e ) { |
|
382 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
383 | + } catch (ConstraintParameterException $e) { |
|
384 | 384 | // unknown value means “now” |
385 | 385 | return new NowValue(); |
386 | 386 | } |
@@ -393,14 +393,14 @@ discard block |
||
393 | 393 | * @param string $unit |
394 | 394 | * @return bool |
395 | 395 | */ |
396 | - private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) { |
|
397 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
398 | - !( $max instanceof UnboundedQuantityValue ) |
|
396 | + private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) { |
|
397 | + if (!($min instanceof UnboundedQuantityValue) || |
|
398 | + !($max instanceof UnboundedQuantityValue) |
|
399 | 399 | ) { |
400 | 400 | return false; |
401 | 401 | } |
402 | 402 | |
403 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
403 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -413,42 +413,42 @@ discard block |
||
413 | 413 | * @throws ConstraintParameterException if the parameter is invalid or missing |
414 | 414 | * @return DataValue[] if the parameter is invalid or missing |
415 | 415 | */ |
416 | - private function parseRangeParameter( array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type ) { |
|
417 | - $this->checkError( $constraintParameters ); |
|
418 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
419 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
416 | + private function parseRangeParameter(array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type) { |
|
417 | + $this->checkError($constraintParameters); |
|
418 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
419 | + !array_key_exists($maximumId, $constraintParameters) |
|
420 | 420 | ) { |
421 | 421 | throw new ConstraintParameterException( |
422 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) ) |
|
423 | - ->withDataValueType( $type ) |
|
424 | - ->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
425 | - ->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
426 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
422 | + (new ViolationMessage('wbqc-violation-message-range-parameters-needed')) |
|
423 | + ->withDataValueType($type) |
|
424 | + ->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
425 | + ->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
426 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
427 | 427 | ); |
428 | 428 | } |
429 | 429 | |
430 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
431 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
430 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
431 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
432 | 432 | $parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
433 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
434 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
433 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
434 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
435 | 435 | |
436 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
437 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
436 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
437 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
438 | 438 | throw new ConstraintParameterException( |
439 | - new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
439 | + new ViolationMessage('wbqc-violation-message-range-parameters-one-year') |
|
440 | 440 | ); |
441 | 441 | } |
442 | - if ( $min === null && $max === null || |
|
443 | - $min !== null && $max !== null && $min->equals( $max ) ) { |
|
442 | + if ($min === null && $max === null || |
|
443 | + $min !== null && $max !== null && $min->equals($max)) { |
|
444 | 444 | throw new ConstraintParameterException( |
445 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) ) |
|
446 | - ->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
447 | - ->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
445 | + (new ViolationMessage('wbqc-violation-message-range-parameters-same')) |
|
446 | + ->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
447 | + ->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
448 | 448 | ); |
449 | 449 | } |
450 | 450 | |
451 | - return [ $min, $max ]; |
|
451 | + return [$min, $max]; |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
@@ -458,11 +458,11 @@ discard block |
||
458 | 458 | * @throws ConstraintParameterException if the parameter is invalid or missing |
459 | 459 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
460 | 460 | */ |
461 | - public function parseQuantityRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
461 | + public function parseQuantityRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
462 | 462 | return $this->parseRangeParameter( |
463 | 463 | $constraintParameters, |
464 | - $this->config->get( 'WBQualityConstraintsMinimumQuantityId' ), |
|
465 | - $this->config->get( 'WBQualityConstraintsMaximumQuantityId' ), |
|
464 | + $this->config->get('WBQualityConstraintsMinimumQuantityId'), |
|
465 | + $this->config->get('WBQualityConstraintsMaximumQuantityId'), |
|
466 | 466 | $constraintTypeItemId, |
467 | 467 | 'quantity' |
468 | 468 | ); |
@@ -475,11 +475,11 @@ discard block |
||
475 | 475 | * @throws ConstraintParameterException if the parameter is invalid or missing |
476 | 476 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
477 | 477 | */ |
478 | - public function parseTimeRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
478 | + public function parseTimeRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
479 | 479 | return $this->parseRangeParameter( |
480 | 480 | $constraintParameters, |
481 | - $this->config->get( 'WBQualityConstraintsMinimumDateId' ), |
|
482 | - $this->config->get( 'WBQualityConstraintsMaximumDateId' ), |
|
481 | + $this->config->get('WBQualityConstraintsMinimumDateId'), |
|
482 | + $this->config->get('WBQualityConstraintsMaximumDateId'), |
|
483 | 483 | $constraintTypeItemId, |
484 | 484 | 'time' |
485 | 485 | ); |
@@ -492,17 +492,17 @@ discard block |
||
492 | 492 | * @throws ConstraintParameterException |
493 | 493 | * @return string |
494 | 494 | */ |
495 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
496 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
497 | - $this->requireValueParameter( $snak, $parameterId ); |
|
495 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
496 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
497 | + $this->requireValueParameter($snak, $parameterId); |
|
498 | 498 | $value = $snak->getDataValue(); |
499 | - if ( $value instanceof StringValue ) { |
|
499 | + if ($value instanceof StringValue) { |
|
500 | 500 | return $value->getValue(); |
501 | 501 | } else { |
502 | 502 | throw new ConstraintParameterException( |
503 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) ) |
|
504 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
505 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
503 | + (new ViolationMessage('wbqc-violation-message-parameter-string')) |
|
504 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
505 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
506 | 506 | ); |
507 | 507 | } |
508 | 508 | } |
@@ -513,15 +513,15 @@ discard block |
||
513 | 513 | * @throws ConstraintParameterException if the parameter is invalid or missing |
514 | 514 | * @return string |
515 | 515 | */ |
516 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
517 | - $this->checkError( $constraintParameters ); |
|
518 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
519 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
516 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
517 | + $this->checkError($constraintParameters); |
|
518 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
519 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
520 | 520 | return ''; |
521 | 521 | } |
522 | 522 | |
523 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
524 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
523 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
524 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -530,19 +530,19 @@ discard block |
||
530 | 530 | * @throws ConstraintParameterException if the parameter is invalid or missing |
531 | 531 | * @return string |
532 | 532 | */ |
533 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
534 | - $this->checkError( $constraintParameters ); |
|
535 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
536 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
533 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
534 | + $this->checkError($constraintParameters); |
|
535 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
536 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
537 | 537 | throw new ConstraintParameterException( |
538 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
539 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
540 | - ->withEntityId( new PropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
538 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
539 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
540 | + ->withEntityId(new PropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
541 | 541 | ); |
542 | 542 | } |
543 | 543 | |
544 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
545 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
544 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
545 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -550,16 +550,16 @@ discard block |
||
550 | 550 | * @throws ConstraintParameterException if the parameter is invalid |
551 | 551 | * @return EntityId[] |
552 | 552 | */ |
553 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
554 | - $this->checkError( $constraintParameters ); |
|
555 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
556 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
553 | + public function parseExceptionParameter(array $constraintParameters) { |
|
554 | + $this->checkError($constraintParameters); |
|
555 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
556 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
557 | 557 | return []; |
558 | 558 | } |
559 | 559 | |
560 | 560 | return array_map( |
561 | - function( $snakSerialization ) use ( $exceptionId ) { |
|
562 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
561 | + function($snakSerialization) use ($exceptionId) { |
|
562 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
563 | 563 | }, |
564 | 564 | $constraintParameters[$exceptionId] |
565 | 565 | ); |
@@ -570,35 +570,35 @@ discard block |
||
570 | 570 | * @throws ConstraintParameterException if the parameter is invalid |
571 | 571 | * @return string|null 'mandatory', 'suggestion' or null |
572 | 572 | */ |
573 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
574 | - $this->checkError( $constraintParameters ); |
|
575 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
576 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
573 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
574 | + $this->checkError($constraintParameters); |
|
575 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
576 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
577 | 577 | return null; |
578 | 578 | } |
579 | 579 | |
580 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
581 | - $supportedStatuses = [ new ItemId( $mandatoryId ) ]; |
|
582 | - if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) { |
|
583 | - $suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' ); |
|
584 | - $supportedStatuses[] = new ItemId( $suggestionId ); |
|
580 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
581 | + $supportedStatuses = [new ItemId($mandatoryId)]; |
|
582 | + if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) { |
|
583 | + $suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId'); |
|
584 | + $supportedStatuses[] = new ItemId($suggestionId); |
|
585 | 585 | } else { |
586 | 586 | $suggestionId = null; |
587 | 587 | } |
588 | 588 | |
589 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
590 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
591 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
589 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
590 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
591 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
592 | 592 | $statusId = $snak->getDataValue()->getEntityId()->getSerialization(); |
593 | 593 | |
594 | - if ( $statusId === $mandatoryId ) { |
|
594 | + if ($statusId === $mandatoryId) { |
|
595 | 595 | return 'mandatory'; |
596 | - } elseif ( $statusId === $suggestionId ) { |
|
596 | + } elseif ($statusId === $suggestionId) { |
|
597 | 597 | return 'suggestion'; |
598 | 598 | } else { |
599 | 599 | throw new ConstraintParameterException( |
600 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
601 | - ->withEntityId( new PropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
600 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
601 | + ->withEntityId(new PropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
602 | 602 | ->withEntityIdList( |
603 | 603 | $supportedStatuses, |
604 | 604 | Role::CONSTRAINT_PARAMETER_VALUE |
@@ -614,12 +614,12 @@ discard block |
||
614 | 614 | * @return void |
615 | 615 | * @throws ConstraintParameterException |
616 | 616 | */ |
617 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
618 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
617 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
618 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
619 | 619 | throw new ConstraintParameterException( |
620 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) ) |
|
621 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
622 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
620 | + (new ViolationMessage('wbqc-violation-message-parameter-monolingualtext')) |
|
621 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
622 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
623 | 623 | ); |
624 | 624 | } |
625 | 625 | } |
@@ -632,30 +632,30 @@ discard block |
||
632 | 632 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
633 | 633 | * @return MultilingualTextValue |
634 | 634 | */ |
635 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
635 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
636 | 636 | $result = []; |
637 | 637 | |
638 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
639 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
640 | - $this->requireValueParameter( $snak, $parameterId ); |
|
638 | + foreach ($snakSerializations as $snakSerialization) { |
|
639 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
640 | + $this->requireValueParameter($snak, $parameterId); |
|
641 | 641 | |
642 | 642 | $value = $snak->getDataValue(); |
643 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
643 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
644 | 644 | /** @var MonolingualTextValue $value */ |
645 | 645 | |
646 | 646 | $code = $value->getLanguageCode(); |
647 | - if ( array_key_exists( $code, $result ) ) { |
|
647 | + if (array_key_exists($code, $result)) { |
|
648 | 648 | throw new ConstraintParameterException( |
649 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) ) |
|
650 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
651 | - ->withLanguage( $code ) |
|
649 | + (new ViolationMessage('wbqc-violation-message-parameter-single-per-language')) |
|
650 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
651 | + ->withLanguage($code) |
|
652 | 652 | ); |
653 | 653 | } |
654 | 654 | |
655 | 655 | $result[$code] = $value; |
656 | 656 | } |
657 | 657 | |
658 | - return new MultilingualTextValue( $result ); |
|
658 | + return new MultilingualTextValue($result); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | /** |
@@ -663,11 +663,11 @@ discard block |
||
663 | 663 | * @throws ConstraintParameterException if the parameter is invalid |
664 | 664 | * @return MultilingualTextValue |
665 | 665 | */ |
666 | - public function parseSyntaxClarificationParameter( array $constraintParameters ) { |
|
667 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
666 | + public function parseSyntaxClarificationParameter(array $constraintParameters) { |
|
667 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
668 | 668 | |
669 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
670 | - return new MultilingualTextValue( [] ); |
|
669 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
670 | + return new MultilingualTextValue([]); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -686,9 +686,9 @@ discard block |
||
686 | 686 | * @throws ConstraintParameterException if the parameter is invalid |
687 | 687 | * @return string[]|null Context::TYPE_* constants |
688 | 688 | */ |
689 | - public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) { |
|
689 | + public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) { |
|
690 | 690 | $contextTypes = []; |
691 | - $parameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
691 | + $parameterId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
692 | 692 | $items = $this->parseItemsParameter( |
693 | 693 | $constraintParameters, |
694 | 694 | $constraintTypeItemId, |
@@ -696,23 +696,23 @@ discard block |
||
696 | 696 | $parameterId |
697 | 697 | ); |
698 | 698 | |
699 | - if ( $items === [] ) { |
|
699 | + if ($items === []) { |
|
700 | 700 | return null; |
701 | 701 | } |
702 | 702 | |
703 | - foreach ( $items as $item ) { |
|
704 | - $contextTypes[] = $this->parseContextTypeItem( $item, 'constraint scope', $parameterId ); |
|
703 | + foreach ($items as $item) { |
|
704 | + $contextTypes[] = $this->parseContextTypeItem($item, 'constraint scope', $parameterId); |
|
705 | 705 | } |
706 | 706 | |
707 | - if ( $validScopes !== null ) { |
|
708 | - $invalidScopes = array_diff( $contextTypes, $validScopes ); |
|
709 | - if ( $invalidScopes !== [] ) { |
|
710 | - $invalidScope = array_pop( $invalidScopes ); |
|
707 | + if ($validScopes !== null) { |
|
708 | + $invalidScopes = array_diff($contextTypes, $validScopes); |
|
709 | + if ($invalidScopes !== []) { |
|
710 | + $invalidScope = array_pop($invalidScopes); |
|
711 | 711 | throw new ConstraintParameterException( |
712 | - ( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) ) |
|
713 | - ->withConstraintScope( $invalidScope, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
714 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
715 | - ->withConstraintScopeList( $validScopes, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
712 | + (new ViolationMessage('wbqc-violation-message-invalid-scope')) |
|
713 | + ->withConstraintScope($invalidScope, Role::CONSTRAINT_PARAMETER_VALUE) |
|
714 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
715 | + ->withConstraintScopeList($validScopes, Role::CONSTRAINT_PARAMETER_VALUE) |
|
716 | 716 | ); |
717 | 717 | } |
718 | 718 | } |
@@ -726,15 +726,15 @@ discard block |
||
726 | 726 | * @param ItemId $unitId |
727 | 727 | * @return string unit |
728 | 728 | */ |
729 | - private function parseUnitParameter( ItemId $unitId ) { |
|
729 | + private function parseUnitParameter(ItemId $unitId) { |
|
730 | 730 | $unitRepositoryName = $unitId->getRepositoryName(); |
731 | - if ( !array_key_exists( $unitRepositoryName, $this->conceptBaseUris ) ) { |
|
731 | + if (!array_key_exists($unitRepositoryName, $this->conceptBaseUris)) { |
|
732 | 732 | throw new LogicException( |
733 | - 'No base URI for concept URI for repository: ' . $unitRepositoryName |
|
733 | + 'No base URI for concept URI for repository: '.$unitRepositoryName |
|
734 | 734 | ); |
735 | 735 | } |
736 | 736 | $baseUri = $this->conceptBaseUris[$unitRepositoryName]; |
737 | - return $baseUri . $unitId->getSerialization(); |
|
737 | + return $baseUri.$unitId->getSerialization(); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | /** |
@@ -744,23 +744,23 @@ discard block |
||
744 | 744 | * @return UnitsParameter |
745 | 745 | * @throws ConstraintParameterException |
746 | 746 | */ |
747 | - private function parseUnitItem( ItemIdSnakValue $item ) { |
|
748 | - switch ( true ) { |
|
747 | + private function parseUnitItem(ItemIdSnakValue $item) { |
|
748 | + switch (true) { |
|
749 | 749 | case $item->isValue(): |
750 | - $unit = $this->parseUnitParameter( $item->getItemId() ); |
|
750 | + $unit = $this->parseUnitParameter($item->getItemId()); |
|
751 | 751 | return new UnitsParameter( |
752 | - [ $item->getItemId() ], |
|
753 | - [ UnboundedQuantityValue::newFromNumber( 1, $unit ) ], |
|
752 | + [$item->getItemId()], |
|
753 | + [UnboundedQuantityValue::newFromNumber(1, $unit)], |
|
754 | 754 | false |
755 | 755 | ); |
756 | 756 | case $item->isSomeValue(): |
757 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
757 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
758 | 758 | throw new ConstraintParameterException( |
759 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
760 | - ->withEntityId( new PropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
759 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
760 | + ->withEntityId(new PropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
761 | 761 | ); |
762 | 762 | case $item->isNoValue(): |
763 | - return new UnitsParameter( [], [], true ); |
|
763 | + return new UnitsParameter([], [], true); |
|
764 | 764 | } |
765 | 765 | } |
766 | 766 | |
@@ -770,26 +770,26 @@ discard block |
||
770 | 770 | * @throws ConstraintParameterException if the parameter is invalid or missing |
771 | 771 | * @return UnitsParameter |
772 | 772 | */ |
773 | - public function parseUnitsParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
774 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
773 | + public function parseUnitsParameter(array $constraintParameters, $constraintTypeItemId) { |
|
774 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
775 | 775 | $unitItems = []; |
776 | 776 | $unitQuantities = []; |
777 | 777 | $unitlessAllowed = false; |
778 | 778 | |
779 | - foreach ( $items as $item ) { |
|
780 | - $unit = $this->parseUnitItem( $item ); |
|
781 | - $unitItems = array_merge( $unitItems, $unit->getUnitItemIds() ); |
|
782 | - $unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() ); |
|
779 | + foreach ($items as $item) { |
|
780 | + $unit = $this->parseUnitItem($item); |
|
781 | + $unitItems = array_merge($unitItems, $unit->getUnitItemIds()); |
|
782 | + $unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities()); |
|
783 | 783 | $unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed(); |
784 | 784 | } |
785 | 785 | |
786 | - if ( $unitQuantities === [] && !$unitlessAllowed ) { |
|
786 | + if ($unitQuantities === [] && !$unitlessAllowed) { |
|
787 | 787 | throw new LogicException( |
788 | 788 | 'The "units" parameter is required, and yet we seem to be missing any allowed unit' |
789 | 789 | ); |
790 | 790 | } |
791 | 791 | |
792 | - return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed ); |
|
792 | + return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | /** |
@@ -799,49 +799,49 @@ discard block |
||
799 | 799 | * @return EntityTypesParameter |
800 | 800 | * @throws ConstraintParameterException |
801 | 801 | */ |
802 | - private function parseEntityTypeItem( ItemIdSnakValue $item ) { |
|
803 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
802 | + private function parseEntityTypeItem(ItemIdSnakValue $item) { |
|
803 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
804 | 804 | |
805 | - if ( !$item->isValue() ) { |
|
805 | + if (!$item->isValue()) { |
|
806 | 806 | throw new ConstraintParameterException( |
807 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
808 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
807 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
808 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
809 | 809 | ); |
810 | 810 | } |
811 | 811 | |
812 | 812 | $itemId = $item->getItemId(); |
813 | - switch ( $itemId->getSerialization() ) { |
|
814 | - case $this->config->get( 'WBQualityConstraintsWikibaseItemId' ): |
|
813 | + switch ($itemId->getSerialization()) { |
|
814 | + case $this->config->get('WBQualityConstraintsWikibaseItemId'): |
|
815 | 815 | $entityType = 'item'; |
816 | 816 | break; |
817 | - case $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ): |
|
817 | + case $this->config->get('WBQualityConstraintsWikibasePropertyId'): |
|
818 | 818 | $entityType = 'property'; |
819 | 819 | break; |
820 | - case $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ): |
|
820 | + case $this->config->get('WBQualityConstraintsWikibaseLexemeId'): |
|
821 | 821 | $entityType = 'lexeme'; |
822 | 822 | break; |
823 | - case $this->config->get( 'WBQualityConstraintsWikibaseFormId' ): |
|
823 | + case $this->config->get('WBQualityConstraintsWikibaseFormId'): |
|
824 | 824 | $entityType = 'form'; |
825 | 825 | break; |
826 | - case $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ): |
|
826 | + case $this->config->get('WBQualityConstraintsWikibaseSenseId'): |
|
827 | 827 | $entityType = 'sense'; |
828 | 828 | break; |
829 | 829 | default: |
830 | 830 | $allowed = [ |
831 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseItemId' ) ), |
|
832 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) ), |
|
833 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) ), |
|
834 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseFormId' ) ), |
|
835 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) ), |
|
831 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseItemId')), |
|
832 | + new ItemId($this->config->get('WBQualityConstraintsWikibasePropertyId')), |
|
833 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseLexemeId')), |
|
834 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseFormId')), |
|
835 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseSenseId')), |
|
836 | 836 | ]; |
837 | 837 | throw new ConstraintParameterException( |
838 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
839 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
840 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
838 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
839 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
840 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
841 | 841 | ); |
842 | 842 | } |
843 | 843 | |
844 | - return new EntityTypesParameter( [ $entityType ], [ $itemId ] ); |
|
844 | + return new EntityTypesParameter([$entityType], [$itemId]); |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | /** |
@@ -850,27 +850,27 @@ discard block |
||
850 | 850 | * @throws ConstraintParameterException if the parameter is invalid or missing |
851 | 851 | * @return EntityTypesParameter |
852 | 852 | */ |
853 | - public function parseEntityTypesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
853 | + public function parseEntityTypesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
854 | 854 | $entityTypes = []; |
855 | 855 | $entityTypeItemIds = []; |
856 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
856 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
857 | 857 | |
858 | - foreach ( $items as $item ) { |
|
859 | - $entityType = $this->parseEntityTypeItem( $item ); |
|
860 | - $entityTypes = array_merge( $entityTypes, $entityType->getEntityTypes() ); |
|
861 | - $entityTypeItemIds = array_merge( $entityTypeItemIds, $entityType->getEntityTypeItemIds() ); |
|
858 | + foreach ($items as $item) { |
|
859 | + $entityType = $this->parseEntityTypeItem($item); |
|
860 | + $entityTypes = array_merge($entityTypes, $entityType->getEntityTypes()); |
|
861 | + $entityTypeItemIds = array_merge($entityTypeItemIds, $entityType->getEntityTypeItemIds()); |
|
862 | 862 | } |
863 | 863 | |
864 | - if ( empty( $entityTypes ) ) { |
|
864 | + if (empty($entityTypes)) { |
|
865 | 865 | // @codeCoverageIgnoreStart |
866 | 866 | throw new LogicException( |
867 | - 'The "entity types" parameter is required, ' . |
|
867 | + 'The "entity types" parameter is required, '. |
|
868 | 868 | 'and yet we seem to be missing any allowed entity type' |
869 | 869 | ); |
870 | 870 | // @codeCoverageIgnoreEnd |
871 | 871 | } |
872 | 872 | |
873 | - return new EntityTypesParameter( $entityTypes, $entityTypeItemIds ); |
|
873 | + return new EntityTypesParameter($entityTypes, $entityTypeItemIds); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | /** |
@@ -878,18 +878,18 @@ discard block |
||
878 | 878 | * @throws ConstraintParameterException if the parameter is invalid |
879 | 879 | * @return PropertyId[] |
880 | 880 | */ |
881 | - public function parseSeparatorsParameter( array $constraintParameters ) { |
|
882 | - $separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' ); |
|
881 | + public function parseSeparatorsParameter(array $constraintParameters) { |
|
882 | + $separatorId = $this->config->get('WBQualityConstraintsSeparatorId'); |
|
883 | 883 | |
884 | - if ( !array_key_exists( $separatorId, $constraintParameters ) ) { |
|
884 | + if (!array_key_exists($separatorId, $constraintParameters)) { |
|
885 | 885 | return []; |
886 | 886 | } |
887 | 887 | |
888 | 888 | $parameters = $constraintParameters[$separatorId]; |
889 | 889 | $separators = []; |
890 | 890 | |
891 | - foreach ( $parameters as $parameter ) { |
|
892 | - $separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId ); |
|
891 | + foreach ($parameters as $parameter) { |
|
892 | + $separators[] = $this->parsePropertyIdParameter($parameter, $separatorId); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | return $separators; |
@@ -904,26 +904,26 @@ discard block |
||
904 | 904 | * @return string one of the Context::TYPE_* constants |
905 | 905 | * @throws ConstraintParameterException |
906 | 906 | */ |
907 | - private function parseContextTypeItem( ItemIdSnakValue $item, $use, $parameterId ) { |
|
908 | - if ( !$item->isValue() ) { |
|
907 | + private function parseContextTypeItem(ItemIdSnakValue $item, $use, $parameterId) { |
|
908 | + if (!$item->isValue()) { |
|
909 | 909 | throw new ConstraintParameterException( |
910 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
911 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
910 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
911 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
912 | 912 | ); |
913 | 913 | } |
914 | 914 | |
915 | - if ( $use === 'constraint scope' ) { |
|
916 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ); |
|
917 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ); |
|
918 | - $referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ); |
|
915 | + if ($use === 'constraint scope') { |
|
916 | + $mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId'); |
|
917 | + $qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId'); |
|
918 | + $referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId'); |
|
919 | 919 | } else { |
920 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
921 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
922 | - $referencesId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
920 | + $mainSnakId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
921 | + $qualifiersId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
922 | + $referencesId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
923 | 923 | } |
924 | 924 | |
925 | 925 | $itemId = $item->getItemId(); |
926 | - switch ( $itemId->getSerialization() ) { |
|
926 | + switch ($itemId->getSerialization()) { |
|
927 | 927 | case $mainSnakId: |
928 | 928 | return Context::TYPE_STATEMENT; |
929 | 929 | case $qualifiersId: |
@@ -931,11 +931,11 @@ discard block |
||
931 | 931 | case $referencesId: |
932 | 932 | return Context::TYPE_REFERENCE; |
933 | 933 | default: |
934 | - $allowed = [ $mainSnakId, $qualifiersId, $referencesId ]; |
|
934 | + $allowed = [$mainSnakId, $qualifiersId, $referencesId]; |
|
935 | 935 | throw new ConstraintParameterException( |
936 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
937 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
938 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
936 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
937 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
938 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
939 | 939 | ); |
940 | 940 | } |
941 | 941 | } |
@@ -946,9 +946,9 @@ discard block |
||
946 | 946 | * @throws ConstraintParameterException if the parameter is invalid or missing |
947 | 947 | * @return string[] list of Context::TYPE_* constants |
948 | 948 | */ |
949 | - public function parsePropertyScopeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
949 | + public function parsePropertyScopeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
950 | 950 | $contextTypes = []; |
951 | - $parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' ); |
|
951 | + $parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId'); |
|
952 | 952 | $items = $this->parseItemsParameter( |
953 | 953 | $constraintParameters, |
954 | 954 | $constraintTypeItemId, |
@@ -956,14 +956,14 @@ discard block |
||
956 | 956 | $parameterId |
957 | 957 | ); |
958 | 958 | |
959 | - foreach ( $items as $item ) { |
|
960 | - $contextTypes[] = $this->parseContextTypeItem( $item, 'property scope', $parameterId ); |
|
959 | + foreach ($items as $item) { |
|
960 | + $contextTypes[] = $this->parseContextTypeItem($item, 'property scope', $parameterId); |
|
961 | 961 | } |
962 | 962 | |
963 | - if ( empty( $contextTypes ) ) { |
|
963 | + if (empty($contextTypes)) { |
|
964 | 964 | // @codeCoverageIgnoreStart |
965 | 965 | throw new LogicException( |
966 | - 'The "property scope" parameter is required, ' . |
|
966 | + 'The "property scope" parameter is required, '. |
|
967 | 967 | 'and yet we seem to be missing any allowed scope' |
968 | 968 | ); |
969 | 969 | // @codeCoverageIgnoreEnd |
@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param DatabaseUpdater $updater |
30 | 30 | */ |
31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
32 | 32 | $updater->addExtensionTable( |
33 | 33 | 'wbqc_constraints', |
34 | - __DIR__ . '/../sql/create_wbqc_constraints.sql' |
|
34 | + __DIR__.'/../sql/create_wbqc_constraints.sql' |
|
35 | 35 | ); |
36 | 36 | $updater->addExtensionField( |
37 | 37 | 'wbqc_constraints', |
38 | 38 | 'constraint_id', |
39 | - __DIR__ . '/../sql/patch-wbqc_constraints-constraint_id.sql' |
|
39 | + __DIR__.'/../sql/patch-wbqc_constraints-constraint_id.sql' |
|
40 | 40 | ); |
41 | 41 | $updater->addExtensionIndex( |
42 | 42 | 'wbqc_constraints', |
43 | 43 | 'wbqc_constraints_guid_uniq', |
44 | - __DIR__ . '/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
44 | + __DIR__.'/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
45 | 45 | ); |
46 | 46 | } |
47 | 47 | |
48 | - public static function onWikibaseChange( Change $change ) { |
|
49 | - if ( !( $change instanceof EntityChange ) ) { |
|
48 | + public static function onWikibaseChange(Change $change) { |
|
49 | + if (!($change instanceof EntityChange)) { |
|
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
@@ -55,44 +55,44 @@ discard block |
||
55 | 55 | |
56 | 56 | // If jobs are enabled and the results would be stored in some way run a job. |
57 | 57 | if ( |
58 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
59 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
58 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
59 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
60 | 60 | self::isSelectedForJobRunBasedOnPercentage() |
61 | 61 | ) { |
62 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
62 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
63 | 63 | JobQueueGroup::singleton()->push( |
64 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
64 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
65 | 65 | ); |
66 | 66 | } |
67 | 67 | |
68 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
69 | - self::isConstraintStatementsChange( $config, $change ) |
|
68 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
69 | + self::isConstraintStatementsChange($config, $change) |
|
70 | 70 | ) { |
71 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
71 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
72 | 72 | JobQueueGroup::singleton()->push( |
73 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
73 | + new JobSpecification('constraintsTableUpdate', $params) |
|
74 | 74 | ); |
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
78 | 78 | private static function isSelectedForJobRunBasedOnPercentage() { |
79 | 79 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
80 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
80 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
81 | 81 | |
82 | - return mt_rand( 1, 100 ) <= $percentage; |
|
82 | + return mt_rand(1, 100) <= $percentage; |
|
83 | 83 | } |
84 | 84 | |
85 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
86 | - if ( !( $change instanceof EntityChange ) || |
|
85 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
86 | + if (!($change instanceof EntityChange) || |
|
87 | 87 | $change->getAction() !== EntityChange::UPDATE || |
88 | - !( $change->getEntityId() instanceof PropertyId ) |
|
88 | + !($change->getEntityId() instanceof PropertyId) |
|
89 | 89 | ) { |
90 | 90 | return false; |
91 | 91 | } |
92 | 92 | |
93 | 93 | $info = $change->getInfo(); |
94 | 94 | |
95 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
95 | + if (!array_key_exists('compactDiff', $info)) { |
|
96 | 96 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
97 | 97 | // so we only know that the change *might* affect the constraint statements |
98 | 98 | return true; |
@@ -101,46 +101,46 @@ discard block |
||
101 | 101 | /** @var EntityDiffChangedAspects $aspects */ |
102 | 102 | $aspects = $info['compactDiff']; |
103 | 103 | |
104 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
105 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
104 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
105 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
106 | 106 | } |
107 | 107 | |
108 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
108 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
109 | 109 | $repo = WikibaseRepo::getDefaultInstance(); |
110 | 110 | |
111 | 111 | $entityContentFactory = $repo->getEntityContentFactory(); |
112 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
113 | - $entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
114 | - if ( $entityId !== null ) { |
|
112 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
113 | + $entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle()); |
|
114 | + if ($entityId !== null) { |
|
115 | 115 | $resultsCache = ResultsCache::getDefaultInstance(); |
116 | - $resultsCache->delete( $entityId ); |
|
116 | + $resultsCache->delete($entityId); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
121 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
122 | 122 | $repo = WikibaseRepo::getDefaultInstance(); |
123 | 123 | |
124 | 124 | $lookup = $repo->getEntityNamespaceLookup(); |
125 | 125 | $title = $out->getTitle(); |
126 | - if ( $title === null ) { |
|
126 | + if ($title === null) { |
|
127 | 127 | return; |
128 | 128 | } |
129 | 129 | |
130 | - if ( !$lookup->isEntityNamespace( $title->getNamespace() ) ) { |
|
130 | + if (!$lookup->isEntityNamespace($title->getNamespace())) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
133 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
137 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
138 | 138 | |
139 | - if ( !$out->getUser()->isLoggedIn() ) { |
|
139 | + if (!$out->getUser()->isLoggedIn()) { |
|
140 | 140 | return; |
141 | 141 | } |
142 | 142 | |
143 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
143 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | } |
@@ -74,19 +74,19 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | ]; |