@@ -24,7 +24,7 @@ |
||
24 | 24 | * @param bool $bool |
25 | 25 | * @param Metadata $metadata |
26 | 26 | */ |
27 | - public function __construct( $bool, Metadata $metadata ) { |
|
27 | + public function __construct($bool, Metadata $metadata) { |
|
28 | 28 | $this->bool = $bool; |
29 | 29 | $this->metadata = $metadata; |
30 | 30 | } |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | return $ret; |
33 | 33 | } |
34 | 34 | |
35 | - public static function ofCachingMetadata( CachingMetadata $cachingMetadata ) { |
|
35 | + public static function ofCachingMetadata(CachingMetadata $cachingMetadata) { |
|
36 | 36 | $ret = new self; |
37 | 37 | $ret->cachingMetadata = $cachingMetadata; |
38 | 38 | $ret->dependencyMetadata = DependencyMetadata::blank(); |
39 | 39 | return $ret; |
40 | 40 | } |
41 | 41 | |
42 | - public static function ofDependencyMetadata( DependencyMetadata $dependencyMetadata ) { |
|
42 | + public static function ofDependencyMetadata(DependencyMetadata $dependencyMetadata) { |
|
43 | 43 | $ret = new self; |
44 | 44 | $ret->cachingMetadata = CachingMetadata::fresh(); |
45 | 45 | $ret->dependencyMetadata = $dependencyMetadata; |
@@ -50,17 +50,17 @@ discard block |
||
50 | 50 | * @param self[] $metadatas |
51 | 51 | * @return self |
52 | 52 | */ |
53 | - public static function merge( array $metadatas ) { |
|
54 | - Assert::parameterElementType( self::class, $metadatas, '$metadatas' ); |
|
53 | + public static function merge(array $metadatas) { |
|
54 | + Assert::parameterElementType(self::class, $metadatas, '$metadatas'); |
|
55 | 55 | $cachingMetadatas = []; |
56 | 56 | $dependencyMetadatas = []; |
57 | - foreach ( $metadatas as $metadata ) { |
|
57 | + foreach ($metadatas as $metadata) { |
|
58 | 58 | $cachingMetadatas[] = $metadata->cachingMetadata; |
59 | 59 | $dependencyMetadatas[] = $metadata->dependencyMetadata; |
60 | 60 | } |
61 | 61 | $ret = new self; |
62 | - $ret->cachingMetadata = CachingMetadata::merge( $cachingMetadatas ); |
|
63 | - $ret->dependencyMetadata = DependencyMetadata::merge( $dependencyMetadatas ); |
|
62 | + $ret->cachingMetadata = CachingMetadata::merge($cachingMetadatas); |
|
63 | + $ret->dependencyMetadata = DependencyMetadata::merge($dependencyMetadatas); |
|
64 | 64 | return $ret; |
65 | 65 | } |
66 | 66 |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * @param int $maxAge The maximum age of the cached value (in seconds). |
30 | 30 | * @return self Indication that a value is possibly outdated by up to this many seconds. |
31 | 31 | */ |
32 | - public static function ofMaximumAgeInSeconds( $maxAge ) { |
|
33 | - Assert::parameterType( 'integer', $maxAge, '$maxAge' ); |
|
34 | - Assert::parameter( $maxAge > 0, '$maxAge', '$maxage > 0' ); |
|
32 | + public static function ofMaximumAgeInSeconds($maxAge) { |
|
33 | + Assert::parameterType('integer', $maxAge, '$maxAge'); |
|
34 | + Assert::parameter($maxAge > 0, '$maxAge', '$maxage > 0'); |
|
35 | 35 | $ret = new self; |
36 | 36 | $ret->maxAge = $maxAge; |
37 | 37 | return $ret; |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * @param array|null $array As returned by toArray. |
43 | 43 | * @return CachingMetadata |
44 | 44 | */ |
45 | - public static function ofArray( array $array = null ) { |
|
45 | + public static function ofArray(array $array = null) { |
|
46 | 46 | $ret = new self; |
47 | - if ( $array !== null ) { |
|
47 | + if ($array !== null) { |
|
48 | 48 | $ret->maxAge = $array['maximumAgeInSeconds']; |
49 | 49 | } |
50 | 50 | return $ret; |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | * @param self[] $metadatas |
55 | 55 | * @return self |
56 | 56 | */ |
57 | - public static function merge( array $metadatas ) { |
|
58 | - Assert::parameterElementType( self::class, $metadatas, '$metadatas' ); |
|
57 | + public static function merge(array $metadatas) { |
|
58 | + Assert::parameterElementType(self::class, $metadatas, '$metadatas'); |
|
59 | 59 | $ret = new self; |
60 | - foreach ( $metadatas as $metadata ) { |
|
61 | - $ret->maxAge = max( $ret->maxAge, $metadata->maxAge ); |
|
60 | + foreach ($metadatas as $metadata) { |
|
61 | + $ret->maxAge = max($ret->maxAge, $metadata->maxAge); |
|
62 | 62 | } |
63 | 63 | return $ret; |
64 | 64 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * For a fresh value, returns 0. |
77 | 77 | */ |
78 | 78 | public function getMaximumAgeInSeconds() { |
79 | - if ( is_int( $this->maxAge ) ) { |
|
79 | + if (is_int($this->maxAge)) { |
|
80 | 80 | return $this->maxAge; |
81 | 81 | } else { |
82 | 82 | return 0; |
@@ -91,8 +91,7 @@ discard block |
||
91 | 91 | return $this->isCached() ? |
92 | 92 | [ |
93 | 93 | 'maximumAgeInSeconds' => $this->maxAge, |
94 | - ] : |
|
95 | - null; |
|
94 | + ] : null; |
|
96 | 95 | } |
97 | 96 | |
98 | 97 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | public static function getDefaultInstance() { |
132 | 132 | static $instance = null; |
133 | 133 | |
134 | - if ( $instance === null ) { |
|
134 | + if ($instance === null) { |
|
135 | 135 | $wikibaseRepo = WikibaseRepo::getDefaultInstance(); |
136 | 136 | $entityIdFormatter = $wikibaseRepo->getEntityIdHtmlLinkFormatterFactory()->getEntityIdFormatter( |
137 | 137 | $wikibaseRepo->getLanguageFallbackLabelDescriptionLookupFactory()->newLabelDescriptionLookup( |
@@ -196,21 +196,21 @@ discard block |
||
196 | 196 | * @return DelegatingConstraintChecker |
197 | 197 | */ |
198 | 198 | public function getConstraintChecker() { |
199 | - if ( $this->delegatingConstraintChecker === null ) { |
|
199 | + if ($this->delegatingConstraintChecker === null) { |
|
200 | 200 | $this->delegatingConstraintChecker = new DelegatingConstraintChecker( |
201 | 201 | $this->lookup, |
202 | 202 | $this->getConstraintCheckerMap(), |
203 | - new CachingConstraintLookup( $this->getConstraintRepository() ), |
|
203 | + new CachingConstraintLookup($this->getConstraintRepository()), |
|
204 | 204 | $this->constraintParameterParser, |
205 | 205 | $this->statementGuidParser, |
206 | 206 | new LoggingHelper( |
207 | 207 | MediaWikiServices::getInstance()->getStatsdDataFactory(), |
208 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
208 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
209 | 209 | $this->config |
210 | 210 | ), |
211 | - $this->config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
212 | - $this->config->get( 'WBQualityConstraintsCheckReferences' ), |
|
213 | - $this->config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
211 | + $this->config->get('WBQualityConstraintsCheckQualifiers'), |
|
212 | + $this->config->get('WBQualityConstraintsCheckReferences'), |
|
213 | + $this->config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
214 | 214 | ); |
215 | 215 | } |
216 | 216 | |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | * @return ConstraintChecker[] |
222 | 222 | */ |
223 | 223 | private function getConstraintCheckerMap() { |
224 | - if ( $this->constraintCheckerMap === null ) { |
|
224 | + if ($this->constraintCheckerMap === null) { |
|
225 | 225 | $connectionCheckerHelper = new ConnectionCheckerHelper(); |
226 | - $rangeCheckerHelper = new RangeCheckerHelper( $this->config, $this->unitConverter ); |
|
227 | - if ( $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ) !== '' ) { |
|
226 | + $rangeCheckerHelper = new RangeCheckerHelper($this->config, $this->unitConverter); |
|
227 | + if ($this->config->get('WBQualityConstraintsSparqlEndpoint') !== '') { |
|
228 | 228 | $sparqlHelper = new SparqlHelper( |
229 | 229 | $this->config, |
230 | 230 | $this->rdfVocabulary, |
@@ -243,74 +243,74 @@ discard block |
||
243 | 243 | ); |
244 | 244 | |
245 | 245 | $this->constraintCheckerMap = [ |
246 | - $this->config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
246 | + $this->config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
247 | 247 | => new ConflictsWithChecker( |
248 | 248 | $this->lookup, |
249 | 249 | $this->constraintParameterParser, |
250 | 250 | $connectionCheckerHelper, |
251 | 251 | $this->constraintParameterRenderer |
252 | 252 | ), |
253 | - $this->config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
253 | + $this->config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
254 | 254 | => new ItemChecker( |
255 | 255 | $this->lookup, |
256 | 256 | $this->constraintParameterParser, |
257 | 257 | $connectionCheckerHelper, |
258 | 258 | $this->constraintParameterRenderer |
259 | 259 | ), |
260 | - $this->config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
260 | + $this->config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
261 | 261 | => new TargetRequiredClaimChecker( |
262 | 262 | $this->lookup, |
263 | 263 | $this->constraintParameterParser, |
264 | 264 | $connectionCheckerHelper, |
265 | 265 | $this->constraintParameterRenderer |
266 | 266 | ), |
267 | - $this->config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
267 | + $this->config->get('WBQualityConstraintsSymmetricConstraintId') |
|
268 | 268 | => new SymmetricChecker( |
269 | 269 | $this->lookup, |
270 | 270 | $connectionCheckerHelper, |
271 | 271 | $this->constraintParameterRenderer |
272 | 272 | ), |
273 | - $this->config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
273 | + $this->config->get('WBQualityConstraintsInverseConstraintId') |
|
274 | 274 | => new InverseChecker( |
275 | 275 | $this->lookup, |
276 | 276 | $this->constraintParameterParser, |
277 | 277 | $connectionCheckerHelper, |
278 | 278 | $this->constraintParameterRenderer |
279 | 279 | ), |
280 | - $this->config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
280 | + $this->config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
281 | 281 | => new QualifierChecker(), |
282 | - $this->config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
282 | + $this->config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
283 | 283 | => new QualifiersChecker( |
284 | 284 | $this->constraintParameterParser, |
285 | 285 | $this->constraintParameterRenderer |
286 | 286 | ), |
287 | - $this->config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
287 | + $this->config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
288 | 288 | => new MandatoryQualifiersChecker( |
289 | 289 | $this->constraintParameterParser, |
290 | 290 | $this->constraintParameterRenderer |
291 | 291 | ), |
292 | - $this->config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
292 | + $this->config->get('WBQualityConstraintsRangeConstraintId') |
|
293 | 293 | => new RangeChecker( |
294 | 294 | $this->propertyDataTypeLookup, |
295 | 295 | $this->constraintParameterParser, |
296 | 296 | $rangeCheckerHelper, |
297 | 297 | $this->constraintParameterRenderer |
298 | 298 | ), |
299 | - $this->config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
299 | + $this->config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
300 | 300 | => new DiffWithinRangeChecker( |
301 | 301 | $this->constraintParameterParser, |
302 | 302 | $rangeCheckerHelper, |
303 | 303 | $this->constraintParameterRenderer, |
304 | 304 | $this->config |
305 | 305 | ), |
306 | - $this->config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
306 | + $this->config->get('WBQualityConstraintsTypeConstraintId') |
|
307 | 307 | => new TypeChecker( |
308 | 308 | $this->lookup, |
309 | 309 | $this->constraintParameterParser, |
310 | 310 | $typeCheckerHelper, |
311 | 311 | $this->config |
312 | 312 | ), |
313 | - $this->config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
313 | + $this->config->get('WBQualityConstraintsValueTypeConstraintId') |
|
314 | 314 | => new ValueTypeChecker( |
315 | 315 | $this->lookup, |
316 | 316 | $this->constraintParameterParser, |
@@ -318,36 +318,36 @@ discard block |
||
318 | 318 | $typeCheckerHelper, |
319 | 319 | $this->config |
320 | 320 | ), |
321 | - $this->config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
321 | + $this->config->get('WBQualityConstraintsSingleValueConstraintId') |
|
322 | 322 | => new SingleValueChecker(), |
323 | - $this->config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
323 | + $this->config->get('WBQualityConstraintsMultiValueConstraintId') |
|
324 | 324 | => new MultiValueChecker(), |
325 | - $this->config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
325 | + $this->config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
326 | 326 | => new UniqueValueChecker( |
327 | 327 | $this->constraintParameterRenderer, |
328 | 328 | $sparqlHelper |
329 | 329 | ), |
330 | - $this->config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
330 | + $this->config->get('WBQualityConstraintsFormatConstraintId') |
|
331 | 331 | => new FormatChecker( |
332 | 332 | $this->constraintParameterParser, |
333 | 333 | $this->constraintParameterRenderer, |
334 | 334 | $this->config, |
335 | 335 | $sparqlHelper |
336 | 336 | ), |
337 | - $this->config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
337 | + $this->config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
338 | 338 | => new CommonsLinkChecker( |
339 | 339 | $this->constraintParameterParser, |
340 | 340 | $this->constraintParameterRenderer, |
341 | 341 | $this->titleParser |
342 | 342 | ), |
343 | - $this->config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
343 | + $this->config->get('WBQualityConstraintsOneOfConstraintId') |
|
344 | 344 | => new OneOfChecker( |
345 | 345 | $this->constraintParameterParser, |
346 | 346 | $this->constraintParameterRenderer |
347 | 347 | ), |
348 | - $this->config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
348 | + $this->config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
349 | 349 | => new ValueOnlyChecker(), |
350 | - $this->config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
350 | + $this->config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
351 | 351 | => new ReferenceChecker(), |
352 | 352 | ]; |
353 | 353 | } |
@@ -359,26 +359,26 @@ discard block |
||
359 | 359 | * @return array[] |
360 | 360 | */ |
361 | 361 | public function getConstraintParameterMap() { |
362 | - if ( $this->constraintParameterMap === null ) { |
|
362 | + if ($this->constraintParameterMap === null) { |
|
363 | 363 | $this->constraintParameterMap = [ |
364 | - 'Commons link' => [ 'namespace' ], |
|
365 | - 'Conflicts with' => [ 'property', 'item' ], |
|
366 | - 'Diff within range' => [ 'property', 'minimum_quantity', 'maximum_quantity' ], |
|
367 | - 'Format' => [ 'pattern' ], |
|
368 | - 'Inverse' => [ 'property' ], |
|
369 | - 'Item' => [ 'property', 'item' ], |
|
370 | - 'Mandatory qualifiers' => [ 'property' ], |
|
364 | + 'Commons link' => ['namespace'], |
|
365 | + 'Conflicts with' => ['property', 'item'], |
|
366 | + 'Diff within range' => ['property', 'minimum_quantity', 'maximum_quantity'], |
|
367 | + 'Format' => ['pattern'], |
|
368 | + 'Inverse' => ['property'], |
|
369 | + 'Item' => ['property', 'item'], |
|
370 | + 'Mandatory qualifiers' => ['property'], |
|
371 | 371 | 'Multi value' => [], |
372 | - 'One of' => [ 'item' ], |
|
372 | + 'One of' => ['item'], |
|
373 | 373 | 'Qualifier' => [], |
374 | - 'Qualifiers' => [ 'property' ], |
|
375 | - 'Range' => [ 'minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date' ], |
|
374 | + 'Qualifiers' => ['property'], |
|
375 | + 'Range' => ['minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date'], |
|
376 | 376 | 'Single value' => [], |
377 | 377 | 'Symmetric' => [], |
378 | - 'Target required claim' => [ 'property', 'item' ], |
|
379 | - 'Type' => [ 'class', 'relation' ], |
|
378 | + 'Target required claim' => ['property', 'item'], |
|
379 | + 'Type' => ['class', 'relation'], |
|
380 | 380 | 'Unique value' => [], |
381 | - 'Value type' => [ 'class', 'relation' ] |
|
381 | + 'Value type' => ['class', 'relation'] |
|
382 | 382 | ]; |
383 | 383 | } |
384 | 384 | |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | * @return ConstraintRepository |
390 | 390 | */ |
391 | 391 | public function getConstraintRepository() { |
392 | - if ( $this->constraintRepository === null ) { |
|
392 | + if ($this->constraintRepository === null) { |
|
393 | 393 | $this->constraintRepository = new ConstraintRepository(); |
394 | 394 | } |
395 | 395 |
@@ -89,18 +89,18 @@ discard block |
||
89 | 89 | $this->propertyDataTypeLookup = $propertyDataTypeLookup; |
90 | 90 | $this->cache = $cache; |
91 | 91 | |
92 | - $this->entityPrefix = $rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY ); |
|
92 | + $this->entityPrefix = $rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY); |
|
93 | 93 | $this->prefixes = <<<EOT |
94 | -PREFIX wd: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY )}> |
|
95 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
96 | -PREFIX wdt: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_DIRECT_CLAIM )}> |
|
97 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}> |
|
98 | -PREFIX p: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM )}> |
|
99 | -PREFIX ps: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM_STATEMENT )}> |
|
100 | -PREFIX pq: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER )}> |
|
101 | -PREFIX pqv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER_VALUE )}> |
|
102 | -PREFIX pr: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE )}> |
|
103 | -PREFIX prv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE_VALUE )}> |
|
94 | +PREFIX wd: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY)}> |
|
95 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
96 | +PREFIX wdt: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_DIRECT_CLAIM)}> |
|
97 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}> |
|
98 | +PREFIX p: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM)}> |
|
99 | +PREFIX ps: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM_STATEMENT)}> |
|
100 | +PREFIX pq: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER)}> |
|
101 | +PREFIX pqv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER_VALUE)}> |
|
102 | +PREFIX pr: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE)}> |
|
103 | +PREFIX prv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE_VALUE)}> |
|
104 | 104 | PREFIX wikibase: <http://wikiba.se/ontology#> |
105 | 105 | PREFIX wikibase-beta: <http://wikiba.se/ontology-beta#> |
106 | 106 | EOT; |
@@ -117,21 +117,21 @@ discard block |
||
117 | 117 | * @return CachedBool |
118 | 118 | * @throws SparqlHelperException if the query times out or some other error occurs |
119 | 119 | */ |
120 | - public function hasType( $id, array $classes, $withInstance ) { |
|
121 | - $instanceOfId = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
122 | - $subclassOfId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
120 | + public function hasType($id, array $classes, $withInstance) { |
|
121 | + $instanceOfId = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
122 | + $subclassOfId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
123 | 123 | |
124 | - $path = ( $withInstance ? "wdt:$instanceOfId/" : "" ) . "wdt:$subclassOfId*"; |
|
124 | + $path = ($withInstance ? "wdt:$instanceOfId/" : "")."wdt:$subclassOfId*"; |
|
125 | 125 | |
126 | 126 | $metadatas = []; |
127 | 127 | |
128 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
129 | - $classesValues = implode( ' ', array_map( |
|
130 | - function( $class ) { |
|
131 | - return 'wd:' . $class; |
|
128 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
129 | + $classesValues = implode(' ', array_map( |
|
130 | + function($class) { |
|
131 | + return 'wd:'.$class; |
|
132 | 132 | }, |
133 | 133 | $classesChunk |
134 | - ) ); |
|
134 | + )); |
|
135 | 135 | |
136 | 136 | $query = <<<EOF |
137 | 137 | ASK { |
@@ -142,19 +142,19 @@ discard block |
||
142 | 142 | EOF; |
143 | 143 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
144 | 144 | |
145 | - $result = $this->runQuery( $query ); |
|
145 | + $result = $this->runQuery($query); |
|
146 | 146 | $metadatas[] = $result->getMetadata(); |
147 | - if ( $result->getArray()['boolean'] ) { |
|
147 | + if ($result->getArray()['boolean']) { |
|
148 | 148 | return new CachedBool( |
149 | 149 | true, |
150 | - Metadata::merge( $metadatas ) |
|
150 | + Metadata::merge($metadatas) |
|
151 | 151 | ); |
152 | 152 | } |
153 | 153 | } |
154 | 154 | |
155 | 155 | return new CachedBool( |
156 | 156 | false, |
157 | - Metadata::merge( $metadatas ) |
|
157 | + Metadata::merge($metadatas) |
|
158 | 158 | ); |
159 | 159 | } |
160 | 160 | |
@@ -170,10 +170,10 @@ discard block |
||
170 | 170 | $ignoreDeprecatedStatements |
171 | 171 | ) { |
172 | 172 | $pid = $statement->getPropertyId()->serialize(); |
173 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
173 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
174 | 174 | |
175 | 175 | $deprecatedFilter = ''; |
176 | - if ( $ignoreDeprecatedStatements ) { |
|
176 | + if ($ignoreDeprecatedStatements) { |
|
177 | 177 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
178 | 178 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }'; |
179 | 179 | } |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | LIMIT 10 |
194 | 194 | EOF; |
195 | 195 | |
196 | - $result = $this->runQuery( $query ); |
|
196 | + $result = $this->runQuery($query); |
|
197 | 197 | |
198 | - return $this->getOtherEntities( $result ); |
|
198 | + return $this->getOtherEntities($result); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -220,16 +220,15 @@ discard block |
||
220 | 220 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
221 | 221 | $snak->getPropertyId() |
222 | 222 | ); |
223 | - list ( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
224 | - if ( $isFullValue ) { |
|
223 | + list ($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
224 | + if ($isFullValue) { |
|
225 | 225 | $prefix .= 'v'; |
226 | 226 | } |
227 | 227 | $path = $type === Context::TYPE_QUALIFIER ? |
228 | - "$prefix:$pid" : |
|
229 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
228 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
230 | 229 | |
231 | 230 | $deprecatedFilter = ''; |
232 | - if ( $ignoreDeprecatedStatements ) { |
|
231 | + if ($ignoreDeprecatedStatements) { |
|
233 | 232 | $deprecatedFilter = <<< EOF |
234 | 233 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
235 | 234 | MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. } |
@@ -250,9 +249,9 @@ discard block |
||
250 | 249 | LIMIT 10 |
251 | 250 | EOF; |
252 | 251 | |
253 | - $result = $this->runQuery( $query ); |
|
252 | + $result = $this->runQuery($query); |
|
254 | 253 | |
255 | - return $this->getOtherEntities( $result ); |
|
254 | + return $this->getOtherEntities($result); |
|
256 | 255 | } |
257 | 256 | |
258 | 257 | /** |
@@ -262,8 +261,8 @@ discard block |
||
262 | 261 | * |
263 | 262 | * @return string |
264 | 263 | */ |
265 | - private function stringLiteral( $text ) { |
|
266 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
264 | + private function stringLiteral($text) { |
|
265 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
267 | 266 | } |
268 | 267 | |
269 | 268 | /** |
@@ -273,17 +272,17 @@ discard block |
||
273 | 272 | * |
274 | 273 | * @return CachedEntityIds |
275 | 274 | */ |
276 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
277 | - return new CachedEntityIds( array_map( |
|
278 | - function ( $resultBindings ) { |
|
275 | + private function getOtherEntities(CachedQueryResults $results) { |
|
276 | + return new CachedEntityIds(array_map( |
|
277 | + function($resultBindings) { |
|
279 | 278 | $entityIRI = $resultBindings['otherEntity']['value']; |
280 | - $entityPrefixLength = strlen( $this->entityPrefix ); |
|
281 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $this->entityPrefix ) { |
|
279 | + $entityPrefixLength = strlen($this->entityPrefix); |
|
280 | + if (substr($entityIRI, 0, $entityPrefixLength) === $this->entityPrefix) { |
|
282 | 281 | try { |
283 | 282 | return $this->entityIdParser->parse( |
284 | - substr( $entityIRI, $entityPrefixLength ) |
|
283 | + substr($entityIRI, $entityPrefixLength) |
|
285 | 284 | ); |
286 | - } catch ( EntityIdParsingException $e ) { |
|
285 | + } catch (EntityIdParsingException $e) { |
|
287 | 286 | // fall through |
288 | 287 | } |
289 | 288 | } |
@@ -291,7 +290,7 @@ discard block |
||
291 | 290 | return null; |
292 | 291 | }, |
293 | 292 | $results->getArray()['results']['bindings'] |
294 | - ), $results->getMetadata() ); |
|
293 | + ), $results->getMetadata()); |
|
295 | 294 | } |
296 | 295 | |
297 | 296 | // @codingStandardsIgnoreStart cyclomatic complexity of this function is too high |
@@ -304,47 +303,47 @@ discard block |
||
304 | 303 | * @return array the literal or IRI as a string in SPARQL syntax, |
305 | 304 | * and a boolean indicating whether it refers to a full value node or not |
306 | 305 | */ |
307 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
308 | - switch ( $dataType ) { |
|
306 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
307 | + switch ($dataType) { |
|
309 | 308 | case 'string': |
310 | 309 | case 'external-id': |
311 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
310 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
312 | 311 | case 'commonsMedia': |
313 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
314 | - return [ '<' . $url . '>', false ]; |
|
312 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
313 | + return ['<'.$url.'>', false]; |
|
315 | 314 | case 'geo-shape': |
316 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
317 | - return [ '<' . $url . '>', false ]; |
|
315 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
316 | + return ['<'.$url.'>', false]; |
|
318 | 317 | case 'tabular-data': |
319 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
320 | - return [ '<' . $url . '>', false ]; |
|
318 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
319 | + return ['<'.$url.'>', false]; |
|
321 | 320 | case 'url': |
322 | 321 | $url = $dataValue->getValue(); |
323 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
322 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
324 | 323 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
325 | 324 | // such an URL should never reach us, so just throw |
326 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
325 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
327 | 326 | } |
328 | - return [ '<' . $url . '>', false ]; |
|
327 | + return ['<'.$url.'>', false]; |
|
329 | 328 | case 'wikibase-item': |
330 | 329 | case 'wikibase-property': |
331 | 330 | /** @var EntityIdValue $dataValue */ |
332 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
331 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
333 | 332 | case 'monolingualtext': |
334 | 333 | /** @var MonolingualTextValue $dataValue */ |
335 | 334 | $lang = $dataValue->getLanguageCode(); |
336 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
335 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
337 | 336 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
338 | 337 | // such a language tag should never reach us, so just throw |
339 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
338 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
340 | 339 | } |
341 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
340 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
342 | 341 | case 'globe-coordinate': |
343 | 342 | case 'quantity': |
344 | 343 | case 'time': |
345 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
344 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
346 | 345 | default: |
347 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
346 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
348 | 347 | } |
349 | 348 | } |
350 | 349 | // @codingStandardsIgnoreEnd |
@@ -357,41 +356,41 @@ discard block |
||
357 | 356 | * @throws SparqlHelperException if the query times out or some other error occurs |
358 | 357 | * @throws ConstraintParameterException if the $regex is invalid |
359 | 358 | */ |
360 | - public function matchesRegularExpression( $text, $regex ) { |
|
359 | + public function matchesRegularExpression($text, $regex) { |
|
361 | 360 | // caching wrapper around matchesRegularExpressionWithSparql |
362 | 361 | |
363 | - $textHash = hash( 'sha256', $text ); |
|
364 | - $cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
362 | + $textHash = hash('sha256', $text); |
|
363 | + $cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
365 | 364 | |
366 | 365 | $cacheMapArray = $this->cache->getWithSetCallback( |
367 | 366 | $this->cache->makeKey( |
368 | 367 | 'WikibaseQualityConstraints', // extension |
369 | 368 | 'regex', // action |
370 | 369 | 'WDQS-Java', // regex flavor |
371 | - hash( 'sha256', $regex ) |
|
370 | + hash('sha256', $regex) |
|
372 | 371 | ), |
373 | 372 | WANObjectCache::TTL_DAY, |
374 | - function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) { |
|
373 | + function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) { |
|
375 | 374 | // Initialize the cache map if not set |
376 | - if ( $cacheMapArray === false ) { |
|
375 | + if ($cacheMapArray === false) { |
|
377 | 376 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
378 | - $this->dataFactory->increment( $key ); |
|
377 | + $this->dataFactory->increment($key); |
|
379 | 378 | return []; |
380 | 379 | } |
381 | 380 | |
382 | 381 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
383 | - $this->dataFactory->increment( $key ); |
|
384 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize ); |
|
385 | - if ( $cacheMap->has( $textHash ) ) { |
|
382 | + $this->dataFactory->increment($key); |
|
383 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize); |
|
384 | + if ($cacheMap->has($textHash)) { |
|
386 | 385 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
387 | - $this->dataFactory->increment( $key ); |
|
388 | - $cacheMap->get( $textHash ); // ping cache |
|
386 | + $this->dataFactory->increment($key); |
|
387 | + $cacheMap->get($textHash); // ping cache |
|
389 | 388 | } else { |
390 | 389 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
391 | - $this->dataFactory->increment( $key ); |
|
390 | + $this->dataFactory->increment($key); |
|
392 | 391 | $cacheMap->set( |
393 | 392 | $textHash, |
394 | - $this->matchesRegularExpressionWithSparql( $text, $regex ), |
|
393 | + $this->matchesRegularExpressionWithSparql($text, $regex), |
|
395 | 394 | 3 / 8 |
396 | 395 | ); |
397 | 396 | } |
@@ -409,14 +408,14 @@ discard block |
||
409 | 408 | ] |
410 | 409 | ); |
411 | 410 | |
412 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
411 | + if (isset($cacheMapArray[$textHash])) { |
|
413 | 412 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
414 | - $this->dataFactory->increment( $key ); |
|
413 | + $this->dataFactory->increment($key); |
|
415 | 414 | return $cacheMapArray[$textHash]; |
416 | 415 | } else { |
417 | 416 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
418 | - $this->dataFactory->increment( $key ); |
|
419 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
417 | + $this->dataFactory->increment($key); |
|
418 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
420 | 419 | } |
421 | 420 | } |
422 | 421 | |
@@ -431,26 +430,26 @@ discard block |
||
431 | 430 | * @throws SparqlHelperException if the query times out or some other error occurs |
432 | 431 | * @throws ConstraintParameterException if the $regex is invalid |
433 | 432 | */ |
434 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
435 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
436 | - $regexStringLiteral = $this->stringLiteral( '^' . $regex . '$' ); |
|
433 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
434 | + $textStringLiteral = $this->stringLiteral($text); |
|
435 | + $regexStringLiteral = $this->stringLiteral('^'.$regex.'$'); |
|
437 | 436 | |
438 | 437 | $query = <<<EOF |
439 | 438 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
440 | 439 | EOF; |
441 | 440 | |
442 | - $result = $this->runQuery( $query ); |
|
441 | + $result = $this->runQuery($query); |
|
443 | 442 | |
444 | 443 | $vars = $result->getArray()['results']['bindings'][0]; |
445 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
444 | + if (array_key_exists('matches', $vars)) { |
|
446 | 445 | // true or false ⇒ regex okay, text matches or not |
447 | 446 | return $vars['matches']['value'] === 'true'; |
448 | 447 | } else { |
449 | 448 | // empty result: regex broken |
450 | 449 | throw new ConstraintParameterException( |
451 | - wfMessage( 'wbqc-violation-message-parameter-regex' ) |
|
452 | - ->rawParams( ConstraintParameterRenderer::formatByRole( Role::CONSTRAINT_PARAMETER_VALUE, |
|
453 | - '<code><nowiki>' . htmlspecialchars( $regex ) . '</nowiki></code>' ) ) |
|
450 | + wfMessage('wbqc-violation-message-parameter-regex') |
|
451 | + ->rawParams(ConstraintParameterRenderer::formatByRole(Role::CONSTRAINT_PARAMETER_VALUE, |
|
452 | + '<code><nowiki>'.htmlspecialchars($regex).'</nowiki></code>')) |
|
454 | 453 | ->escaped() |
455 | 454 | ); |
456 | 455 | } |
@@ -463,14 +462,14 @@ discard block |
||
463 | 462 | * |
464 | 463 | * @return boolean |
465 | 464 | */ |
466 | - public function isTimeout( $responseContent ) { |
|
467 | - $timeoutRegex = implode( '|', array_map( |
|
468 | - function ( $fqn ) { |
|
469 | - return preg_quote( $fqn, '/' ); |
|
465 | + public function isTimeout($responseContent) { |
|
466 | + $timeoutRegex = implode('|', array_map( |
|
467 | + function($fqn) { |
|
468 | + return preg_quote($fqn, '/'); |
|
470 | 469 | }, |
471 | - $this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' ) |
|
472 | - ) ); |
|
473 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
470 | + $this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses') |
|
471 | + )); |
|
472 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
474 | 473 | } |
475 | 474 | |
476 | 475 | /** |
@@ -482,17 +481,17 @@ discard block |
||
482 | 481 | * @return integer|boolean the max-age (in seconds) |
483 | 482 | * or a plain boolean if no max-age can be determined |
484 | 483 | */ |
485 | - public function getCacheMaxAge( $responseHeaders ) { |
|
484 | + public function getCacheMaxAge($responseHeaders) { |
|
486 | 485 | if ( |
487 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
488 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
486 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
487 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
489 | 488 | ) { |
490 | 489 | $maxage = []; |
491 | 490 | if ( |
492 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
493 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
491 | + array_key_exists('cache-control', $responseHeaders) && |
|
492 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
494 | 493 | ) { |
495 | - return intval( $maxage[1] ); |
|
494 | + return intval($maxage[1]); |
|
496 | 495 | } else { |
497 | 496 | return true; |
498 | 497 | } |
@@ -510,59 +509,58 @@ discard block |
||
510 | 509 | * |
511 | 510 | * @throws SparqlHelperException if the query times out or some other error occurs |
512 | 511 | */ |
513 | - public function runQuery( $query ) { |
|
512 | + public function runQuery($query) { |
|
514 | 513 | |
515 | - $endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
516 | - $maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
517 | - $url = $endpoint . '?' . http_build_query( |
|
514 | + $endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint'); |
|
515 | + $maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
516 | + $url = $endpoint.'?'.http_build_query( |
|
518 | 517 | [ |
519 | - 'query' => "#wbqc\n" . $this->prefixes . $query, |
|
518 | + 'query' => "#wbqc\n".$this->prefixes.$query, |
|
520 | 519 | 'format' => 'json', |
521 | 520 | 'maxQueryTimeMillis' => $maxQueryTimeMillis, |
522 | 521 | ], |
523 | - null, ini_get( 'arg_separator.output' ), |
|
522 | + null, ini_get('arg_separator.output'), |
|
524 | 523 | // encode spaces with %20, not + |
525 | 524 | PHP_QUERY_RFC3986 |
526 | 525 | ); |
527 | 526 | |
528 | 527 | $options = [ |
529 | 528 | 'method' => 'GET', |
530 | - 'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ), |
|
529 | + 'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000), |
|
531 | 530 | 'connectTimeout' => 'default', |
532 | 531 | ]; |
533 | - $request = MWHttpRequest::factory( $url, $options ); |
|
534 | - $startTime = microtime( true ); |
|
532 | + $request = MWHttpRequest::factory($url, $options); |
|
533 | + $startTime = microtime(true); |
|
535 | 534 | $status = $request->execute(); |
536 | - $endTime = microtime( true ); |
|
535 | + $endTime = microtime(true); |
|
537 | 536 | $this->dataFactory->timing( |
538 | 537 | 'wikibase.quality.constraints.sparql.timing', |
539 | - ( $endTime - $startTime ) * 1000 |
|
538 | + ($endTime - $startTime) * 1000 |
|
540 | 539 | ); |
541 | 540 | |
542 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
543 | - if ( $maxAge ) { |
|
544 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
541 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
542 | + if ($maxAge) { |
|
543 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
545 | 544 | } |
546 | 545 | |
547 | - if ( $status->isOK() ) { |
|
546 | + if ($status->isOK()) { |
|
548 | 547 | $json = $request->getContent(); |
549 | - $arr = json_decode( $json, true ); |
|
548 | + $arr = json_decode($json, true); |
|
550 | 549 | return new CachedQueryResults( |
551 | 550 | $arr, |
552 | 551 | Metadata::ofCachingMetadata( |
553 | 552 | $maxAge ? |
554 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
555 | - CachingMetadata::fresh() |
|
553 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
556 | 554 | ) |
557 | 555 | ); |
558 | 556 | } else { |
559 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
557 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
560 | 558 | |
561 | 559 | $this->dataFactory->increment( |
562 | 560 | "wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}" |
563 | 561 | ); |
564 | 562 | |
565 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
563 | + if ($this->isTimeout($request->getContent())) { |
|
566 | 564 | $this->dataFactory->increment( |
567 | 565 | 'wikibase.quality.constraints.sparql.error.timeout' |
568 | 566 | ); |
@@ -60,22 +60,22 @@ discard block |
||
60 | 60 | * @return array first element is the namespace number (default namespace for TitleParser), |
61 | 61 | * second element is a string to prepend to the title before giving it to the TitleParser |
62 | 62 | */ |
63 | - private function getCommonsNamespace( $namespace ) { |
|
63 | + private function getCommonsNamespace($namespace) { |
|
64 | 64 | // for namespace numbers see mediawiki-config repo, wmf-config/InitialiseSettings.php, |
65 | 65 | // 'wgExtraNamespaces' key, 'commonswiki' subkey |
66 | - switch ( $namespace ) { |
|
66 | + switch ($namespace) { |
|
67 | 67 | case '': |
68 | - return [ NS_MAIN, '' ]; |
|
68 | + return [NS_MAIN, '']; |
|
69 | 69 | case 'Creator': |
70 | - return [ 100, '' ]; |
|
70 | + return [100, '']; |
|
71 | 71 | case 'TimedText': |
72 | - return [ 102, '' ]; |
|
72 | + return [102, '']; |
|
73 | 73 | case 'Sequence': |
74 | - return [ 104, '' ]; |
|
74 | + return [104, '']; |
|
75 | 75 | case 'Institution': |
76 | - return [ 106, '' ]; |
|
76 | + return [106, '']; |
|
77 | 77 | default: |
78 | - return [ NS_MAIN, $namespace . ':' ]; |
|
78 | + return [NS_MAIN, $namespace.':']; |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
@@ -87,17 +87,17 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @return CheckResult |
89 | 89 | */ |
90 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
90 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
91 | 91 | $parameters = []; |
92 | 92 | $constraintParameters = $constraint->getConstraintParameters(); |
93 | - $namespace = $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
94 | - $parameters['namespace'] = [ $namespace ]; |
|
93 | + $namespace = $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
94 | + $parameters['namespace'] = [$namespace]; |
|
95 | 95 | |
96 | 96 | $snak = $context->getSnak(); |
97 | 97 | |
98 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
98 | + if (!$snak instanceof PropertyValueSnak) { |
|
99 | 99 | // nothing to check |
100 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
100 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $dataValue = $snak->getDataValue(); |
@@ -107,49 +107,49 @@ discard block |
||
107 | 107 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
108 | 108 | * parameter $namespace can be null, works for commons galleries |
109 | 109 | */ |
110 | - if ( $dataValue->getType() !== 'string' ) { |
|
111 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
110 | + if ($dataValue->getType() !== 'string') { |
|
111 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
112 | 112 | ->rawParams( |
113 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
114 | - wfMessage( 'datatypes-type-string' )->escaped() |
|
113 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
114 | + wfMessage('datatypes-type-string')->escaped() |
|
115 | 115 | ) |
116 | 116 | ->escaped(); |
117 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
117 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | $commonsLink = $dataValue->getValue(); |
121 | 121 | |
122 | 122 | try { |
123 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
124 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
123 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
124 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
125 | 125 | } |
126 | - list ( $defaultNamespace, $prefix ) = $this->getCommonsNamespace( $namespace ); |
|
127 | - $title = $this->titleParser->parseTitle( $prefix . $commonsLink, $defaultNamespace ); |
|
128 | - if ( $this->pageExists( $title ) ) { |
|
126 | + list ($defaultNamespace, $prefix) = $this->getCommonsNamespace($namespace); |
|
127 | + $title = $this->titleParser->parseTitle($prefix.$commonsLink, $defaultNamespace); |
|
128 | + if ($this->pageExists($title)) { |
|
129 | 129 | $message = ''; |
130 | 130 | $status = CheckResult::STATUS_COMPLIANCE; |
131 | 131 | } else { |
132 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
133 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
132 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
133 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
134 | 134 | } else { |
135 | - $message = wfMessage( "wbqc-violation-message-commons-link-no-existent" )->escaped(); |
|
135 | + $message = wfMessage("wbqc-violation-message-commons-link-no-existent")->escaped(); |
|
136 | 136 | $status = CheckResult::STATUS_VIOLATION; |
137 | 137 | } |
138 | 138 | } |
139 | - } catch ( MalformedTitleException $e ) { |
|
140 | - $message = wfMessage( "wbqc-violation-message-commons-link-not-well-formed" )->escaped(); |
|
139 | + } catch (MalformedTitleException $e) { |
|
140 | + $message = wfMessage("wbqc-violation-message-commons-link-not-well-formed")->escaped(); |
|
141 | 141 | $status = CheckResult::STATUS_VIOLATION; |
142 | 142 | } |
143 | 143 | |
144 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
144 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
145 | 145 | } |
146 | 146 | |
147 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
147 | + public function checkConstraintParameters(Constraint $constraint) { |
|
148 | 148 | $constraintParameters = $constraint->getConstraintParameters(); |
149 | 149 | $exceptions = []; |
150 | 150 | try { |
151 | - $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
152 | - } catch ( ConstraintParameterException $e ) { |
|
151 | + $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
152 | + } catch (ConstraintParameterException $e) { |
|
153 | 153 | $exceptions[] = $e; |
154 | 154 | } |
155 | 155 | return $exceptions; |
@@ -160,19 +160,19 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @return bool |
162 | 162 | */ |
163 | - private function pageExists( TitleValue $title ) { |
|
163 | + private function pageExists(TitleValue $title) { |
|
164 | 164 | $commonsWikiId = 'commonswiki'; |
165 | - if ( defined( 'MW_PHPUNIT_TEST' ) ) { |
|
165 | + if (defined('MW_PHPUNIT_TEST')) { |
|
166 | 166 | $commonsWikiId = false; |
167 | 167 | } |
168 | 168 | |
169 | - $dbLoadBalancer = wfGetLB( $commonsWikiId ); |
|
169 | + $dbLoadBalancer = wfGetLB($commonsWikiId); |
|
170 | 170 | $dbConnection = $dbLoadBalancer->getConnection( |
171 | 171 | DB_REPLICA, false, $commonsWikiId ); |
172 | - $row = $dbConnection->selectRow( 'page', '*', [ |
|
172 | + $row = $dbConnection->selectRow('page', '*', [ |
|
173 | 173 | 'page_title' => $title->getDBkey(), |
174 | 174 | 'page_namespace' => $title->getNamespace() |
175 | - ] ); |
|
175 | + ]); |
|
176 | 176 | |
177 | 177 | return $row !== false; |
178 | 178 | } |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return bool |
184 | 184 | */ |
185 | - private function commonsLinkIsWellFormed( $commonsLink ) { |
|
186 | - $toReplace = [ "_", "%20" ]; |
|
187 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
185 | + private function commonsLinkIsWellFormed($commonsLink) { |
|
186 | + $toReplace = ["_", "%20"]; |
|
187 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
188 | 188 | return $commonsLink === $compareString; |
189 | 189 | } |
190 | 190 | |
@@ -197,9 +197,9 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @return bool |
199 | 199 | */ |
200 | - private function valueIncludesNamespace( $value, $namespace ) { |
|
200 | + private function valueIncludesNamespace($value, $namespace) { |
|
201 | 201 | return $namespace !== '' && |
202 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
202 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | } |
@@ -73,44 +73,43 @@ discard block |
||
73 | 73 | ) { |
74 | 74 | $response = []; |
75 | 75 | $metadatas = []; |
76 | - foreach ( $entityIds as $entityId ) { |
|
76 | + foreach ($entityIds as $entityId) { |
|
77 | 77 | $results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnEntityId( |
78 | 78 | $entityId, |
79 | 79 | $constraintIds, |
80 | - [ $this, 'defaultResults' ] |
|
80 | + [$this, 'defaultResults'] |
|
81 | 81 | ); |
82 | - foreach ( $results as $result ) { |
|
82 | + foreach ($results as $result) { |
|
83 | 83 | $metadatas[] = $result->getMetadata(); |
84 | - $resultArray = $this->checkResultToArray( $result ); |
|
85 | - $result->getContext()->storeCheckResultInArray( $resultArray, $response ); |
|
84 | + $resultArray = $this->checkResultToArray($result); |
|
85 | + $result->getContext()->storeCheckResultInArray($resultArray, $response); |
|
86 | 86 | } |
87 | 87 | } |
88 | - foreach ( $claimIds as $claimId ) { |
|
88 | + foreach ($claimIds as $claimId) { |
|
89 | 89 | $results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnClaimId( |
90 | 90 | $claimId, |
91 | 91 | $constraintIds, |
92 | - [ $this, 'defaultResults' ] |
|
92 | + [$this, 'defaultResults'] |
|
93 | 93 | ); |
94 | - foreach ( $results as $result ) { |
|
94 | + foreach ($results as $result) { |
|
95 | 95 | $metadatas[] = $result->getMetadata(); |
96 | - $resultArray = $this->checkResultToArray( $result ); |
|
97 | - $result->getContext()->storeCheckResultInArray( $resultArray, $response ); |
|
96 | + $resultArray = $this->checkResultToArray($result); |
|
97 | + $result->getContext()->storeCheckResultInArray($resultArray, $response); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | return new CachedCheckConstraintsResponse( |
101 | 101 | $response, |
102 | - Metadata::merge( $metadatas ) |
|
102 | + Metadata::merge($metadatas) |
|
103 | 103 | ); |
104 | 104 | } |
105 | 105 | |
106 | - public function defaultResults( Context $context ) { |
|
106 | + public function defaultResults(Context $context) { |
|
107 | 107 | return $context->getType() === Context::TYPE_STATEMENT ? |
108 | - [ new NullResult( $context ) ] : |
|
109 | - []; |
|
108 | + [new NullResult($context)] : []; |
|
110 | 109 | } |
111 | 110 | |
112 | - public function checkResultToArray( CheckResult $checkResult ) { |
|
113 | - if ( $checkResult instanceof NullResult ) { |
|
111 | + public function checkResultToArray(CheckResult $checkResult) { |
|
112 | + if ($checkResult instanceof NullResult) { |
|
114 | 113 | return null; |
115 | 114 | } |
116 | 115 | |
@@ -118,10 +117,10 @@ discard block |
||
118 | 117 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
119 | 118 | $constraintPropertyId = $checkResult->getContext()->getSnak()->getPropertyId(); |
120 | 119 | |
121 | - $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
122 | - $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
120 | + $title = $this->entityTitleLookup->getTitleForId($constraintPropertyId); |
|
121 | + $typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId)); |
|
123 | 122 | // TODO link to the statement when possible (T169224) |
124 | - $link = $title->getFullURL() . '#' . $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
123 | + $link = $title->getFullURL().'#'.$this->config->get('WBQualityConstraintsPropertyConstraintId'); |
|
125 | 124 | |
126 | 125 | $constraint = [ |
127 | 126 | 'id' => $constraintId, |
@@ -129,11 +128,11 @@ discard block |
||
129 | 128 | 'typeLabel' => $typeLabel, |
130 | 129 | 'link' => $link, |
131 | 130 | ]; |
132 | - if ( $this->config->get( 'WBQualityConstraintsIncludeDetailInApi' ) ) { |
|
131 | + if ($this->config->get('WBQualityConstraintsIncludeDetailInApi')) { |
|
133 | 132 | $parameters = $checkResult->getParameters(); |
134 | 133 | $constraint += [ |
135 | 134 | 'detail' => $parameters, |
136 | - 'detailHTML' => $this->constraintParameterRenderer->formatParameters( $parameters ), |
|
135 | + 'detailHTML' => $this->constraintParameterRenderer->formatParameters($parameters), |
|
137 | 136 | ]; |
138 | 137 | } |
139 | 138 | |
@@ -143,14 +142,14 @@ discard block |
||
143 | 142 | 'constraint' => $constraint |
144 | 143 | ]; |
145 | 144 | $message = $checkResult->getMessage(); |
146 | - if ( $message ) { |
|
145 | + if ($message) { |
|
147 | 146 | $result['message-html'] = $message; |
148 | 147 | } |
149 | - if ( $checkResult->getContext()->getType() === Context::TYPE_STATEMENT ) { |
|
148 | + if ($checkResult->getContext()->getType() === Context::TYPE_STATEMENT) { |
|
150 | 149 | $result['claim'] = $checkResult->getContext()->getSnakStatement()->getGuid(); |
151 | 150 | } |
152 | 151 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
153 | - if ( $cachingMetadataArray !== null ) { |
|
152 | + if ($cachingMetadataArray !== null) { |
|
154 | 153 | $result['cached'] = $cachingMetadataArray; |
155 | 154 | } |
156 | 155 |
@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | private $cache; |
19 | 19 | |
20 | 20 | public static function getDefaultInstance() { |
21 | - return new self( MediaWikiServices::getInstance()->getMainWANObjectCache() ); |
|
21 | + return new self(MediaWikiServices::getInstance()->getMainWANObjectCache()); |
|
22 | 22 | } |
23 | 23 | |
24 | - public function __construct( WANObjectCache $cache ) { |
|
24 | + public function __construct(WANObjectCache $cache) { |
|
25 | 25 | $this->cache = $cache; |
26 | 26 | } |
27 | 27 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param EntityId $entityId |
30 | 30 | * @return string cache key |
31 | 31 | */ |
32 | - public function makeKey( EntityId $entityId ) { |
|
32 | + public function makeKey(EntityId $entityId) { |
|
33 | 33 | return $this->cache->makeKey( |
34 | 34 | 'WikibaseQualityConstraints', // extension |
35 | 35 | 'checkConstraints', // action |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @param float &$asOf |
46 | 46 | * @return mixed |
47 | 47 | */ |
48 | - public function get( EntityId $key, &$curTTL = null, array $checkKeys = [], &$asOf = null ) { |
|
49 | - return $this->cache->get( $this->makeKey( $key ), $curTTL, $checkKeys, $asOf ); |
|
48 | + public function get(EntityId $key, &$curTTL = null, array $checkKeys = [], &$asOf = null) { |
|
49 | + return $this->cache->get($this->makeKey($key), $curTTL, $checkKeys, $asOf); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | * @param array $opts |
57 | 57 | * @return bool |
58 | 58 | */ |
59 | - public function set( EntityId $key, $value, $ttl = 0, array $opts = [] ) { |
|
60 | - return $this->cache->set( $this->makeKey( $key ), $value, $ttl, $opts ); |
|
59 | + public function set(EntityId $key, $value, $ttl = 0, array $opts = []) { |
|
60 | + return $this->cache->set($this->makeKey($key), $value, $ttl, $opts); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @param EntityId $key |
65 | 65 | * @return bool |
66 | 66 | */ |
67 | - public function delete( EntityId $key ) { |
|
68 | - return $this->cache->delete( $this->makeKey( $key ) ); |
|
67 | + public function delete(EntityId $key) { |
|
68 | + return $this->cache->delete($this->makeKey($key)); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | } |
@@ -66,22 +66,22 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return self |
68 | 68 | */ |
69 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
69 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
70 | 70 | $repo = WikibaseRepo::getDefaultInstance(); |
71 | 71 | |
72 | 72 | $language = $repo->getUserLanguage(); |
73 | 73 | $formatterOptions = new FormatterOptions(); |
74 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
74 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
75 | 75 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
76 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
76 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
77 | 77 | |
78 | 78 | $languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory(); |
79 | - $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language ); |
|
79 | + $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language); |
|
80 | 80 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
81 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
81 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
82 | 82 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
83 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
84 | - $constraintParameterRenderer = new ConstraintParameterRenderer( $entityIdHtmlLinkFormatter, $valueFormatter ); |
|
83 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
84 | + $constraintParameterRenderer = new ConstraintParameterRenderer($entityIdHtmlLinkFormatter, $valueFormatter); |
|
85 | 85 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
86 | 86 | $titleParser = MediaWikiServices::getInstance()->getTitleParser(); |
87 | 87 | $unitConverter = $repo->getUnitConverter(); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $constraintParameterRenderer, |
110 | 110 | $config |
111 | 111 | ); |
112 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
112 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
113 | 113 | $entityRevisionLookup = $repo->getEntityRevisionLookup(); |
114 | 114 | $entityIdParser = $repo->getEntityIdParser(); |
115 | 115 | $resultsBuilder = new CachingResultsBuilder( |
@@ -117,12 +117,12 @@ discard block |
||
117 | 117 | ResultsCache::getDefaultInstance(), |
118 | 118 | $entityRevisionLookup, |
119 | 119 | $entityIdParser, |
120 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
120 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
121 | 121 | [ |
122 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
123 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
124 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
125 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
122 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
123 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
124 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
125 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
126 | 126 | ] |
127 | 127 | ); |
128 | 128 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $prefix, |
134 | 134 | $repo->getEntityIdParser(), |
135 | 135 | $repo->getStatementGuidValidator(), |
136 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
136 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
137 | 137 | $resultsBuilder |
138 | 138 | ); |
139 | 139 | } |
@@ -147,16 +147,16 @@ discard block |
||
147 | 147 | * @param ApiHelperFactory $apiHelperFactory |
148 | 148 | * @param ResultsBuilder $resultsBuilder |
149 | 149 | */ |
150 | - public function __construct( ApiMain $main, $name, $prefix = '', EntityIdParser $entityIdParser, |
|
150 | + public function __construct(ApiMain $main, $name, $prefix = '', EntityIdParser $entityIdParser, |
|
151 | 151 | StatementGuidValidator $statementGuidValidator, |
152 | 152 | ApiHelperFactory $apiHelperFactory, |
153 | 153 | ResultsBuilder $resultsBuilder |
154 | 154 | ) { |
155 | - parent::__construct( $main, $name, $prefix ); |
|
155 | + parent::__construct($main, $name, $prefix); |
|
156 | 156 | $this->entityIdParser = $entityIdParser; |
157 | 157 | $this->statementGuidValidator = $statementGuidValidator; |
158 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
159 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
158 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
159 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
160 | 160 | $this->resultsBuilder = $resultsBuilder; |
161 | 161 | } |
162 | 162 | |
@@ -165,13 +165,13 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function execute() { |
167 | 167 | MediaWikiServices::getInstance()->getStatsdDataFactory() |
168 | - ->increment( 'wikibase.quality.constraints.api.checkConstraints.execute' ); |
|
168 | + ->increment('wikibase.quality.constraints.api.checkConstraints.execute'); |
|
169 | 169 | |
170 | 170 | $params = $this->extractRequestParams(); |
171 | 171 | |
172 | - $this->validateParameters( $params ); |
|
173 | - $entityIds = $this->parseEntityIds( $params ); |
|
174 | - $claimIds = $this->parseClaimIds( $params ); |
|
172 | + $this->validateParameters($params); |
|
173 | + $entityIds = $this->parseEntityIds($params); |
|
174 | + $claimIds = $this->parseClaimIds($params); |
|
175 | 175 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
176 | 176 | |
177 | 177 | $this->getResult()->addValue( |
@@ -183,64 +183,64 @@ discard block |
||
183 | 183 | )->getArray() |
184 | 184 | ); |
185 | 185 | // ensure that result contains the given entity IDs even if they have no statements |
186 | - foreach ( $entityIds as $entityId ) { |
|
186 | + foreach ($entityIds as $entityId) { |
|
187 | 187 | $this->getResult()->addArrayType( |
188 | - [ $this->getModuleName(), $entityId->getSerialization() ], |
|
188 | + [$this->getModuleName(), $entityId->getSerialization()], |
|
189 | 189 | 'assoc' |
190 | 190 | ); |
191 | 191 | } |
192 | - $this->resultBuilder->markSuccess( 1 ); |
|
192 | + $this->resultBuilder->markSuccess(1); |
|
193 | 193 | } |
194 | 194 | |
195 | - private function parseEntityIds( array $params ) { |
|
195 | + private function parseEntityIds(array $params) { |
|
196 | 196 | $ids = $params[self::PARAM_ID]; |
197 | 197 | |
198 | - if ( $ids === null ) { |
|
198 | + if ($ids === null) { |
|
199 | 199 | return []; |
200 | - } elseif ( $ids === [] ) { |
|
200 | + } elseif ($ids === []) { |
|
201 | 201 | $this->errorReporter->dieError( |
202 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
202 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
203 | 203 | } |
204 | 204 | |
205 | - return array_map( function ( $id ) { |
|
205 | + return array_map(function($id) { |
|
206 | 206 | try { |
207 | - return $this->entityIdParser->parse( $id ); |
|
208 | - } catch ( EntityIdParsingException $e ) { |
|
207 | + return $this->entityIdParser->parse($id); |
|
208 | + } catch (EntityIdParsingException $e) { |
|
209 | 209 | $this->errorReporter->dieError( |
210 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
210 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
211 | 211 | } |
212 | - }, $ids ); |
|
212 | + }, $ids); |
|
213 | 213 | } |
214 | 214 | |
215 | - private function parseClaimIds( array $params ) { |
|
215 | + private function parseClaimIds(array $params) { |
|
216 | 216 | $ids = $params[self::PARAM_CLAIM_ID]; |
217 | 217 | |
218 | - if ( $ids === null ) { |
|
218 | + if ($ids === null) { |
|
219 | 219 | return []; |
220 | - } elseif ( $ids === [] ) { |
|
220 | + } elseif ($ids === []) { |
|
221 | 221 | $this->errorReporter->dieError( |
222 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
222 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
223 | 223 | } |
224 | 224 | |
225 | - foreach ( $ids as $id ) { |
|
226 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
225 | + foreach ($ids as $id) { |
|
226 | + if (!$this->statementGuidValidator->validate($id)) { |
|
227 | 227 | $this->errorReporter->dieError( |
228 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
228 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | 232 | return $ids; |
233 | 233 | } |
234 | 234 | |
235 | - private function validateParameters( array $params ) { |
|
236 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
237 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
235 | + private function validateParameters(array $params) { |
|
236 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
237 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
238 | 238 | ) { |
239 | 239 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
240 | 240 | $this->errorReporter->dieError( |
241 | 241 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
242 | 242 | } |
243 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
243 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
244 | 244 | $paramId = self::PARAM_ID; |
245 | 245 | $paramClaimId = self::PARAM_CLAIM_ID; |
246 | 246 | $this->errorReporter->dieError( |