@@ -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 | } |
@@ -28,36 +28,36 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return bool |
30 | 30 | */ |
31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
32 | - $updater->addExtensionTable( 'wbqc_constraints', __DIR__ . '/../sql/create_wbqc_constraints.sql' ); |
|
31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
32 | + $updater->addExtensionTable('wbqc_constraints', __DIR__.'/../sql/create_wbqc_constraints.sql'); |
|
33 | 33 | return true; |
34 | 34 | } |
35 | 35 | |
36 | - public static function onWikibaseChange( Change $change ) { |
|
36 | + public static function onWikibaseChange(Change $change) { |
|
37 | 37 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
38 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
39 | - self::isConstraintStatementsChange( $config, $change ) |
|
38 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
39 | + self::isConstraintStatementsChange($config, $change) |
|
40 | 40 | ) { |
41 | 41 | /** @var EntityChange $change */ |
42 | 42 | $title = Title::newMainPage(); |
43 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
43 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
44 | 44 | JobQueueGroup::singleton()->push( |
45 | - new JobSpecification( 'constraintsTableUpdate', $params, [], $title ) |
|
45 | + new JobSpecification('constraintsTableUpdate', $params, [], $title) |
|
46 | 46 | ); |
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
51 | - if ( !( $change instanceof EntityChange ) || |
|
50 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
51 | + if (!($change instanceof EntityChange) || |
|
52 | 52 | $change->getAction() !== EntityChange::UPDATE || |
53 | - !( $change->getEntityId() instanceof PropertyId ) |
|
53 | + !($change->getEntityId() instanceof PropertyId) |
|
54 | 54 | ) { |
55 | 55 | return false; |
56 | 56 | } |
57 | 57 | |
58 | 58 | $info = $change->getInfo(); |
59 | 59 | |
60 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
60 | + if (!array_key_exists('compactDiff', $info)) { |
|
61 | 61 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
62 | 62 | // so we only know that the change *might* affect the constraint statements |
63 | 63 | return true; |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | /** @var EntityDiffChangedAspects $aspects */ |
67 | 67 | $aspects = $info['compactDiff']; |
68 | 68 | |
69 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
70 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
69 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
70 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
71 | 71 | } |
72 | 72 | |
73 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
73 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
74 | 74 | $repo = WikibaseRepo::getDefaultInstance(); |
75 | 75 | |
76 | 76 | $entityContentFactory = $repo->getEntityContentFactory(); |
77 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
78 | - $entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
77 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
78 | + $entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle()); |
|
79 | 79 | $resultsCache = ResultsCache::getDefaultInstance(); |
80 | - $resultsCache->delete( $entityId ); |
|
80 | + $resultsCache->delete($entityId); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | public static function getDefaultInstance() { |
138 | 138 | static $instance = null; |
139 | 139 | |
140 | - if ( $instance === null ) { |
|
140 | + if ($instance === null) { |
|
141 | 141 | $wikibaseRepo = WikibaseRepo::getDefaultInstance(); |
142 | 142 | $entityIdFormatter = $wikibaseRepo->getEntityIdHtmlLinkFormatterFactory()->getEntityIdFormatter( |
143 | 143 | $wikibaseRepo->getLanguageFallbackLabelDescriptionLookupFactory()->newLabelDescriptionLookup( |
@@ -205,21 +205,21 @@ discard block |
||
205 | 205 | * @return DelegatingConstraintChecker |
206 | 206 | */ |
207 | 207 | public function getConstraintChecker() { |
208 | - if ( $this->delegatingConstraintChecker === null ) { |
|
208 | + if ($this->delegatingConstraintChecker === null) { |
|
209 | 209 | $this->delegatingConstraintChecker = new DelegatingConstraintChecker( |
210 | 210 | $this->lookup, |
211 | 211 | $this->getConstraintCheckerMap(), |
212 | - new CachingConstraintLookup( $this->getConstraintRepository() ), |
|
212 | + new CachingConstraintLookup($this->getConstraintRepository()), |
|
213 | 213 | $this->constraintParameterParser, |
214 | 214 | $this->statementGuidParser, |
215 | 215 | new LoggingHelper( |
216 | 216 | $this->dataFactory, |
217 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
217 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
218 | 218 | $this->config |
219 | 219 | ), |
220 | - $this->config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
221 | - $this->config->get( 'WBQualityConstraintsCheckReferences' ), |
|
222 | - $this->config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
220 | + $this->config->get('WBQualityConstraintsCheckQualifiers'), |
|
221 | + $this->config->get('WBQualityConstraintsCheckReferences'), |
|
222 | + $this->config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
223 | 223 | ); |
224 | 224 | } |
225 | 225 | |
@@ -230,10 +230,10 @@ discard block |
||
230 | 230 | * @return ConstraintChecker[] |
231 | 231 | */ |
232 | 232 | private function getConstraintCheckerMap() { |
233 | - if ( $this->constraintCheckerMap === null ) { |
|
233 | + if ($this->constraintCheckerMap === null) { |
|
234 | 234 | $connectionCheckerHelper = new ConnectionCheckerHelper(); |
235 | - $rangeCheckerHelper = new RangeCheckerHelper( $this->config, $this->unitConverter ); |
|
236 | - if ( $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ) !== '' ) { |
|
235 | + $rangeCheckerHelper = new RangeCheckerHelper($this->config, $this->unitConverter); |
|
236 | + if ($this->config->get('WBQualityConstraintsSparqlEndpoint') !== '') { |
|
237 | 237 | $sparqlHelper = new SparqlHelper( |
238 | 238 | $this->config, |
239 | 239 | $this->rdfVocabulary, |
@@ -254,74 +254,74 @@ discard block |
||
254 | 254 | ); |
255 | 255 | |
256 | 256 | $this->constraintCheckerMap = [ |
257 | - $this->config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
257 | + $this->config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
258 | 258 | => new ConflictsWithChecker( |
259 | 259 | $this->lookup, |
260 | 260 | $this->constraintParameterParser, |
261 | 261 | $connectionCheckerHelper, |
262 | 262 | $this->constraintParameterRenderer |
263 | 263 | ), |
264 | - $this->config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
264 | + $this->config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
265 | 265 | => new ItemChecker( |
266 | 266 | $this->lookup, |
267 | 267 | $this->constraintParameterParser, |
268 | 268 | $connectionCheckerHelper, |
269 | 269 | $this->constraintParameterRenderer |
270 | 270 | ), |
271 | - $this->config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
271 | + $this->config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
272 | 272 | => new TargetRequiredClaimChecker( |
273 | 273 | $this->lookup, |
274 | 274 | $this->constraintParameterParser, |
275 | 275 | $connectionCheckerHelper, |
276 | 276 | $this->constraintParameterRenderer |
277 | 277 | ), |
278 | - $this->config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
278 | + $this->config->get('WBQualityConstraintsSymmetricConstraintId') |
|
279 | 279 | => new SymmetricChecker( |
280 | 280 | $this->lookup, |
281 | 281 | $connectionCheckerHelper, |
282 | 282 | $this->constraintParameterRenderer |
283 | 283 | ), |
284 | - $this->config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
284 | + $this->config->get('WBQualityConstraintsInverseConstraintId') |
|
285 | 285 | => new InverseChecker( |
286 | 286 | $this->lookup, |
287 | 287 | $this->constraintParameterParser, |
288 | 288 | $connectionCheckerHelper, |
289 | 289 | $this->constraintParameterRenderer |
290 | 290 | ), |
291 | - $this->config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
291 | + $this->config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
292 | 292 | => new QualifierChecker(), |
293 | - $this->config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
293 | + $this->config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
294 | 294 | => new QualifiersChecker( |
295 | 295 | $this->constraintParameterParser, |
296 | 296 | $this->constraintParameterRenderer |
297 | 297 | ), |
298 | - $this->config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
298 | + $this->config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
299 | 299 | => new MandatoryQualifiersChecker( |
300 | 300 | $this->constraintParameterParser, |
301 | 301 | $this->constraintParameterRenderer |
302 | 302 | ), |
303 | - $this->config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
303 | + $this->config->get('WBQualityConstraintsRangeConstraintId') |
|
304 | 304 | => new RangeChecker( |
305 | 305 | $this->propertyDataTypeLookup, |
306 | 306 | $this->constraintParameterParser, |
307 | 307 | $rangeCheckerHelper, |
308 | 308 | $this->constraintParameterRenderer |
309 | 309 | ), |
310 | - $this->config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
310 | + $this->config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
311 | 311 | => new DiffWithinRangeChecker( |
312 | 312 | $this->constraintParameterParser, |
313 | 313 | $rangeCheckerHelper, |
314 | 314 | $this->constraintParameterRenderer, |
315 | 315 | $this->config |
316 | 316 | ), |
317 | - $this->config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
317 | + $this->config->get('WBQualityConstraintsTypeConstraintId') |
|
318 | 318 | => new TypeChecker( |
319 | 319 | $this->lookup, |
320 | 320 | $this->constraintParameterParser, |
321 | 321 | $typeCheckerHelper, |
322 | 322 | $this->config |
323 | 323 | ), |
324 | - $this->config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
324 | + $this->config->get('WBQualityConstraintsValueTypeConstraintId') |
|
325 | 325 | => new ValueTypeChecker( |
326 | 326 | $this->lookup, |
327 | 327 | $this->constraintParameterParser, |
@@ -329,36 +329,36 @@ discard block |
||
329 | 329 | $typeCheckerHelper, |
330 | 330 | $this->config |
331 | 331 | ), |
332 | - $this->config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
332 | + $this->config->get('WBQualityConstraintsSingleValueConstraintId') |
|
333 | 333 | => new SingleValueChecker(), |
334 | - $this->config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
334 | + $this->config->get('WBQualityConstraintsMultiValueConstraintId') |
|
335 | 335 | => new MultiValueChecker(), |
336 | - $this->config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
336 | + $this->config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
337 | 337 | => new UniqueValueChecker( |
338 | 338 | $this->constraintParameterRenderer, |
339 | 339 | $sparqlHelper |
340 | 340 | ), |
341 | - $this->config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
341 | + $this->config->get('WBQualityConstraintsFormatConstraintId') |
|
342 | 342 | => new FormatChecker( |
343 | 343 | $this->constraintParameterParser, |
344 | 344 | $this->constraintParameterRenderer, |
345 | 345 | $this->config, |
346 | 346 | $sparqlHelper |
347 | 347 | ), |
348 | - $this->config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
348 | + $this->config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
349 | 349 | => new CommonsLinkChecker( |
350 | 350 | $this->constraintParameterParser, |
351 | 351 | $this->constraintParameterRenderer, |
352 | 352 | $this->titleParser |
353 | 353 | ), |
354 | - $this->config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
354 | + $this->config->get('WBQualityConstraintsOneOfConstraintId') |
|
355 | 355 | => new OneOfChecker( |
356 | 356 | $this->constraintParameterParser, |
357 | 357 | $this->constraintParameterRenderer |
358 | 358 | ), |
359 | - $this->config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
359 | + $this->config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
360 | 360 | => new ValueOnlyChecker(), |
361 | - $this->config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
361 | + $this->config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
362 | 362 | => new ReferenceChecker(), |
363 | 363 | ]; |
364 | 364 | } |
@@ -370,26 +370,26 @@ discard block |
||
370 | 370 | * @return array[] |
371 | 371 | */ |
372 | 372 | public function getConstraintParameterMap() { |
373 | - if ( $this->constraintParameterMap === null ) { |
|
373 | + if ($this->constraintParameterMap === null) { |
|
374 | 374 | $this->constraintParameterMap = [ |
375 | - 'Commons link' => [ 'namespace' ], |
|
376 | - 'Conflicts with' => [ 'property', 'item' ], |
|
377 | - 'Diff within range' => [ 'property', 'minimum_quantity', 'maximum_quantity' ], |
|
378 | - 'Format' => [ 'pattern' ], |
|
379 | - 'Inverse' => [ 'property' ], |
|
380 | - 'Item' => [ 'property', 'item' ], |
|
381 | - 'Mandatory qualifiers' => [ 'property' ], |
|
375 | + 'Commons link' => ['namespace'], |
|
376 | + 'Conflicts with' => ['property', 'item'], |
|
377 | + 'Diff within range' => ['property', 'minimum_quantity', 'maximum_quantity'], |
|
378 | + 'Format' => ['pattern'], |
|
379 | + 'Inverse' => ['property'], |
|
380 | + 'Item' => ['property', 'item'], |
|
381 | + 'Mandatory qualifiers' => ['property'], |
|
382 | 382 | 'Multi value' => [], |
383 | - 'One of' => [ 'item' ], |
|
383 | + 'One of' => ['item'], |
|
384 | 384 | 'Qualifier' => [], |
385 | - 'Qualifiers' => [ 'property' ], |
|
386 | - 'Range' => [ 'minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date' ], |
|
385 | + 'Qualifiers' => ['property'], |
|
386 | + 'Range' => ['minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date'], |
|
387 | 387 | 'Single value' => [], |
388 | 388 | 'Symmetric' => [], |
389 | - 'Target required claim' => [ 'property', 'item' ], |
|
390 | - 'Type' => [ 'class', 'relation' ], |
|
389 | + 'Target required claim' => ['property', 'item'], |
|
390 | + 'Type' => ['class', 'relation'], |
|
391 | 391 | 'Unique value' => [], |
392 | - 'Value type' => [ 'class', 'relation' ] |
|
392 | + 'Value type' => ['class', 'relation'] |
|
393 | 393 | ]; |
394 | 394 | } |
395 | 395 | |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | * @return ConstraintRepository |
401 | 401 | */ |
402 | 402 | public function getConstraintRepository() { |
403 | - if ( $this->constraintRepository === null ) { |
|
403 | + if ($this->constraintRepository === null) { |
|
404 | 404 | $this->constraintRepository = new ConstraintRepository(); |
405 | 405 | } |
406 | 406 |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return self |
67 | 67 | */ |
68 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
68 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
69 | 69 | $constraintReportFactory = ConstraintReportFactory::getDefaultInstance(); |
70 | 70 | $repo = WikibaseRepo::getDefaultInstance(); |
71 | - $helperFactory = $repo->getApiHelperFactory( RequestContext::getMain() ); |
|
71 | + $helperFactory = $repo->getApiHelperFactory(RequestContext::getMain()); |
|
72 | 72 | return new self( |
73 | 73 | $main, |
74 | 74 | $name, |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | StatementGuidParser $statementGuidParser, |
99 | 99 | IBufferingStatsdDataFactory $dataFactory |
100 | 100 | ) { |
101 | - parent::__construct( $main, $name, $prefix ); |
|
101 | + parent::__construct($main, $name, $prefix); |
|
102 | 102 | |
103 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
103 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
104 | 104 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
105 | 105 | $this->statementGuidParser = $statementGuidParser; |
106 | 106 | $this->dataFactory = $dataFactory; |
@@ -114,39 +114,39 @@ discard block |
||
114 | 114 | $params = $this->extractRequestParams(); |
115 | 115 | $result = $this->getResult(); |
116 | 116 | |
117 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
118 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
117 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
118 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
119 | 119 | |
120 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
121 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
120 | + $this->checkPropertyIds($propertyIds, $result); |
|
121 | + $this->checkConstraintIds($constraintIds, $result); |
|
122 | 122 | |
123 | - $result->addValue( null, 'success', 1 ); |
|
123 | + $result->addValue(null, 'success', 1); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
127 | 127 | * @param array|null $propertyIdSerializations |
128 | 128 | * @return PropertyId[] |
129 | 129 | */ |
130 | - private function parsePropertyIds( $propertyIdSerializations ) { |
|
131 | - if ( $propertyIdSerializations === null ) { |
|
130 | + private function parsePropertyIds($propertyIdSerializations) { |
|
131 | + if ($propertyIdSerializations === null) { |
|
132 | 132 | return []; |
133 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
133 | + } elseif (empty($propertyIdSerializations)) { |
|
134 | 134 | $this->apiErrorReporter->dieError( |
135 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
135 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
136 | 136 | 'no-data' |
137 | 137 | ); |
138 | 138 | } |
139 | 139 | |
140 | 140 | return array_map( |
141 | - function( $propertyIdSerialization ) { |
|
141 | + function($propertyIdSerialization) { |
|
142 | 142 | try { |
143 | - return new PropertyId( $propertyIdSerialization ); |
|
144 | - } catch ( InvalidArgumentException $e ) { |
|
143 | + return new PropertyId($propertyIdSerialization); |
|
144 | + } catch (InvalidArgumentException $e) { |
|
145 | 145 | $this->apiErrorReporter->dieError( |
146 | 146 | "Invalid id: $propertyIdSerialization", |
147 | 147 | 'invalid-property-id', |
148 | 148 | 0, // default argument |
149 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
149 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
150 | 150 | ); |
151 | 151 | } |
152 | 152 | }, |
@@ -158,35 +158,35 @@ discard block |
||
158 | 158 | * @param array|null $constraintIds |
159 | 159 | * @return string[] |
160 | 160 | */ |
161 | - private function parseConstraintIds( $constraintIds ) { |
|
162 | - if ( $constraintIds === null ) { |
|
161 | + private function parseConstraintIds($constraintIds) { |
|
162 | + if ($constraintIds === null) { |
|
163 | 163 | return []; |
164 | - } elseif ( empty( $constraintIds ) ) { |
|
164 | + } elseif (empty($constraintIds)) { |
|
165 | 165 | $this->apiErrorReporter->dieError( |
166 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
166 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
167 | 167 | 'no-data' |
168 | 168 | ); |
169 | 169 | } |
170 | 170 | |
171 | 171 | return array_map( |
172 | - function( $constraintId ) { |
|
172 | + function($constraintId) { |
|
173 | 173 | try { |
174 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
175 | - if ( !$propertyId instanceof PropertyId ) { |
|
174 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
175 | + if (!$propertyId instanceof PropertyId) { |
|
176 | 176 | $this->apiErrorReporter->dieError( |
177 | 177 | "Invalid property ID: {$propertyId->getSerialization()}", |
178 | 178 | 'invalid-property-id', |
179 | 179 | 0, // default argument |
180 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
180 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
181 | 181 | ); |
182 | 182 | } |
183 | 183 | return $constraintId; |
184 | - } catch ( StatementGuidParsingException $e ) { |
|
184 | + } catch (StatementGuidParsingException $e) { |
|
185 | 185 | $this->apiErrorReporter->dieError( |
186 | 186 | "Invalid statement GUID: $constraintId", |
187 | 187 | 'invalid-guid', |
188 | 188 | 0, // default argument |
189 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
189 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
190 | 190 | ); |
191 | 191 | } |
192 | 192 | }, |
@@ -198,12 +198,12 @@ discard block |
||
198 | 198 | * @param PropertyId[] $propertyIds |
199 | 199 | * @param ApiResult $result |
200 | 200 | */ |
201 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ) { |
|
202 | - foreach ( $propertyIds as $propertyId ) { |
|
203 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
204 | - $allConstraintExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnPropertyId( $propertyId ); |
|
205 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
206 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
201 | + private function checkPropertyIds(array $propertyIds, ApiResult $result) { |
|
202 | + foreach ($propertyIds as $propertyId) { |
|
203 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
204 | + $allConstraintExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnPropertyId($propertyId); |
|
205 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
206 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | } |
@@ -212,14 +212,14 @@ discard block |
||
212 | 212 | * @param string[] $constraintIds |
213 | 213 | * @param ApiResult $result |
214 | 214 | */ |
215 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ) { |
|
216 | - foreach ( $constraintIds as $constraintId ) { |
|
217 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
215 | + private function checkConstraintIds(array $constraintIds, ApiResult $result) { |
|
216 | + foreach ($constraintIds as $constraintId) { |
|
217 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
218 | 218 | // already checked as part of checkPropertyIds() |
219 | 219 | continue; |
220 | 220 | } |
221 | - $constraintParameterExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnConstraintId( $constraintId ); |
|
222 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
221 | + $constraintParameterExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnConstraintId($constraintId); |
|
222 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
@@ -227,17 +227,17 @@ discard block |
||
227 | 227 | * @param PropertyId $propertyId |
228 | 228 | * @return string[] |
229 | 229 | */ |
230 | - private function getResultPathForPropertyId( PropertyId $propertyId ) { |
|
231 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
230 | + private function getResultPathForPropertyId(PropertyId $propertyId) { |
|
231 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
235 | 235 | * @param string $constraintId |
236 | 236 | * @return string[] |
237 | 237 | */ |
238 | - private function getResultPathForConstraintId( $constraintId ) { |
|
239 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
240 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
238 | + private function getResultPathForConstraintId($constraintId) { |
|
239 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
240 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | * @param ConstraintParameterException[]|null $constraintParameterExceptions |
248 | 248 | * @param ApiResult $result |
249 | 249 | */ |
250 | - private function addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, ApiResult $result ) { |
|
251 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
252 | - if ( $constraintParameterExceptions === null ) { |
|
250 | + private function addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, ApiResult $result) { |
|
251 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
252 | + if ($constraintParameterExceptions === null) { |
|
253 | 253 | $result->addValue( |
254 | 254 | $path, |
255 | 255 | self::KEY_STATUS, |
@@ -259,12 +259,12 @@ discard block |
||
259 | 259 | $result->addValue( |
260 | 260 | $path, |
261 | 261 | self::KEY_STATUS, |
262 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
262 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
263 | 263 | ); |
264 | 264 | $result->addValue( |
265 | 265 | $path, |
266 | 266 | self::KEY_PROBLEMS, |
267 | - array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions ) |
|
267 | + array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions) |
|
268 | 268 | ); |
269 | 269 | } |
270 | 270 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * @param ConstraintParameterException $e |
276 | 276 | * @return array |
277 | 277 | */ |
278 | - private function formatConstraintParameterException( ConstraintParameterException $e ) { |
|
278 | + private function formatConstraintParameterException(ConstraintParameterException $e) { |
|
279 | 279 | return [ |
280 | 280 | self::KEY_MESSAGE_HTML => $e->getMessage(), |
281 | 281 | ]; |
@@ -87,23 +87,23 @@ discard block |
||
87 | 87 | * @return bool |
88 | 88 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
89 | 89 | */ |
90 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
91 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
90 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
91 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
92 | 92 | if ( ++$entitiesChecked > $maxEntities ) { |
93 | - throw new OverflowException( 'Too many entities to check' ); |
|
93 | + throw new OverflowException('Too many entities to check'); |
|
94 | 94 | } |
95 | 95 | |
96 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
97 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
96 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
97 | + if (!($item instanceof StatementListProvider)) { |
|
98 | 98 | return false; // lookup failed, probably because item doesn't exist |
99 | 99 | } |
100 | 100 | |
101 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
101 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
102 | 102 | /** @var Statement $statement */ |
103 | - foreach ( $item->getStatements()->getByPropertyId( new PropertyId( $subclassId ) ) as $statement ) { |
|
103 | + foreach ($item->getStatements()->getByPropertyId(new PropertyId($subclassId)) as $statement) { |
|
104 | 104 | $mainSnak = $statement->getMainSnak(); |
105 | 105 | |
106 | - if ( !( $this->hasCorrectType( $mainSnak ) ) ) { |
|
106 | + if (!($this->hasCorrectType($mainSnak))) { |
|
107 | 107 | continue; |
108 | 108 | } |
109 | 109 | /** @var PropertyValueSnak $mainSnak */ |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | $dataValue = $mainSnak->getDataValue(); |
113 | 113 | $comparativeClass = $dataValue->getEntityId(); |
114 | 114 | |
115 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
115 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
116 | 116 | return true; |
117 | 117 | } |
118 | 118 | |
119 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
119 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
120 | 120 | return true; |
121 | 121 | } |
122 | 122 | } |
@@ -137,14 +137,14 @@ discard block |
||
137 | 137 | * @return CachedBool |
138 | 138 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
139 | 139 | */ |
140 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
140 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
141 | 141 | try { |
142 | 142 | return new CachedBool( |
143 | - $this->isSubclassOf( $comparativeClass, $classesToCheck ), |
|
143 | + $this->isSubclassOf($comparativeClass, $classesToCheck), |
|
144 | 144 | Metadata::blank() |
145 | 145 | ); |
146 | - } catch ( OverflowException $e ) { |
|
147 | - if ( $this->sparqlHelper !== null ) { |
|
146 | + } catch (OverflowException $e) { |
|
147 | + if ($this->sparqlHelper !== null) { |
|
148 | 148 | $this->dataFactory->increment( |
149 | 149 | 'wikibase.quality.constraints.sparql.typeFallback' |
150 | 150 | ); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | /* withInstance = */ false |
155 | 155 | ); |
156 | 156 | } else { |
157 | - return new CachedBool( false, Metadata::blank() ); |
|
157 | + return new CachedBool(false, Metadata::blank()); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | } |
@@ -172,14 +172,14 @@ discard block |
||
172 | 172 | * @return CachedBool |
173 | 173 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
174 | 174 | */ |
175 | - public function hasClassInRelation( StatementList $statements, $relationId, array $classesToCheck ) { |
|
175 | + public function hasClassInRelation(StatementList $statements, $relationId, array $classesToCheck) { |
|
176 | 176 | $metadatas = []; |
177 | 177 | |
178 | 178 | /** @var Statement $statement */ |
179 | - foreach ( $statements->getByPropertyId( new PropertyId( $relationId ) ) as $statement ) { |
|
179 | + foreach ($statements->getByPropertyId(new PropertyId($relationId)) as $statement) { |
|
180 | 180 | $mainSnak = $statement->getMainSnak(); |
181 | 181 | |
182 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
182 | + if (!$this->hasCorrectType($mainSnak)) { |
|
183 | 183 | continue; |
184 | 184 | } |
185 | 185 | /** @var PropertyValueSnak $mainSnak */ |
@@ -188,28 +188,28 @@ discard block |
||
188 | 188 | $dataValue = $mainSnak->getDataValue(); |
189 | 189 | $comparativeClass = $dataValue->getEntityId(); |
190 | 190 | |
191 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
191 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
192 | 192 | // discard $metadatas, we know this is fresh |
193 | - return new CachedBool( true, Metadata::blank() ); |
|
193 | + return new CachedBool(true, Metadata::blank()); |
|
194 | 194 | } |
195 | 195 | |
196 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
196 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
197 | 197 | $metadatas[] = $result->getMetadata(); |
198 | - if ( $result->getBool() ) { |
|
198 | + if ($result->getBool()) { |
|
199 | 199 | return new CachedBool( |
200 | 200 | true, |
201 | - Metadata::merge( $metadatas ) |
|
201 | + Metadata::merge($metadatas) |
|
202 | 202 | ); |
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | 206 | return new CachedBool( |
207 | 207 | false, |
208 | - Metadata::merge( $metadatas ) |
|
208 | + Metadata::merge($metadatas) |
|
209 | 209 | ); |
210 | 210 | } |
211 | 211 | |
212 | - private function hasCorrectType( Snak $mainSnak ) { |
|
212 | + private function hasCorrectType(Snak $mainSnak) { |
|
213 | 213 | return $mainSnak instanceof PropertyValueSnak |
214 | 214 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
215 | 215 | } |
@@ -223,20 +223,20 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @return string Localized HTML message |
225 | 225 | */ |
226 | - public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) { |
|
226 | + public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) { |
|
227 | 227 | // Possible messages: |
228 | 228 | // wbqc-violation-message-type-instance |
229 | 229 | // wbqc-violation-message-type-subclass |
230 | 230 | // wbqc-violation-message-valueType-instance |
231 | 231 | // wbqc-violation-message-valueType-subclass |
232 | - $message = wfMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ); |
|
232 | + $message = wfMessage('wbqc-violation-message-'.$checker.'-'.$relation); |
|
233 | 233 | |
234 | 234 | $message->rawParams( |
235 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ), |
|
236 | - $this->constraintParameterRenderer->formatEntityId( $entityId, Role::SUBJECT ) |
|
235 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::CONSTRAINT_PROPERTY), |
|
236 | + $this->constraintParameterRenderer->formatEntityId($entityId, Role::SUBJECT) |
|
237 | 237 | ); |
238 | - $message->numParams( count( $classes ) ); |
|
239 | - $message->rawParams( $this->constraintParameterRenderer->formatItemIdList( $classes, Role::OBJECT ) ); |
|
238 | + $message->numParams(count($classes)); |
|
239 | + $message->rawParams($this->constraintParameterRenderer->formatItemIdList($classes, Role::OBJECT)); |
|
240 | 240 | |
241 | 241 | return $message->escaped(); |
242 | 242 | } |
@@ -91,18 +91,18 @@ discard block |
||
91 | 91 | $this->cache = $cache; |
92 | 92 | $this->dataFactory = $dataFactory; |
93 | 93 | |
94 | - $this->entityPrefix = $rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY ); |
|
94 | + $this->entityPrefix = $rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY); |
|
95 | 95 | $this->prefixes = <<<EOT |
96 | -PREFIX wd: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY )}> |
|
97 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
98 | -PREFIX wdt: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_DIRECT_CLAIM )}> |
|
99 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}> |
|
100 | -PREFIX p: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM )}> |
|
101 | -PREFIX ps: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM_STATEMENT )}> |
|
102 | -PREFIX pq: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER )}> |
|
103 | -PREFIX pqv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER_VALUE )}> |
|
104 | -PREFIX pr: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE )}> |
|
105 | -PREFIX prv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE_VALUE )}> |
|
96 | +PREFIX wd: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY)}> |
|
97 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
98 | +PREFIX wdt: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_DIRECT_CLAIM)}> |
|
99 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}> |
|
100 | +PREFIX p: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM)}> |
|
101 | +PREFIX ps: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM_STATEMENT)}> |
|
102 | +PREFIX pq: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER)}> |
|
103 | +PREFIX pqv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER_VALUE)}> |
|
104 | +PREFIX pr: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE)}> |
|
105 | +PREFIX prv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE_VALUE)}> |
|
106 | 106 | PREFIX wikibase: <http://wikiba.se/ontology#> |
107 | 107 | PREFIX wikibase-beta: <http://wikiba.se/ontology-beta#> |
108 | 108 | EOT; |
@@ -117,21 +117,21 @@ discard block |
||
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,47 +356,47 @@ 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 ); |
|
362 | + $textHash = hash('sha256', $text); |
|
364 | 363 | $cacheKey = $this->cache->makeKey( |
365 | 364 | 'WikibaseQualityConstraints', // extension |
366 | 365 | 'regex', // action |
367 | 366 | 'WDQS-Java', // regex flavor |
368 | - hash( 'sha256', $regex ) |
|
367 | + hash('sha256', $regex) |
|
369 | 368 | ); |
370 | - $cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
369 | + $cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
371 | 370 | |
372 | 371 | $cacheMapArray = $this->cache->getWithSetCallback( |
373 | 372 | $cacheKey, |
374 | 373 | WANObjectCache::TTL_DAY, |
375 | - function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) { |
|
374 | + function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) { |
|
376 | 375 | // Initialize the cache map if not set |
377 | - if ( $cacheMapArray === false ) { |
|
376 | + if ($cacheMapArray === false) { |
|
378 | 377 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
379 | - $this->dataFactory->increment( $key ); |
|
378 | + $this->dataFactory->increment($key); |
|
380 | 379 | return []; |
381 | 380 | } |
382 | 381 | |
383 | 382 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
384 | - $this->dataFactory->increment( $key ); |
|
385 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize ); |
|
386 | - if ( $cacheMap->has( $textHash ) ) { |
|
383 | + $this->dataFactory->increment($key); |
|
384 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize); |
|
385 | + if ($cacheMap->has($textHash)) { |
|
387 | 386 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
388 | - $this->dataFactory->increment( $key ); |
|
389 | - $cacheMap->get( $textHash ); // ping cache |
|
387 | + $this->dataFactory->increment($key); |
|
388 | + $cacheMap->get($textHash); // ping cache |
|
390 | 389 | } else { |
391 | 390 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
392 | - $this->dataFactory->increment( $key ); |
|
391 | + $this->dataFactory->increment($key); |
|
393 | 392 | try { |
394 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
395 | - } catch ( ConstraintParameterException $e ) { |
|
393 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
394 | + } catch (ConstraintParameterException $e) { |
|
396 | 395 | $matches = [ |
397 | 396 | 'type' => ConstraintParameterException::class, |
398 | 397 | 'message' => $e->getMessage(), |
399 | 398 | ]; |
400 | - } catch ( SparqlHelperException $e ) { |
|
399 | + } catch (SparqlHelperException $e) { |
|
401 | 400 | // don’t cache this |
402 | 401 | return $cacheMap->toArray(); |
403 | 402 | } |
@@ -421,27 +420,27 @@ discard block |
||
421 | 420 | ] |
422 | 421 | ); |
423 | 422 | |
424 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
423 | + if (isset($cacheMapArray[$textHash])) { |
|
425 | 424 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
426 | - $this->dataFactory->increment( $key ); |
|
425 | + $this->dataFactory->increment($key); |
|
427 | 426 | $matches = $cacheMapArray[$textHash]; |
428 | - if ( is_bool( $matches ) ) { |
|
427 | + if (is_bool($matches)) { |
|
429 | 428 | return $matches; |
430 | - } elseif ( is_array( $matches ) && |
|
431 | - $matches['type'] == ConstraintParameterException::class ) { |
|
432 | - throw new ConstraintParameterException( $matches['message'] ); |
|
429 | + } elseif (is_array($matches) && |
|
430 | + $matches['type'] == ConstraintParameterException::class) { |
|
431 | + throw new ConstraintParameterException($matches['message']); |
|
433 | 432 | } else { |
434 | 433 | throw new MWException( |
435 | - 'Value of unknown type in object cache (' . |
|
436 | - 'cache key: ' . $cacheKey . ', ' . |
|
437 | - 'cache map key: ' . $textHash . ', ' . |
|
438 | - 'value type: ' . gettype( $matches ) . ')' |
|
434 | + 'Value of unknown type in object cache ('. |
|
435 | + 'cache key: '.$cacheKey.', '. |
|
436 | + 'cache map key: '.$textHash.', '. |
|
437 | + 'value type: '.gettype($matches).')' |
|
439 | 438 | ); |
440 | 439 | } |
441 | 440 | } else { |
442 | 441 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
443 | - $this->dataFactory->increment( $key ); |
|
444 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
442 | + $this->dataFactory->increment($key); |
|
443 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
445 | 444 | } |
446 | 445 | } |
447 | 446 | |
@@ -456,26 +455,26 @@ discard block |
||
456 | 455 | * @throws SparqlHelperException if the query times out or some other error occurs |
457 | 456 | * @throws ConstraintParameterException if the $regex is invalid |
458 | 457 | */ |
459 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
460 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
461 | - $regexStringLiteral = $this->stringLiteral( '^' . $regex . '$' ); |
|
458 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
459 | + $textStringLiteral = $this->stringLiteral($text); |
|
460 | + $regexStringLiteral = $this->stringLiteral('^'.$regex.'$'); |
|
462 | 461 | |
463 | 462 | $query = <<<EOF |
464 | 463 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
465 | 464 | EOF; |
466 | 465 | |
467 | - $result = $this->runQuery( $query ); |
|
466 | + $result = $this->runQuery($query); |
|
468 | 467 | |
469 | 468 | $vars = $result->getArray()['results']['bindings'][0]; |
470 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
469 | + if (array_key_exists('matches', $vars)) { |
|
471 | 470 | // true or false ⇒ regex okay, text matches or not |
472 | 471 | return $vars['matches']['value'] === 'true'; |
473 | 472 | } else { |
474 | 473 | // empty result: regex broken |
475 | 474 | throw new ConstraintParameterException( |
476 | - wfMessage( 'wbqc-violation-message-parameter-regex' ) |
|
477 | - ->rawParams( ConstraintParameterRenderer::formatByRole( Role::CONSTRAINT_PARAMETER_VALUE, |
|
478 | - '<code><nowiki>' . htmlspecialchars( $regex ) . '</nowiki></code>' ) ) |
|
475 | + wfMessage('wbqc-violation-message-parameter-regex') |
|
476 | + ->rawParams(ConstraintParameterRenderer::formatByRole(Role::CONSTRAINT_PARAMETER_VALUE, |
|
477 | + '<code><nowiki>'.htmlspecialchars($regex).'</nowiki></code>')) |
|
479 | 478 | ->escaped() |
480 | 479 | ); |
481 | 480 | } |
@@ -488,14 +487,14 @@ discard block |
||
488 | 487 | * |
489 | 488 | * @return boolean |
490 | 489 | */ |
491 | - public function isTimeout( $responseContent ) { |
|
492 | - $timeoutRegex = implode( '|', array_map( |
|
493 | - function ( $fqn ) { |
|
494 | - return preg_quote( $fqn, '/' ); |
|
490 | + public function isTimeout($responseContent) { |
|
491 | + $timeoutRegex = implode('|', array_map( |
|
492 | + function($fqn) { |
|
493 | + return preg_quote($fqn, '/'); |
|
495 | 494 | }, |
496 | - $this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' ) |
|
497 | - ) ); |
|
498 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
495 | + $this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses') |
|
496 | + )); |
|
497 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
499 | 498 | } |
500 | 499 | |
501 | 500 | /** |
@@ -507,17 +506,17 @@ discard block |
||
507 | 506 | * @return integer|boolean the max-age (in seconds) |
508 | 507 | * or a plain boolean if no max-age can be determined |
509 | 508 | */ |
510 | - public function getCacheMaxAge( $responseHeaders ) { |
|
509 | + public function getCacheMaxAge($responseHeaders) { |
|
511 | 510 | if ( |
512 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
513 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
511 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
512 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
514 | 513 | ) { |
515 | 514 | $maxage = []; |
516 | 515 | if ( |
517 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
518 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
516 | + array_key_exists('cache-control', $responseHeaders) && |
|
517 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
519 | 518 | ) { |
520 | - return intval( $maxage[1] ); |
|
519 | + return intval($maxage[1]); |
|
521 | 520 | } else { |
522 | 521 | return true; |
523 | 522 | } |
@@ -535,59 +534,58 @@ discard block |
||
535 | 534 | * |
536 | 535 | * @throws SparqlHelperException if the query times out or some other error occurs |
537 | 536 | */ |
538 | - public function runQuery( $query ) { |
|
537 | + public function runQuery($query) { |
|
539 | 538 | |
540 | - $endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
541 | - $maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
542 | - $url = $endpoint . '?' . http_build_query( |
|
539 | + $endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint'); |
|
540 | + $maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
541 | + $url = $endpoint.'?'.http_build_query( |
|
543 | 542 | [ |
544 | - 'query' => "#wbqc\n" . $this->prefixes . $query, |
|
543 | + 'query' => "#wbqc\n".$this->prefixes.$query, |
|
545 | 544 | 'format' => 'json', |
546 | 545 | 'maxQueryTimeMillis' => $maxQueryTimeMillis, |
547 | 546 | ], |
548 | - null, ini_get( 'arg_separator.output' ), |
|
547 | + null, ini_get('arg_separator.output'), |
|
549 | 548 | // encode spaces with %20, not + |
550 | 549 | PHP_QUERY_RFC3986 |
551 | 550 | ); |
552 | 551 | |
553 | 552 | $options = [ |
554 | 553 | 'method' => 'GET', |
555 | - 'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ), |
|
554 | + 'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000), |
|
556 | 555 | 'connectTimeout' => 'default', |
557 | 556 | ]; |
558 | - $request = MWHttpRequest::factory( $url, $options ); |
|
559 | - $startTime = microtime( true ); |
|
557 | + $request = MWHttpRequest::factory($url, $options); |
|
558 | + $startTime = microtime(true); |
|
560 | 559 | $status = $request->execute(); |
561 | - $endTime = microtime( true ); |
|
560 | + $endTime = microtime(true); |
|
562 | 561 | $this->dataFactory->timing( |
563 | 562 | 'wikibase.quality.constraints.sparql.timing', |
564 | - ( $endTime - $startTime ) * 1000 |
|
563 | + ($endTime - $startTime) * 1000 |
|
565 | 564 | ); |
566 | 565 | |
567 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
568 | - if ( $maxAge ) { |
|
569 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
566 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
567 | + if ($maxAge) { |
|
568 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
570 | 569 | } |
571 | 570 | |
572 | - if ( $status->isOK() ) { |
|
571 | + if ($status->isOK()) { |
|
573 | 572 | $json = $request->getContent(); |
574 | - $arr = json_decode( $json, true ); |
|
573 | + $arr = json_decode($json, true); |
|
575 | 574 | return new CachedQueryResults( |
576 | 575 | $arr, |
577 | 576 | Metadata::ofCachingMetadata( |
578 | 577 | $maxAge ? |
579 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
580 | - CachingMetadata::fresh() |
|
578 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
581 | 579 | ) |
582 | 580 | ); |
583 | 581 | } else { |
584 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
582 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
585 | 583 | |
586 | 584 | $this->dataFactory->increment( |
587 | 585 | "wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}" |
588 | 586 | ); |
589 | 587 | |
590 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
588 | + if ($this->isTimeout($request->getContent())) { |
|
591 | 589 | $this->dataFactory->increment( |
592 | 590 | 'wikibase.quality.constraints.sparql.error.timeout' |
593 | 591 | ); |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | ) { |
117 | 117 | $results = []; |
118 | 118 | $metadatas = []; |
119 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds ) ) { |
|
119 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds)) { |
|
120 | 120 | $storedEntityIds = []; |
121 | - foreach ( $entityIds as $entityId ) { |
|
122 | - $storedResults = $this->getStoredResults( $entityId ); |
|
123 | - if ( $storedResults !== null ) { |
|
121 | + foreach ($entityIds as $entityId) { |
|
122 | + $storedResults = $this->getStoredResults($entityId); |
|
123 | + if ($storedResults !== null) { |
|
124 | 124 | $this->dataFactory->increment( |
125 | 125 | 'wikibase.quality.constraints.cache.entity.hit' |
126 | 126 | ); |
@@ -129,20 +129,20 @@ discard block |
||
129 | 129 | $storedEntityIds[] = $entityId; |
130 | 130 | } |
131 | 131 | } |
132 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
132 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
133 | 133 | } |
134 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
134 | + if ($entityIds !== [] || $claimIds !== []) { |
|
135 | 135 | $this->dataFactory->updateCount( |
136 | 136 | 'wikibase.quality.constraints.cache.entity.miss', |
137 | - count( $entityIds ) |
|
137 | + count($entityIds) |
|
138 | 138 | ); |
139 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds ); |
|
139 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds); |
|
140 | 140 | $results += $response->getArray(); |
141 | 141 | $metadatas[] = $response->getMetadata(); |
142 | 142 | } |
143 | 143 | return new CachedCheckConstraintsResponse( |
144 | 144 | $results, |
145 | - Metadata::merge( $metadatas ) |
|
145 | + Metadata::merge($metadatas) |
|
146 | 146 | ); |
147 | 147 | } |
148 | 148 | |
@@ -175,17 +175,17 @@ discard block |
||
175 | 175 | array $claimIds, |
176 | 176 | array $constraintIds = null |
177 | 177 | ) { |
178 | - $results = $this->resultsBuilder->getResults( $entityIds, $claimIds, $constraintIds ); |
|
178 | + $results = $this->resultsBuilder->getResults($entityIds, $claimIds, $constraintIds); |
|
179 | 179 | |
180 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds ) ) { |
|
181 | - foreach ( $entityIds as $entityId ) { |
|
180 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds)) { |
|
181 | + foreach ($entityIds as $entityId) { |
|
182 | 182 | $value = [ |
183 | 183 | 'results' => $results->getArray()[$entityId->getSerialization()], |
184 | 184 | 'latestRevisionIds' => $this->getLatestRevisionIds( |
185 | 185 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
186 | 186 | ), |
187 | 187 | ]; |
188 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
188 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
@@ -218,45 +218,44 @@ discard block |
||
218 | 218 | public function getStoredResults( |
219 | 219 | EntityId $entityId |
220 | 220 | ) { |
221 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
222 | - $now = call_user_func( $this->microtime, true ); |
|
221 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
222 | + $now = call_user_func($this->microtime, true); |
|
223 | 223 | |
224 | - if ( $value === false ) { |
|
224 | + if ($value === false) { |
|
225 | 225 | return null; |
226 | 226 | } |
227 | 227 | |
228 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
228 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
229 | 229 | |
230 | 230 | $dependedEntityIds = array_map( |
231 | - [ $this->entityIdParser, "parse" ], |
|
232 | - array_keys( $value['latestRevisionIds'] ) |
|
231 | + [$this->entityIdParser, "parse"], |
|
232 | + array_keys($value['latestRevisionIds']) |
|
233 | 233 | ); |
234 | 234 | |
235 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
235 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
236 | 236 | return null; |
237 | 237 | } |
238 | 238 | |
239 | 239 | $cachingMetadata = $ageInSeconds > 0 ? |
240 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
241 | - CachingMetadata::fresh(); |
|
240 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
242 | 241 | |
243 | - if ( is_array( $value['results'] ) ) { |
|
244 | - array_walk( $value['results'], [ $this, 'updateCachingMetadata' ], $cachingMetadata ); |
|
242 | + if (is_array($value['results'])) { |
|
243 | + array_walk($value['results'], [$this, 'updateCachingMetadata'], $cachingMetadata); |
|
245 | 244 | } |
246 | 245 | |
247 | 246 | return new CachedCheckConstraintsResponse( |
248 | - [ $entityId->getSerialization() => $value['results'] ], |
|
247 | + [$entityId->getSerialization() => $value['results']], |
|
249 | 248 | array_reduce( |
250 | 249 | $dependedEntityIds, |
251 | - function( Metadata $metadata, EntityId $entityId ) { |
|
252 | - return Metadata::merge( [ |
|
250 | + function(Metadata $metadata, EntityId $entityId) { |
|
251 | + return Metadata::merge([ |
|
253 | 252 | $metadata, |
254 | 253 | Metadata::ofDependencyMetadata( |
255 | - DependencyMetadata::ofEntityId( $entityId ) |
|
254 | + DependencyMetadata::ofEntityId($entityId) |
|
256 | 255 | ) |
257 | - ] ); |
|
256 | + ]); |
|
258 | 257 | }, |
259 | - Metadata::ofCachingMetadata( $cachingMetadata ) |
|
258 | + Metadata::ofCachingMetadata($cachingMetadata) |
|
260 | 259 | ) |
261 | 260 | ); |
262 | 261 | } |
@@ -265,39 +264,39 @@ discard block |
||
265 | 264 | * @param EntityId[] $entityIds |
266 | 265 | * @return int[] |
267 | 266 | */ |
268 | - private function getLatestRevisionIds( array $entityIds ) { |
|
267 | + private function getLatestRevisionIds(array $entityIds) { |
|
269 | 268 | $revisionInformations = $this->wikiPageEntityMetaDataAccessor->loadRevisionInformation( |
270 | 269 | $entityIds, |
271 | 270 | EntityRevisionLookup::LATEST_FROM_REPLICA |
272 | 271 | ); |
273 | 272 | $latestRevisionIds = []; |
274 | - foreach ( $revisionInformations as $serialization => $revisionInformation ) { |
|
273 | + foreach ($revisionInformations as $serialization => $revisionInformation) { |
|
275 | 274 | $latestRevisionIds[$serialization] = $revisionInformation->page_latest; |
276 | 275 | } |
277 | 276 | return $latestRevisionIds; |
278 | 277 | } |
279 | 278 | |
280 | - public function updateCachingMetadata( &$element, $key, CachingMetadata $cachingMetadata ) { |
|
281 | - if ( $key === 'cached' ) { |
|
282 | - $element = CachingMetadata::merge( [ |
|
279 | + public function updateCachingMetadata(&$element, $key, CachingMetadata $cachingMetadata) { |
|
280 | + if ($key === 'cached') { |
|
281 | + $element = CachingMetadata::merge([ |
|
283 | 282 | $cachingMetadata, |
284 | - CachingMetadata::ofArray( $element ), |
|
285 | - ] )->toArray(); |
|
283 | + CachingMetadata::ofArray($element), |
|
284 | + ])->toArray(); |
|
286 | 285 | } |
287 | 286 | if ( |
288 | - is_array( $element ) && |
|
289 | - array_key_exists( 'constraint', $element ) && |
|
290 | - in_array( $element['constraint']['type'], $this->possiblyStaleConstraintTypes, true ) |
|
287 | + is_array($element) && |
|
288 | + array_key_exists('constraint', $element) && |
|
289 | + in_array($element['constraint']['type'], $this->possiblyStaleConstraintTypes, true) |
|
291 | 290 | ) { |
292 | - $element['cached'] = CachingMetadata::merge( [ |
|
291 | + $element['cached'] = CachingMetadata::merge([ |
|
293 | 292 | $cachingMetadata, |
294 | 293 | CachingMetadata::ofArray( |
295 | - array_key_exists( 'cached', $element ) ? $element['cached'] : null |
|
294 | + array_key_exists('cached', $element) ? $element['cached'] : null |
|
296 | 295 | ), |
297 | - ] )->toArray(); |
|
296 | + ])->toArray(); |
|
298 | 297 | } |
299 | - if ( is_array( $element ) ) { |
|
300 | - array_walk( $element, [ $this, __FUNCTION__ ], $cachingMetadata ); |
|
298 | + if (is_array($element)) { |
|
299 | + array_walk($element, [$this, __FUNCTION__], $cachingMetadata); |
|
301 | 300 | } |
302 | 301 | } |
303 | 302 | |
@@ -306,7 +305,7 @@ discard block |
||
306 | 305 | * |
307 | 306 | * @param callable $microtime |
308 | 307 | */ |
309 | - public function setMicrotimeFunction( callable $microtime ) { |
|
308 | + public function setMicrotimeFunction(callable $microtime) { |
|
310 | 309 | $this->microtime = $microtime; |
311 | 310 | } |
312 | 311 |
@@ -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, |
@@ -130,11 +129,11 @@ discard block |
||
130 | 129 | 'link' => $link, |
131 | 130 | 'discussLink' => $title->getTalkPage()->getFullURL(), |
132 | 131 | ]; |
133 | - if ( $this->config->get( 'WBQualityConstraintsIncludeDetailInApi' ) ) { |
|
132 | + if ($this->config->get('WBQualityConstraintsIncludeDetailInApi')) { |
|
134 | 133 | $parameters = $checkResult->getParameters(); |
135 | 134 | $constraint += [ |
136 | 135 | 'detail' => $parameters, |
137 | - 'detailHTML' => $this->constraintParameterRenderer->formatParameters( $parameters ), |
|
136 | + 'detailHTML' => $this->constraintParameterRenderer->formatParameters($parameters), |
|
138 | 137 | ]; |
139 | 138 | } |
140 | 139 | |
@@ -144,14 +143,14 @@ discard block |
||
144 | 143 | 'constraint' => $constraint |
145 | 144 | ]; |
146 | 145 | $message = $checkResult->getMessage(); |
147 | - if ( $message ) { |
|
146 | + if ($message) { |
|
148 | 147 | $result['message-html'] = $message; |
149 | 148 | } |
150 | - if ( $checkResult->getContext()->getType() === Context::TYPE_STATEMENT ) { |
|
149 | + if ($checkResult->getContext()->getType() === Context::TYPE_STATEMENT) { |
|
151 | 150 | $result['claim'] = $checkResult->getContext()->getSnakStatement()->getGuid(); |
152 | 151 | } |
153 | 152 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
154 | - if ( $cachingMetadataArray !== null ) { |
|
153 | + if ($cachingMetadataArray !== null) { |
|
155 | 154 | $result['cached'] = $cachingMetadataArray; |
156 | 155 | } |
157 | 156 |
@@ -86,6 +86,6 @@ |
||
86 | 86 | * @param array|null $result |
87 | 87 | * @param array[] &$container |
88 | 88 | */ |
89 | - public function storeCheckResultInArray( array $result = null, array &$container ); |
|
89 | + public function storeCheckResultInArray(array $result = null, array &$container); |
|
90 | 90 | |
91 | 91 | } |