@@ -24,22 +24,22 @@ |
||
24 | 24 | */ |
25 | 25 | const NULL_PROPERTY_ID = 'P2147483647'; |
26 | 26 | |
27 | - public function __construct( ContextCursor $contextCursor ) { |
|
27 | + public function __construct(ContextCursor $contextCursor) { |
|
28 | 28 | $constraint = new Constraint( |
29 | 29 | 'null', |
30 | - new PropertyId( self::NULL_PROPERTY_ID ), |
|
30 | + new PropertyId(self::NULL_PROPERTY_ID), |
|
31 | 31 | 'none', |
32 | 32 | [] |
33 | 33 | ); |
34 | - parent::__construct( $contextCursor, $constraint ); |
|
34 | + parent::__construct($contextCursor, $constraint); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function getConstraint() { |
38 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
38 | + throw new DomainException('NullResult holds no constraint'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | public function getConstraintId() { |
42 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
42 | + throw new DomainException('NullResult holds no constraint'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | } |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | * @param array[] &$container |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - protected function &getClaimsArray( array &$container ) { |
|
30 | + protected function &getClaimsArray(array &$container) { |
|
31 | 31 | $entityId = $this->getEntityId(); |
32 | 32 | |
33 | - if ( !array_key_exists( $entityId, $container ) ) { |
|
33 | + if (!array_key_exists($entityId, $container)) { |
|
34 | 34 | $container[$entityId] = []; |
35 | 35 | } |
36 | 36 | $entityContainer = &$container[$entityId]; |
37 | 37 | |
38 | - if ( !array_key_exists( 'claims', $entityContainer ) ) { |
|
38 | + if (!array_key_exists('claims', $entityContainer)) { |
|
39 | 39 | $entityContainer['claims'] = []; |
40 | 40 | } |
41 | 41 | $claimsArray = &$entityContainer['claims']; |
@@ -49,25 +49,25 @@ discard block |
||
49 | 49 | * @param array[] &$container |
50 | 50 | * @return array |
51 | 51 | */ |
52 | - protected function &getStatementArray( array &$container ) { |
|
52 | + protected function &getStatementArray(array &$container) { |
|
53 | 53 | $statementPropertyId = $this->getStatementPropertyId(); |
54 | 54 | $statementGuid = $this->getStatementGuid(); |
55 | 55 | |
56 | - $claimsContainer = &$this->getClaimsArray( $container ); |
|
56 | + $claimsContainer = &$this->getClaimsArray($container); |
|
57 | 57 | |
58 | - if ( !array_key_exists( $statementPropertyId, $claimsContainer ) ) { |
|
58 | + if (!array_key_exists($statementPropertyId, $claimsContainer)) { |
|
59 | 59 | $claimsContainer[$statementPropertyId] = []; |
60 | 60 | } |
61 | 61 | $propertyContainer = &$claimsContainer[$statementPropertyId]; |
62 | 62 | |
63 | - foreach ( $propertyContainer as &$statement ) { |
|
64 | - if ( $statement['id'] === $statementGuid ) { |
|
63 | + foreach ($propertyContainer as &$statement) { |
|
64 | + if ($statement['id'] === $statementGuid) { |
|
65 | 65 | $statementArray = &$statement; |
66 | 66 | break; |
67 | 67 | } |
68 | 68 | } |
69 | - if ( !isset( $statementArray ) ) { |
|
70 | - $statementArray = [ 'id' => $statementGuid ]; |
|
69 | + if (!isset($statementArray)) { |
|
70 | + $statementArray = ['id' => $statementGuid]; |
|
71 | 71 | $propertyContainer[] = &$statementArray; |
72 | 72 | } |
73 | 73 | |
@@ -82,19 +82,19 @@ discard block |
||
82 | 82 | * @param array[] &$container |
83 | 83 | * @return array |
84 | 84 | */ |
85 | - abstract protected function &getMainArray( array &$container ); |
|
85 | + abstract protected function &getMainArray(array &$container); |
|
86 | 86 | |
87 | 87 | /** |
88 | 88 | * @param array|null $result |
89 | 89 | * @param array[] &$container |
90 | 90 | */ |
91 | - public function storeCheckResultInArray( array $result = null, array &$container ) { |
|
92 | - $mainArray = &$this->getMainArray( $container ); |
|
93 | - if ( !array_key_exists( 'results', $mainArray ) ) { |
|
91 | + public function storeCheckResultInArray(array $result = null, array &$container) { |
|
92 | + $mainArray = &$this->getMainArray($container); |
|
93 | + if (!array_key_exists('results', $mainArray)) { |
|
94 | 94 | $mainArray['results'] = []; |
95 | 95 | } |
96 | 96 | |
97 | - if ( $result !== null ) { |
|
97 | + if ($result !== null) { |
|
98 | 98 | $mainArray['results'][] = $result; |
99 | 99 | } |
100 | 100 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @codeCoverageIgnore This method is not supported. |
34 | 34 | */ |
35 | 35 | public function getType() { |
36 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
36 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | public function getEntityId() { |
@@ -44,35 +44,35 @@ discard block |
||
44 | 44 | * @codeCoverageIgnore This method is not supported. |
45 | 45 | */ |
46 | 46 | public function getStatementPropertyId() { |
47 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
47 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * @codeCoverageIgnore This method is not supported. |
52 | 52 | */ |
53 | 53 | public function getStatementGuid() { |
54 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
54 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @codeCoverageIgnore This method is not supported. |
59 | 59 | */ |
60 | 60 | public function getSnakPropertyId() { |
61 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
61 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @codeCoverageIgnore This method is not supported. |
66 | 66 | */ |
67 | 67 | public function getSnakHash() { |
68 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
68 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
72 | 72 | * @codeCoverageIgnore This method is not supported. |
73 | 73 | */ |
74 | - public function &getMainArray( array &$container ) { |
|
75 | - throw new LogicException( 'EntityContextCursor cannot store check results' ); |
|
74 | + public function &getMainArray(array &$container) { |
|
75 | + throw new LogicException('EntityContextCursor cannot store check results'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | * @param array|null $result must be null |
82 | 82 | * @param array[] &$container |
83 | 83 | */ |
84 | - public function storeCheckResultInArray( array $result = null, array &$container ) { |
|
85 | - if ( $result !== null ) { |
|
86 | - throw new LogicException( 'EntityContextCursor cannot store check results' ); |
|
84 | + public function storeCheckResultInArray(array $result = null, array &$container) { |
|
85 | + if ($result !== null) { |
|
86 | + throw new LogicException('EntityContextCursor cannot store check results'); |
|
87 | 87 | } |
88 | 88 | |
89 | - $this->getClaimsArray( $container ); |
|
89 | + $this->getClaimsArray($container); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | } |
@@ -144,21 +144,21 @@ discard block |
||
144 | 144 | callable $defaultResultsPerEntity = null |
145 | 145 | ) { |
146 | 146 | $checkResults = []; |
147 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
147 | + $entity = $this->entityLookup->getEntity($entityId); |
|
148 | 148 | |
149 | - if ( $entity instanceof StatementListProvider ) { |
|
149 | + if ($entity instanceof StatementListProvider) { |
|
150 | 150 | $checkResults = $this->checkEveryStatement( |
151 | - $this->entityLookup->getEntity( $entityId ), |
|
151 | + $this->entityLookup->getEntity($entityId), |
|
152 | 152 | $constraintIds, |
153 | 153 | $defaultResultsPerContext |
154 | 154 | ); |
155 | 155 | } |
156 | 156 | |
157 | - if ( $defaultResultsPerEntity !== null ) { |
|
158 | - $checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults ); |
|
157 | + if ($defaultResultsPerEntity !== null) { |
|
158 | + $checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults); |
|
159 | 159 | } |
160 | 160 | |
161 | - return $this->sortResult( $checkResults ); |
|
161 | + return $this->sortResult($checkResults); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -180,19 +180,19 @@ discard block |
||
180 | 180 | callable $defaultResults = null |
181 | 181 | ) { |
182 | 182 | |
183 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
183 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
184 | 184 | $entityId = $parsedGuid->getEntityId(); |
185 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
186 | - if ( $entity instanceof StatementListProvider ) { |
|
187 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
188 | - if ( $statement ) { |
|
185 | + $entity = $this->entityLookup->getEntity($entityId); |
|
186 | + if ($entity instanceof StatementListProvider) { |
|
187 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
188 | + if ($statement) { |
|
189 | 189 | $result = $this->checkStatement( |
190 | 190 | $entity, |
191 | 191 | $statement, |
192 | 192 | $constraintIds, |
193 | 193 | $defaultResults |
194 | 194 | ); |
195 | - $output = $this->sortResult( $result ); |
|
195 | + $output = $this->sortResult($result); |
|
196 | 196 | return $output; |
197 | 197 | } |
198 | 198 | } |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | return []; |
201 | 201 | } |
202 | 202 | |
203 | - private function getAllowedContextTypes( Constraint $constraint ) { |
|
204 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
203 | + private function getAllowedContextTypes(Constraint $constraint) { |
|
204 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
205 | 205 | return [ |
206 | 206 | Context::TYPE_STATEMENT, |
207 | 207 | Context::TYPE_QUALIFIER, |
@@ -209,12 +209,12 @@ discard block |
||
209 | 209 | ]; |
210 | 210 | } |
211 | 211 | |
212 | - return array_keys( array_filter( |
|
212 | + return array_keys(array_filter( |
|
213 | 213 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
214 | - function ( $resultStatus ) { |
|
214 | + function($resultStatus) { |
|
215 | 215 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
216 | 216 | } |
217 | - ) ); |
|
217 | + )); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -225,32 +225,32 @@ discard block |
||
225 | 225 | * |
226 | 226 | * @return ConstraintParameterException[] |
227 | 227 | */ |
228 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
228 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
229 | 229 | $constraintParameters = $constraint->getConstraintParameters(); |
230 | 230 | try { |
231 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
232 | - } catch ( ConstraintParameterException $e ) { |
|
233 | - return [ $e ]; |
|
231 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
232 | + } catch (ConstraintParameterException $e) { |
|
233 | + return [$e]; |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | $problems = []; |
237 | 237 | try { |
238 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
239 | - } catch ( ConstraintParameterException $e ) { |
|
238 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
239 | + } catch (ConstraintParameterException $e) { |
|
240 | 240 | $problems[] = $e; |
241 | 241 | } |
242 | 242 | try { |
243 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
244 | - } catch ( ConstraintParameterException $e ) { |
|
243 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
244 | + } catch (ConstraintParameterException $e) { |
|
245 | 245 | $problems[] = $e; |
246 | 246 | } |
247 | 247 | try { |
248 | 248 | $this->constraintParameterParser->parseConstraintScopeParameter( |
249 | 249 | $constraintParameters, |
250 | 250 | $constraint->getConstraintTypeItemId(), |
251 | - $this->getAllowedContextTypes( $constraint ) |
|
251 | + $this->getAllowedContextTypes($constraint) |
|
252 | 252 | ); |
253 | - } catch ( ConstraintParameterException $e ) { |
|
253 | + } catch (ConstraintParameterException $e) { |
|
254 | 254 | $problems[] = $e; |
255 | 255 | } |
256 | 256 | return $problems; |
@@ -263,16 +263,16 @@ discard block |
||
263 | 263 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
264 | 264 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
265 | 265 | */ |
266 | - public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) { |
|
267 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
266 | + public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) { |
|
267 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
268 | 268 | $result = []; |
269 | 269 | |
270 | - foreach ( $constraints as $constraint ) { |
|
271 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
270 | + foreach ($constraints as $constraint) { |
|
271 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
272 | 272 | |
273 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
273 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
274 | 274 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
275 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
275 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | $result[$constraint->getConstraintId()] = $problems; |
@@ -289,17 +289,17 @@ discard block |
||
289 | 289 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
290 | 290 | * (empty means all parameters okay), or null if constraint is not found |
291 | 291 | */ |
292 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
293 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
294 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
292 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
293 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
294 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
295 | 295 | |
296 | - foreach ( $constraints as $constraint ) { |
|
297 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
298 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
296 | + foreach ($constraints as $constraint) { |
|
297 | + if ($constraint->getConstraintId() === $constraintId) { |
|
298 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
299 | 299 | |
300 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
300 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
301 | 301 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
302 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
302 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | return $problems; |
@@ -324,14 +324,14 @@ discard block |
||
324 | 324 | $result = []; |
325 | 325 | |
326 | 326 | /** @var Statement $statement */ |
327 | - foreach ( $entity->getStatements() as $statement ) { |
|
328 | - $result = array_merge( $result, |
|
327 | + foreach ($entity->getStatements() as $statement) { |
|
328 | + $result = array_merge($result, |
|
329 | 329 | $this->checkStatement( |
330 | 330 | $entity, |
331 | 331 | $statement, |
332 | 332 | $constraintIds, |
333 | 333 | $defaultResultsPerContext |
334 | - ) ); |
|
334 | + )); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | return $result; |
@@ -353,32 +353,32 @@ discard block |
||
353 | 353 | ) { |
354 | 354 | $result = []; |
355 | 355 | |
356 | - $result = array_merge( $result, |
|
356 | + $result = array_merge($result, |
|
357 | 357 | $this->checkConstraintsForMainSnak( |
358 | 358 | $entity, |
359 | 359 | $statement, |
360 | 360 | $constraintIds, |
361 | 361 | $defaultResultsPerContext |
362 | - ) ); |
|
362 | + )); |
|
363 | 363 | |
364 | - if ( $this->checkQualifiers ) { |
|
365 | - $result = array_merge( $result, |
|
364 | + if ($this->checkQualifiers) { |
|
365 | + $result = array_merge($result, |
|
366 | 366 | $this->checkConstraintsForQualifiers( |
367 | 367 | $entity, |
368 | 368 | $statement, |
369 | 369 | $constraintIds, |
370 | 370 | $defaultResultsPerContext |
371 | - ) ); |
|
371 | + )); |
|
372 | 372 | } |
373 | 373 | |
374 | - if ( $this->checkReferences ) { |
|
375 | - $result = array_merge( $result, |
|
374 | + if ($this->checkReferences) { |
|
375 | + $result = array_merge($result, |
|
376 | 376 | $this->checkConstraintsForReferences( |
377 | 377 | $entity, |
378 | 378 | $statement, |
379 | 379 | $constraintIds, |
380 | 380 | $defaultResultsPerContext |
381 | - ) ); |
|
381 | + )); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | return $result; |
@@ -393,12 +393,12 @@ discard block |
||
393 | 393 | * @param string[]|null $constraintIds |
394 | 394 | * @return Constraint[] |
395 | 395 | */ |
396 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
397 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
398 | - if ( $constraintIds !== null ) { |
|
396 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
397 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
398 | + if ($constraintIds !== null) { |
|
399 | 399 | $constraintsToUse = []; |
400 | - foreach ( $constraints as $constraint ) { |
|
401 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
400 | + foreach ($constraints as $constraint) { |
|
401 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
402 | 402 | $constraintsToUse[] = $constraint; |
403 | 403 | } |
404 | 404 | } |
@@ -422,29 +422,29 @@ discard block |
||
422 | 422 | array $constraintIds = null, |
423 | 423 | callable $defaultResults = null |
424 | 424 | ) { |
425 | - $context = new MainSnakContext( $entity, $statement ); |
|
425 | + $context = new MainSnakContext($entity, $statement); |
|
426 | 426 | $constraints = $this->getConstraintsToUse( |
427 | 427 | $statement->getPropertyId(), |
428 | 428 | $constraintIds |
429 | 429 | ); |
430 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
430 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
431 | 431 | |
432 | - foreach ( $constraints as $constraint ) { |
|
432 | + foreach ($constraints as $constraint) { |
|
433 | 433 | $parameters = $constraint->getConstraintParameters(); |
434 | 434 | try { |
435 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
436 | - } catch ( ConstraintParameterException $e ) { |
|
437 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
435 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
436 | + } catch (ConstraintParameterException $e) { |
|
437 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
438 | 438 | continue; |
439 | 439 | } |
440 | 440 | |
441 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
442 | - $message = new ViolationMessage( 'wbqc-violation-message-exception' ); |
|
443 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
441 | + if (in_array($entity->getId(), $exceptions)) { |
|
442 | + $message = new ViolationMessage('wbqc-violation-message-exception'); |
|
443 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
444 | 444 | continue; |
445 | 445 | } |
446 | 446 | |
447 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
447 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | return $result; |
@@ -466,24 +466,24 @@ discard block |
||
466 | 466 | ) { |
467 | 467 | $result = []; |
468 | 468 | |
469 | - if ( in_array( |
|
469 | + if (in_array( |
|
470 | 470 | $statement->getPropertyId()->getSerialization(), |
471 | 471 | $this->propertiesWithViolatingQualifiers |
472 | - ) ) { |
|
472 | + )) { |
|
473 | 473 | return $result; |
474 | 474 | } |
475 | 475 | |
476 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
477 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
478 | - if ( $defaultResultsPerContext !== null ) { |
|
479 | - $result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) ); |
|
476 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
477 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
478 | + if ($defaultResultsPerContext !== null) { |
|
479 | + $result = array_merge($result, $defaultResultsPerContext($qualifierContext)); |
|
480 | 480 | } |
481 | 481 | $qualifierConstraints = $this->getConstraintsToUse( |
482 | 482 | $qualifierContext->getSnak()->getPropertyId(), |
483 | 483 | $constraintIds |
484 | 484 | ); |
485 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
486 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
485 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
486 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
487 | 487 | } |
488 | 488 | } |
489 | 489 | |
@@ -507,19 +507,19 @@ discard block |
||
507 | 507 | $result = []; |
508 | 508 | |
509 | 509 | /** @var Reference $reference */ |
510 | - foreach ( $statement->getReferences() as $reference ) { |
|
511 | - foreach ( $reference->getSnaks() as $snak ) { |
|
510 | + foreach ($statement->getReferences() as $reference) { |
|
511 | + foreach ($reference->getSnaks() as $snak) { |
|
512 | 512 | $referenceContext = new ReferenceContext( |
513 | 513 | $entity, $statement, $reference, $snak |
514 | 514 | ); |
515 | - if ( $defaultResultsPerContext !== null ) { |
|
516 | - $result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) ); |
|
515 | + if ($defaultResultsPerContext !== null) { |
|
516 | + $result = array_merge($result, $defaultResultsPerContext($referenceContext)); |
|
517 | 517 | } |
518 | 518 | $referenceConstraints = $this->getConstraintsToUse( |
519 | 519 | $referenceContext->getSnak()->getPropertyId(), |
520 | 520 | $constraintIds |
521 | 521 | ); |
522 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
522 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
523 | 523 | $result[] = $this->getCheckResultFor( |
524 | 524 | $referenceContext, |
525 | 525 | $referenceConstraint |
@@ -538,65 +538,65 @@ discard block |
||
538 | 538 | * @throws InvalidArgumentException |
539 | 539 | * @return CheckResult |
540 | 540 | */ |
541 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
542 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
541 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
542 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
543 | 543 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
544 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
544 | + $result = $this->handleScope($checker, $context, $constraint); |
|
545 | 545 | |
546 | - if ( $result !== null ) { |
|
547 | - $this->addMetadata( $context, $result ); |
|
546 | + if ($result !== null) { |
|
547 | + $this->addMetadata($context, $result); |
|
548 | 548 | return $result; |
549 | 549 | } |
550 | 550 | |
551 | - $startTime = microtime( true ); |
|
551 | + $startTime = microtime(true); |
|
552 | 552 | try { |
553 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
554 | - } catch ( ConstraintParameterException $e ) { |
|
555 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
556 | - } catch ( SparqlHelperException $e ) { |
|
557 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
558 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
553 | + $result = $checker->checkConstraint($context, $constraint); |
|
554 | + } catch (ConstraintParameterException $e) { |
|
555 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
556 | + } catch (SparqlHelperException $e) { |
|
557 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
558 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
559 | 559 | } |
560 | - $endTime = microtime( true ); |
|
560 | + $endTime = microtime(true); |
|
561 | 561 | |
562 | - $this->addMetadata( $context, $result ); |
|
562 | + $this->addMetadata($context, $result); |
|
563 | 563 | |
564 | 564 | try { |
565 | 565 | $constraintStatus = $this->constraintParameterParser |
566 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
567 | - } catch ( ConstraintParameterException $e ) { |
|
568 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
566 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
567 | + } catch (ConstraintParameterException $e) { |
|
568 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
569 | 569 | $constraintStatus = null; |
570 | 570 | } |
571 | - if ( $constraintStatus === null ) { |
|
571 | + if ($constraintStatus === null) { |
|
572 | 572 | // downgrade violation to warning |
573 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
574 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
573 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
574 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
575 | 575 | } |
576 | 576 | } else { |
577 | - if ( $constraintStatus !== 'mandatory' ) { |
|
577 | + if ($constraintStatus !== 'mandatory') { |
|
578 | 578 | // @codeCoverageIgnoreStart |
579 | 579 | throw new LogicException( |
580 | - "Unknown constraint status '$constraintStatus', " . |
|
580 | + "Unknown constraint status '$constraintStatus', ". |
|
581 | 581 | "only known status is 'mandatory'" |
582 | 582 | ); |
583 | 583 | // @codeCoverageIgnoreEnd |
584 | 584 | } |
585 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
585 | + $result->addParameter('constraint_status', $constraintStatus); |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | $this->loggingHelper->logConstraintCheck( |
589 | 589 | $context, |
590 | 590 | $constraint, |
591 | 591 | $result, |
592 | - get_class( $checker ), |
|
592 | + get_class($checker), |
|
593 | 593 | $endTime - $startTime, |
594 | 594 | __METHOD__ |
595 | 595 | ); |
596 | 596 | |
597 | 597 | return $result; |
598 | 598 | } else { |
599 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
599 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
600 | 600 | } |
601 | 601 | } |
602 | 602 | |
@@ -610,29 +610,29 @@ discard block |
||
610 | 610 | $constraint->getConstraintParameters(), |
611 | 611 | $constraint->getConstraintTypeItemId() |
612 | 612 | ); |
613 | - } catch ( ConstraintParameterException $e ) { |
|
614 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
613 | + } catch (ConstraintParameterException $e) { |
|
614 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
615 | 615 | } |
616 | - if ( $checkedContextTypes === null ) { |
|
616 | + if ($checkedContextTypes === null) { |
|
617 | 617 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
618 | 618 | } |
619 | - if ( !in_array( $context->getType(), $checkedContextTypes ) ) { |
|
620 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
619 | + if (!in_array($context->getType(), $checkedContextTypes)) { |
|
620 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
621 | 621 | } |
622 | - if ( $checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO ) { |
|
623 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
622 | + if ($checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO) { |
|
623 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
624 | 624 | } |
625 | 625 | return null; |
626 | 626 | } |
627 | 627 | |
628 | - private function addMetadata( Context $context, CheckResult $result ) { |
|
629 | - $result->withMetadata( Metadata::merge( [ |
|
628 | + private function addMetadata(Context $context, CheckResult $result) { |
|
629 | + $result->withMetadata(Metadata::merge([ |
|
630 | 630 | $result->getMetadata(), |
631 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
632 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
633 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
634 | - ] ) ), |
|
635 | - ] ) ); |
|
631 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
632 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
633 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
634 | + ])), |
|
635 | + ])); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | /** |
@@ -640,12 +640,12 @@ discard block |
||
640 | 640 | * |
641 | 641 | * @return CheckResult[] |
642 | 642 | */ |
643 | - private function sortResult( array $result ) { |
|
644 | - if ( count( $result ) < 2 ) { |
|
643 | + private function sortResult(array $result) { |
|
644 | + if (count($result) < 2) { |
|
645 | 645 | return $result; |
646 | 646 | } |
647 | 647 | |
648 | - $sortFunction = function ( CheckResult $a, CheckResult $b ) { |
|
648 | + $sortFunction = function(CheckResult $a, CheckResult $b) { |
|
649 | 649 | $orderNum = 0; |
650 | 650 | $order = [ |
651 | 651 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -661,55 +661,55 @@ discard block |
||
661 | 661 | $statusA = $a->getStatus(); |
662 | 662 | $statusB = $b->getStatus(); |
663 | 663 | |
664 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
665 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
664 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
665 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
666 | 666 | |
667 | - if ( $orderA === $orderB ) { |
|
667 | + if ($orderA === $orderB) { |
|
668 | 668 | $cursorA = $a->getContextCursor(); |
669 | 669 | $cursorB = $b->getContextCursor(); |
670 | 670 | |
671 | - if ( $cursorA instanceof EntityContextCursor ) { |
|
671 | + if ($cursorA instanceof EntityContextCursor) { |
|
672 | 672 | return $cursorB instanceof EntityContextCursor ? 0 : -1; |
673 | 673 | } |
674 | - if ( $cursorB instanceof EntityContextCursor ) { |
|
674 | + if ($cursorB instanceof EntityContextCursor) { |
|
675 | 675 | return $cursorA instanceof EntityContextCursor ? 0 : 1; |
676 | 676 | } |
677 | 677 | |
678 | 678 | $pidA = $cursorA->getSnakPropertyId(); |
679 | 679 | $pidB = $cursorB->getSnakPropertyId(); |
680 | 680 | |
681 | - if ( $pidA === $pidB ) { |
|
681 | + if ($pidA === $pidB) { |
|
682 | 682 | $hashA = $cursorA->getSnakHash(); |
683 | 683 | $hashB = $cursorB->getSnakHash(); |
684 | 684 | |
685 | - if ( $hashA === $hashB ) { |
|
686 | - if ( $a instanceof NullResult ) { |
|
685 | + if ($hashA === $hashB) { |
|
686 | + if ($a instanceof NullResult) { |
|
687 | 687 | return $b instanceof NullResult ? 0 : -1; |
688 | 688 | } |
689 | - if ( $b instanceof NullResult ) { |
|
689 | + if ($b instanceof NullResult) { |
|
690 | 690 | return $a instanceof NullResult ? 0 : 1; |
691 | 691 | } |
692 | 692 | |
693 | 693 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
694 | 694 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
695 | 695 | |
696 | - if ( $typeA == $typeB ) { |
|
696 | + if ($typeA == $typeB) { |
|
697 | 697 | return 0; |
698 | 698 | } else { |
699 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
699 | + return ($typeA > $typeB) ? 1 : -1; |
|
700 | 700 | } |
701 | 701 | } else { |
702 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
702 | + return ($hashA > $hashB) ? 1 : -1; |
|
703 | 703 | } |
704 | 704 | } else { |
705 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
705 | + return ($pidA > $pidB) ? 1 : -1; |
|
706 | 706 | } |
707 | 707 | } else { |
708 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
708 | + return ($orderA > $orderB) ? 1 : -1; |
|
709 | 709 | } |
710 | 710 | }; |
711 | 711 | |
712 | - uasort( $result, $sortFunction ); |
|
712 | + uasort($result, $sortFunction); |
|
713 | 713 | |
714 | 714 | return $result; |
715 | 715 | } |
@@ -43,52 +43,51 @@ |
||
43 | 43 | ) { |
44 | 44 | $results = []; |
45 | 45 | $metadatas = []; |
46 | - $statusesFlipped = array_flip( $statuses ); |
|
47 | - foreach ( $entityIds as $entityId ) { |
|
46 | + $statusesFlipped = array_flip($statuses); |
|
47 | + foreach ($entityIds as $entityId) { |
|
48 | 48 | $entityResults = $this->delegatingConstraintChecker->checkAgainstConstraintsOnEntityId( |
49 | 49 | $entityId, |
50 | 50 | $constraintIds, |
51 | - [ $this, 'defaultResultsPerContext' ], |
|
52 | - [ $this, 'defaultResultsPerEntity' ] |
|
51 | + [$this, 'defaultResultsPerContext'], |
|
52 | + [$this, 'defaultResultsPerEntity'] |
|
53 | 53 | ); |
54 | - foreach ( $entityResults as $result ) { |
|
54 | + foreach ($entityResults as $result) { |
|
55 | 55 | $metadatas[] = $result->getMetadata(); |
56 | - if ( $this->statusSelected( $statusesFlipped, $result ) ) { |
|
56 | + if ($this->statusSelected($statusesFlipped, $result)) { |
|
57 | 57 | $results[] = $result; |
58 | 58 | } |
59 | 59 | } |
60 | 60 | } |
61 | - foreach ( $claimIds as $claimId ) { |
|
61 | + foreach ($claimIds as $claimId) { |
|
62 | 62 | $claimResults = $this->delegatingConstraintChecker->checkAgainstConstraintsOnClaimId( |
63 | 63 | $claimId, |
64 | 64 | $constraintIds, |
65 | - [ $this, 'defaultResultsPerContext' ] |
|
65 | + [$this, 'defaultResultsPerContext'] |
|
66 | 66 | ); |
67 | - foreach ( $claimResults as $result ) { |
|
67 | + foreach ($claimResults as $result) { |
|
68 | 68 | $metadatas[] = $result->getMetadata(); |
69 | - if ( $this->statusSelected( $statusesFlipped, $result ) ) { |
|
69 | + if ($this->statusSelected($statusesFlipped, $result)) { |
|
70 | 70 | $results[] = $result; |
71 | 71 | } |
72 | 72 | } |
73 | 73 | } |
74 | 74 | return new CachedCheckResults( |
75 | 75 | $results, |
76 | - Metadata::merge( $metadatas ) |
|
76 | + Metadata::merge($metadatas) |
|
77 | 77 | ); |
78 | 78 | } |
79 | 79 | |
80 | - public function defaultResultsPerContext( Context $context ) { |
|
80 | + public function defaultResultsPerContext(Context $context) { |
|
81 | 81 | return $context->getType() === Context::TYPE_STATEMENT ? |
82 | - [ new NullResult( $context->getCursor() ) ] : |
|
83 | - []; |
|
82 | + [new NullResult($context->getCursor())] : []; |
|
84 | 83 | } |
85 | 84 | |
86 | - public function defaultResultsPerEntity( EntityId $entityId ) { |
|
87 | - return [ new NullResult( new EntityContextCursor( $entityId->getSerialization() ) ) ]; |
|
85 | + public function defaultResultsPerEntity(EntityId $entityId) { |
|
86 | + return [new NullResult(new EntityContextCursor($entityId->getSerialization()))]; |
|
88 | 87 | } |
89 | 88 | |
90 | - public function statusSelected( array $statusesFlipped, CheckResult $result ) { |
|
91 | - return array_key_exists( $result->getStatus(), $statusesFlipped ) || |
|
89 | + public function statusSelected(array $statusesFlipped, CheckResult $result) { |
|
90 | + return array_key_exists($result->getStatus(), $statusesFlipped) || |
|
92 | 91 | $result instanceof NullResult; |
93 | 92 | } |
94 | 93 |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | * @param CachedCheckResults $checkResults |
60 | 60 | * @return CachedCheckConstraintsResponse |
61 | 61 | */ |
62 | - public function render( CachedCheckResults $checkResults ) { |
|
62 | + public function render(CachedCheckResults $checkResults) { |
|
63 | 63 | $response = []; |
64 | - foreach ( $checkResults->getArray() as $checkResult ) { |
|
65 | - $resultArray = $this->checkResultToArray( $checkResult ); |
|
66 | - $checkResult->getContextCursor()->storeCheckResultInArray( $resultArray, $response ); |
|
64 | + foreach ($checkResults->getArray() as $checkResult) { |
|
65 | + $resultArray = $this->checkResultToArray($checkResult); |
|
66 | + $checkResult->getContextCursor()->storeCheckResultInArray($resultArray, $response); |
|
67 | 67 | } |
68 | 68 | return new CachedCheckConstraintsResponse( |
69 | 69 | $response, |
@@ -71,19 +71,19 @@ discard block |
||
71 | 71 | ); |
72 | 72 | } |
73 | 73 | |
74 | - public function checkResultToArray( CheckResult $checkResult ) { |
|
75 | - if ( $checkResult instanceof NullResult ) { |
|
74 | + public function checkResultToArray(CheckResult $checkResult) { |
|
75 | + if ($checkResult instanceof NullResult) { |
|
76 | 76 | return null; |
77 | 77 | } |
78 | 78 | |
79 | 79 | $constraintId = $checkResult->getConstraint()->getConstraintId(); |
80 | 80 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
81 | - $constraintPropertyId = new PropertyId( $checkResult->getContextCursor()->getSnakPropertyId() ); |
|
81 | + $constraintPropertyId = new PropertyId($checkResult->getContextCursor()->getSnakPropertyId()); |
|
82 | 82 | |
83 | - $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
84 | - $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
83 | + $title = $this->entityTitleLookup->getTitleForId($constraintPropertyId); |
|
84 | + $typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId)); |
|
85 | 85 | // TODO link to the statement when possible (T169224) |
86 | - $link = $title->getFullURL() . '#' . $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
86 | + $link = $title->getFullURL().'#'.$this->config->get('WBQualityConstraintsPropertyConstraintId'); |
|
87 | 87 | |
88 | 88 | $constraint = [ |
89 | 89 | 'id' => $constraintId, |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | 'constraint' => $constraint |
100 | 100 | ]; |
101 | 101 | $message = $checkResult->getMessage(); |
102 | - if ( $message ) { |
|
103 | - $result['message-html'] = $this->violationMessageRenderer->render( $message ); |
|
102 | + if ($message) { |
|
103 | + $result['message-html'] = $this->violationMessageRenderer->render($message); |
|
104 | 104 | } |
105 | - if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) { |
|
105 | + if ($checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT) { |
|
106 | 106 | $result['claim'] = $checkResult->getContextCursor()->getStatementGuid(); |
107 | 107 | } |
108 | 108 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
109 | - if ( $cachingMetadataArray !== null ) { |
|
109 | + if ($cachingMetadataArray !== null) { |
|
110 | 110 | $result['cached'] = $cachingMetadataArray; |
111 | 111 | } |
112 | 112 |
@@ -4,11 +4,11 @@ discard block |
||
4 | 4 | * @license GPL-2.0-or-later |
5 | 5 | */ |
6 | 6 | |
7 | -if ( function_exists( 'wfLoadExtension' ) ) { |
|
8 | - wfLoadExtension( 'WikibaseQualityConstraints', __DIR__ . '/extension.json' ); |
|
7 | +if (function_exists('wfLoadExtension')) { |
|
8 | + wfLoadExtension('WikibaseQualityConstraints', __DIR__.'/extension.json'); |
|
9 | 9 | // Keep i18n globals so mergeMessageFileList.php doesn't break |
10 | - $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__ . '/i18n'; |
|
11 | - $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__ . '/WikibaseQualityConstraints.alias.php'; |
|
10 | + $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__.'/i18n'; |
|
11 | + $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__.'/WikibaseQualityConstraints.alias.php'; |
|
12 | 12 | /* wfWarn( |
13 | 13 | 'Deprecated PHP entry point used for WikibaseQualityConstraints extension. ' . |
14 | 14 | 'Please use wfLoadExtension instead, ' . |
@@ -16,5 +16,5 @@ discard block |
||
16 | 16 | ); */ |
17 | 17 | return; |
18 | 18 | } else { |
19 | - die( 'This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+' ); |
|
19 | + die('This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+'); |
|
20 | 20 | } |
@@ -150,14 +150,14 @@ discard block |
||
150 | 150 | ) { |
151 | 151 | $results = []; |
152 | 152 | $metadatas = []; |
153 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
153 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
154 | 154 | $storedEntityIds = []; |
155 | - foreach ( $entityIds as $entityId ) { |
|
156 | - $storedResults = $this->getStoredResults( $entityId ); |
|
157 | - if ( $storedResults !== null ) { |
|
158 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
159 | - foreach ( $storedResults->getArray() as $checkResult ) { |
|
160 | - if ( in_array( $checkResult->getStatus(), $statuses ) ) { |
|
155 | + foreach ($entityIds as $entityId) { |
|
156 | + $storedResults = $this->getStoredResults($entityId); |
|
157 | + if ($storedResults !== null) { |
|
158 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
159 | + foreach ($storedResults->getArray() as $checkResult) { |
|
160 | + if (in_array($checkResult->getStatus(), $statuses)) { |
|
161 | 161 | $results[] = $checkResult; |
162 | 162 | } |
163 | 163 | } |
@@ -165,19 +165,19 @@ discard block |
||
165 | 165 | $storedEntityIds[] = $entityId; |
166 | 166 | } |
167 | 167 | } |
168 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
168 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
169 | 169 | } |
170 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
171 | - if ( $entityIds !== [] ) { |
|
172 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
170 | + if ($entityIds !== [] || $claimIds !== []) { |
|
171 | + if ($entityIds !== []) { |
|
172 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
173 | 173 | } |
174 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
175 | - $results = array_merge( $results, $response->getArray() ); |
|
174 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
175 | + $results = array_merge($results, $response->getArray()); |
|
176 | 176 | $metadatas[] = $response->getMetadata(); |
177 | 177 | } |
178 | 178 | return new CachedCheckResults( |
179 | 179 | $results, |
180 | - Metadata::merge( $metadatas ) |
|
180 | + Metadata::merge($metadatas) |
|
181 | 181 | ); |
182 | 182 | } |
183 | 183 | |
@@ -200,13 +200,13 @@ discard block |
||
200 | 200 | array $constraintIds = null, |
201 | 201 | array $statuses |
202 | 202 | ) { |
203 | - if ( $claimIds !== [] ) { |
|
203 | + if ($claimIds !== []) { |
|
204 | 204 | return false; |
205 | 205 | } |
206 | - if ( $constraintIds !== null ) { |
|
206 | + if ($constraintIds !== null) { |
|
207 | 207 | return false; |
208 | 208 | } |
209 | - if ( array_diff( $statuses, $this->cachedStatuses ) !== [] ) { |
|
209 | + if (array_diff($statuses, $this->cachedStatuses) !== []) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | return true; |
@@ -225,11 +225,11 @@ discard block |
||
225 | 225 | array $constraintIds = null, |
226 | 226 | array $statuses |
227 | 227 | ) { |
228 | - $results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
228 | + $results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
229 | 229 | |
230 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
231 | - foreach ( $entityIds as $entityId ) { |
|
232 | - $this->storeResults( $entityId, $results ); |
|
230 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
231 | + foreach ($entityIds as $entityId) { |
|
232 | + $this->storeResults($entityId, $results); |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | array $constraintIds = null, |
261 | 261 | array $statuses |
262 | 262 | ) { |
263 | - if ( $constraintIds !== null ) { |
|
263 | + if ($constraintIds !== null) { |
|
264 | 264 | return false; |
265 | 265 | } |
266 | - if ( array_diff( $this->cachedStatuses, $statuses ) !== [] ) { |
|
266 | + if (array_diff($this->cachedStatuses, $statuses) !== []) { |
|
267 | 267 | return false; |
268 | 268 | } |
269 | 269 | return true; |
@@ -277,23 +277,23 @@ discard block |
||
277 | 277 | * May include check results for other entity IDs as well, |
278 | 278 | * or check results with statuses that we’re not interested in caching. |
279 | 279 | */ |
280 | - private function storeResults( EntityId $entityId, CachedCheckResults $results ) { |
|
280 | + private function storeResults(EntityId $entityId, CachedCheckResults $results) { |
|
281 | 281 | $latestRevisionIds = $this->getLatestRevisionIds( |
282 | 282 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
283 | 283 | ); |
284 | - if ( $latestRevisionIds === null ) { |
|
284 | + if ($latestRevisionIds === null) { |
|
285 | 285 | return; |
286 | 286 | } |
287 | 287 | |
288 | 288 | $resultSerializations = []; |
289 | - foreach ( $results->getArray() as $checkResult ) { |
|
290 | - if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) { |
|
289 | + foreach ($results->getArray() as $checkResult) { |
|
290 | + if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) { |
|
291 | 291 | continue; |
292 | 292 | } |
293 | - if ( !in_array( $checkResult->getStatus(), $this->cachedStatuses ) ) { |
|
293 | + if (!in_array($checkResult->getStatus(), $this->cachedStatuses)) { |
|
294 | 294 | continue; |
295 | 295 | } |
296 | - $resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult ); |
|
296 | + $resultSerializations[] = $this->checkResultSerializer->serialize($checkResult); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | $value = [ |
@@ -301,11 +301,11 @@ discard block |
||
301 | 301 | 'latestRevisionIds' => $latestRevisionIds, |
302 | 302 | ]; |
303 | 303 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
304 | - if ( $futureTime !== null ) { |
|
304 | + if ($futureTime !== null) { |
|
305 | 305 | $value['futureTime'] = $futureTime->getArrayValue(); |
306 | 306 | } |
307 | 307 | |
308 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
308 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -315,30 +315,29 @@ discard block |
||
315 | 315 | public function getStoredResults( |
316 | 316 | EntityId $entityId |
317 | 317 | ) { |
318 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
319 | - $now = call_user_func( $this->microtime, true ); |
|
318 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
319 | + $now = call_user_func($this->microtime, true); |
|
320 | 320 | |
321 | - $dependencyMetadata = $this->checkDependencyMetadata( $value ); |
|
322 | - if ( $dependencyMetadata === null ) { |
|
321 | + $dependencyMetadata = $this->checkDependencyMetadata($value); |
|
322 | + if ($dependencyMetadata === null) { |
|
323 | 323 | return null; |
324 | 324 | } |
325 | 325 | |
326 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
326 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
327 | 327 | $cachingMetadata = $ageInSeconds > 0 ? |
328 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
329 | - CachingMetadata::fresh(); |
|
328 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
330 | 329 | |
331 | 330 | $results = []; |
332 | - foreach ( $value['results'] as $resultSerialization ) { |
|
333 | - $results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata ); |
|
331 | + foreach ($value['results'] as $resultSerialization) { |
|
332 | + $results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata); |
|
334 | 333 | } |
335 | 334 | |
336 | 335 | return new CachedCheckResults( |
337 | 336 | $results, |
338 | - Metadata::merge( [ |
|
339 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
340 | - Metadata::ofDependencyMetadata( $dependencyMetadata ), |
|
341 | - ] ) |
|
337 | + Metadata::merge([ |
|
338 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
339 | + Metadata::ofDependencyMetadata($dependencyMetadata), |
|
340 | + ]) |
|
342 | 341 | ); |
343 | 342 | } |
344 | 343 | |
@@ -350,37 +349,37 @@ discard block |
||
350 | 349 | * @return DependencyMetadata|null the dependency metadata, |
351 | 350 | * or null if $value should no longer be used |
352 | 351 | */ |
353 | - private function checkDependencyMetadata( $value ) { |
|
354 | - if ( $value === false ) { |
|
352 | + private function checkDependencyMetadata($value) { |
|
353 | + if ($value === false) { |
|
355 | 354 | return null; |
356 | 355 | } |
357 | 356 | |
358 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
359 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
360 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
357 | + if (array_key_exists('futureTime', $value)) { |
|
358 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
359 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
361 | 360 | return null; |
362 | 361 | } |
363 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
362 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
364 | 363 | } else { |
365 | 364 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
366 | 365 | } |
367 | 366 | |
368 | 367 | $dependedEntityIds = array_map( |
369 | - [ $this->entityIdParser, "parse" ], |
|
370 | - array_keys( $value['latestRevisionIds'] ) |
|
368 | + [$this->entityIdParser, "parse"], |
|
369 | + array_keys($value['latestRevisionIds']) |
|
371 | 370 | ); |
372 | 371 | |
373 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
372 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
374 | 373 | return null; |
375 | 374 | } |
376 | 375 | |
377 | 376 | return array_reduce( |
378 | 377 | $dependedEntityIds, |
379 | - function( DependencyMetadata $metadata, EntityId $entityId ) { |
|
380 | - return DependencyMetadata::merge( [ |
|
378 | + function(DependencyMetadata $metadata, EntityId $entityId) { |
|
379 | + return DependencyMetadata::merge([ |
|
381 | 380 | $metadata, |
382 | - DependencyMetadata::ofEntityId( $entityId ) |
|
383 | - ] ); |
|
381 | + DependencyMetadata::ofEntityId($entityId) |
|
382 | + ]); |
|
384 | 383 | }, |
385 | 384 | $futureTimeDependencyMetadata |
386 | 385 | ); |
@@ -400,13 +399,13 @@ discard block |
||
400 | 399 | array $resultSerialization, |
401 | 400 | CachingMetadata $cachingMetadata |
402 | 401 | ) { |
403 | - $result = $this->checkResultDeserializer->deserialize( $resultSerialization ); |
|
404 | - if ( $this->isPossiblyStaleResult( $result ) ) { |
|
402 | + $result = $this->checkResultDeserializer->deserialize($resultSerialization); |
|
403 | + if ($this->isPossiblyStaleResult($result)) { |
|
405 | 404 | $result->withMetadata( |
406 | - Metadata::merge( [ |
|
405 | + Metadata::merge([ |
|
407 | 406 | $result->getMetadata(), |
408 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
409 | - ] ) |
|
407 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
408 | + ]) |
|
410 | 409 | ); |
411 | 410 | } |
412 | 411 | return $result; |
@@ -416,7 +415,7 @@ discard block |
||
416 | 415 | * @param CheckResult $result |
417 | 416 | * @return bool |
418 | 417 | */ |
419 | - private function isPossiblyStaleResult( CheckResult $result ) { |
|
418 | + private function isPossiblyStaleResult(CheckResult $result) { |
|
420 | 419 | return in_array( |
421 | 420 | $result->getConstraint()->getConstraintTypeItemId(), |
422 | 421 | $this->possiblyStaleConstraintTypes |
@@ -428,14 +427,14 @@ discard block |
||
428 | 427 | * @return int[]|null array from entity ID serializations to revision ID, |
429 | 428 | * or null to indicate that not all revision IDs could be loaded |
430 | 429 | */ |
431 | - private function getLatestRevisionIds( array $entityIds ) { |
|
432 | - if ( $entityIds === [] ) { |
|
430 | + private function getLatestRevisionIds(array $entityIds) { |
|
431 | + if ($entityIds === []) { |
|
433 | 432 | $this->loggingHelper->logEmptyDependencyMetadata(); |
434 | 433 | return []; |
435 | 434 | } |
436 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
435 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
437 | 436 | // one of those entities will probably be edited soon, so might as well skip caching |
438 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
437 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
439 | 438 | return null; |
440 | 439 | } |
441 | 440 | |
@@ -443,7 +442,7 @@ discard block |
||
443 | 442 | $entityIds, |
444 | 443 | EntityRevisionLookup::LATEST_FROM_REPLICA |
445 | 444 | ); |
446 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
445 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
447 | 446 | return null; |
448 | 447 | } |
449 | 448 | return $latestRevisionIds; |
@@ -453,8 +452,8 @@ discard block |
||
453 | 452 | * @param array $array |
454 | 453 | * @return bool |
455 | 454 | */ |
456 | - private function hasFalseElements( array $array ) { |
|
457 | - return in_array( false, $array, true ); |
|
455 | + private function hasFalseElements(array $array) { |
|
456 | + return in_array(false, $array, true); |
|
458 | 457 | } |
459 | 458 | |
460 | 459 | /** |
@@ -462,7 +461,7 @@ discard block |
||
462 | 461 | * |
463 | 462 | * @param callable $microtime |
464 | 463 | */ |
465 | - public function setMicrotimeFunction( callable $microtime ) { |
|
464 | + public function setMicrotimeFunction(callable $microtime) { |
|
466 | 465 | $this->microtime = $microtime; |
467 | 466 | } |
468 | 467 |
@@ -92,28 +92,28 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return self |
94 | 94 | */ |
95 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
95 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
96 | 96 | $repo = WikibaseRepo::getDefaultInstance(); |
97 | 97 | |
98 | 98 | $language = $repo->getUserLanguage(); |
99 | 99 | $formatterOptions = new FormatterOptions(); |
100 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
100 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
101 | 101 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
102 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
102 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
103 | 103 | |
104 | 104 | $languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory(); |
105 | - $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language ); |
|
105 | + $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language); |
|
106 | 106 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
107 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
107 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
108 | 108 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
109 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
109 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
110 | 110 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
111 | 111 | $titleParser = MediaWikiServices::getInstance()->getTitleParser(); |
112 | 112 | $unitConverter = $repo->getUnitConverter(); |
113 | 113 | $dataFactory = MediaWikiServices::getInstance()->getStatsdDataFactory(); |
114 | 114 | $loggingHelper = new LoggingHelper( |
115 | 115 | $dataFactory, |
116 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
116 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
117 | 117 | $config |
118 | 118 | ); |
119 | 119 | $constraintParameterRenderer = new ConstraintParameterRenderer( |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | $checkResultsRenderer = new CheckResultsRenderer( |
148 | 148 | $repo->getEntityTitleLookup(), |
149 | 149 | $entityIdLabelFormatter, |
150 | - new MultilingualTextViolationMessageRenderer( $entityIdHtmlLinkFormatter, $valueFormatter, $config ), |
|
150 | + new MultilingualTextViolationMessageRenderer($entityIdHtmlLinkFormatter, $valueFormatter, $config), |
|
151 | 151 | $config |
152 | 152 | ); |
153 | 153 | $resultsSource = new CheckingResultsSource( |
154 | 154 | $constraintReportFactory->getConstraintChecker() |
155 | 155 | ); |
156 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
156 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
157 | 157 | $wikiPageEntityMetaDataAccessor = new WikiPageEntityMetaDataLookup( |
158 | 158 | $repo->getEntityNamespaceLookup() |
159 | 159 | ); |
@@ -182,14 +182,14 @@ discard block |
||
182 | 182 | $checkResultDeserializer, |
183 | 183 | $wikiPageEntityMetaDataAccessor, |
184 | 184 | $entityIdParser, |
185 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
185 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
186 | 186 | [ |
187 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
188 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
189 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
190 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
187 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
188 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
189 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
190 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
191 | 191 | ], |
192 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
192 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
193 | 193 | $loggingHelper |
194 | 194 | ); |
195 | 195 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $prefix, |
201 | 201 | $repo->getEntityIdParser(), |
202 | 202 | $repo->getStatementGuidValidator(), |
203 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
203 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
204 | 204 | $resultsSource, |
205 | 205 | $checkResultsRenderer, |
206 | 206 | $dataFactory |
@@ -229,11 +229,11 @@ discard block |
||
229 | 229 | CheckResultsRenderer $checkResultsRenderer, |
230 | 230 | IBufferingStatsdDataFactory $dataFactory |
231 | 231 | ) { |
232 | - parent::__construct( $main, $name, $prefix ); |
|
232 | + parent::__construct($main, $name, $prefix); |
|
233 | 233 | $this->entityIdParser = $entityIdParser; |
234 | 234 | $this->statementGuidValidator = $statementGuidValidator; |
235 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
236 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
235 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
236 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
237 | 237 | $this->resultsSource = $resultsSource; |
238 | 238 | $this->checkResultsRenderer = $checkResultsRenderer; |
239 | 239 | $this->dataFactory = $dataFactory; |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | |
250 | 250 | $params = $this->extractRequestParams(); |
251 | 251 | |
252 | - $this->validateParameters( $params ); |
|
253 | - $entityIds = $this->parseEntityIds( $params ); |
|
254 | - $claimIds = $this->parseClaimIds( $params ); |
|
252 | + $this->validateParameters($params); |
|
253 | + $entityIds = $this->parseEntityIds($params); |
|
254 | + $claimIds = $this->parseClaimIds($params); |
|
255 | 255 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
256 | 256 | $statuses = $params[self::PARAM_STATUS]; |
257 | 257 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | ) |
268 | 268 | )->getArray() |
269 | 269 | ); |
270 | - $this->resultBuilder->markSuccess( 1 ); |
|
270 | + $this->resultBuilder->markSuccess(1); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -275,24 +275,24 @@ discard block |
||
275 | 275 | * |
276 | 276 | * @return EntityId[] |
277 | 277 | */ |
278 | - private function parseEntityIds( array $params ) { |
|
278 | + private function parseEntityIds(array $params) { |
|
279 | 279 | $ids = $params[self::PARAM_ID]; |
280 | 280 | |
281 | - if ( $ids === null ) { |
|
281 | + if ($ids === null) { |
|
282 | 282 | return []; |
283 | - } elseif ( $ids === [] ) { |
|
283 | + } elseif ($ids === []) { |
|
284 | 284 | $this->errorReporter->dieError( |
285 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
285 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
286 | 286 | } |
287 | 287 | |
288 | - return array_map( function ( $id ) { |
|
288 | + return array_map(function($id) { |
|
289 | 289 | try { |
290 | - return $this->entityIdParser->parse( $id ); |
|
291 | - } catch ( EntityIdParsingException $e ) { |
|
290 | + return $this->entityIdParser->parse($id); |
|
291 | + } catch (EntityIdParsingException $e) { |
|
292 | 292 | $this->errorReporter->dieError( |
293 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
293 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
294 | 294 | } |
295 | - }, $ids ); |
|
295 | + }, $ids); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -300,35 +300,35 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return string[] |
302 | 302 | */ |
303 | - private function parseClaimIds( array $params ) { |
|
303 | + private function parseClaimIds(array $params) { |
|
304 | 304 | $ids = $params[self::PARAM_CLAIM_ID]; |
305 | 305 | |
306 | - if ( $ids === null ) { |
|
306 | + if ($ids === null) { |
|
307 | 307 | return []; |
308 | - } elseif ( $ids === [] ) { |
|
308 | + } elseif ($ids === []) { |
|
309 | 309 | $this->errorReporter->dieError( |
310 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
310 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
311 | 311 | } |
312 | 312 | |
313 | - foreach ( $ids as $id ) { |
|
314 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
313 | + foreach ($ids as $id) { |
|
314 | + if (!$this->statementGuidValidator->validate($id)) { |
|
315 | 315 | $this->errorReporter->dieError( |
316 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
316 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
317 | 317 | } |
318 | 318 | } |
319 | 319 | |
320 | 320 | return $ids; |
321 | 321 | } |
322 | 322 | |
323 | - private function validateParameters( array $params ) { |
|
324 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
325 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
323 | + private function validateParameters(array $params) { |
|
324 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
325 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
326 | 326 | ) { |
327 | 327 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
328 | 328 | $this->errorReporter->dieError( |
329 | 329 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
330 | 330 | } |
331 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
331 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
332 | 332 | $paramId = self::PARAM_ID; |
333 | 333 | $paramClaimId = self::PARAM_CLAIM_ID; |
334 | 334 | $this->errorReporter->dieError( |
@@ -368,11 +368,11 @@ discard block |
||
368 | 368 | ], |
369 | 369 | ApiBase::PARAM_ISMULTI => true, |
370 | 370 | ApiBase::PARAM_ALL => true, |
371 | - ApiBase::PARAM_DFLT => implode( '|', [ |
|
371 | + ApiBase::PARAM_DFLT => implode('|', [ |
|
372 | 372 | CheckResult::STATUS_VIOLATION, |
373 | 373 | CheckResult::STATUS_WARNING, |
374 | 374 | CheckResult::STATUS_BAD_PARAMETERS, |
375 | - ] ), |
|
375 | + ]), |
|
376 | 376 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
377 | 377 | ], |
378 | 378 | ]; |