@@ -65,6 +65,7 @@ discard block |
||
65 | 65 | * and return it along with the associated log level. |
66 | 66 | * |
67 | 67 | * @param float $durationSeconds |
68 | + * @param double[] $limits |
|
68 | 69 | * @return array [ $limitSeconds, $logLevel ] |
69 | 70 | */ |
70 | 71 | private function findLimit( $limits, $durationSeconds ) { |
@@ -174,6 +175,7 @@ discard block |
||
174 | 175 | * @param EntityId $entityId |
175 | 176 | * @param CheckResult[] $checkResults |
176 | 177 | * @param float $durationSeconds |
178 | + * @param string $method |
|
177 | 179 | */ |
178 | 180 | public function logConstraintCheckOnEntity( |
179 | 181 | EntityId $entityId, |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | $this->dataFactory = $dataFactory; |
52 | 52 | $this->logger = $logger; |
53 | 53 | $this->constraintCheckDurationLimits = [ |
54 | - 'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ), |
|
55 | - 'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ), |
|
54 | + 'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'), |
|
55 | + 'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'), |
|
56 | 56 | ]; |
57 | 57 | $this->constraintCheckOnEntityDurationLimits = [ |
58 | - 'info' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationInfoSeconds' ), |
|
59 | - 'warning' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationWarningSeconds' ), |
|
58 | + 'info' => $config->get('WBQualityConstraintsCheckOnEntityDurationInfoSeconds'), |
|
59 | + 'warning' => $config->get('WBQualityConstraintsCheckOnEntityDurationWarningSeconds'), |
|
60 | 60 | ]; |
61 | 61 | } |
62 | 62 | |
@@ -67,23 +67,23 @@ discard block |
||
67 | 67 | * @param float $durationSeconds |
68 | 68 | * @return array [ $limitSeconds, $logLevel ] |
69 | 69 | */ |
70 | - private function findLimit( $limits, $durationSeconds ) { |
|
70 | + private function findLimit($limits, $durationSeconds) { |
|
71 | 71 | $limitSeconds = null; |
72 | 72 | $logLevel = null; |
73 | 73 | |
74 | - foreach ( $limits as $level => $limit ) { |
|
74 | + foreach ($limits as $level => $limit) { |
|
75 | 75 | if ( |
76 | 76 | // duration exceeds this limit |
77 | - isset( $limit ) && $durationSeconds > $limit && |
|
77 | + isset($limit) && $durationSeconds > $limit && |
|
78 | 78 | // this limit is longer than previous longest limit |
79 | - ( $limitSeconds === null || $limit > $limitSeconds ) |
|
79 | + ($limitSeconds === null || $limit > $limitSeconds) |
|
80 | 80 | ) { |
81 | 81 | $limitSeconds = $limit; |
82 | 82 | $logLevel = $level; |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - return [ $limitSeconds, $logLevel ]; |
|
86 | + return [$limitSeconds, $logLevel]; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -108,31 +108,31 @@ discard block |
||
108 | 108 | $durationSeconds, |
109 | 109 | $method |
110 | 110 | ) { |
111 | - $constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 ); |
|
111 | + $constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1); |
|
112 | 112 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
113 | 113 | |
114 | 114 | $this->dataFactory->timing( |
115 | - 'wikibase.quality.constraints.check.timing.' . |
|
116 | - $constraintTypeItemId . '-' . |
|
115 | + 'wikibase.quality.constraints.check.timing.'. |
|
116 | + $constraintTypeItemId.'-'. |
|
117 | 117 | $constraintCheckerClassShortName, |
118 | 118 | $durationSeconds * 1000 |
119 | 119 | ); |
120 | 120 | |
121 | 121 | // find the longest limit (and associated log level) that the duration exceeds |
122 | - list( $limitSeconds, $logLevel ) = $this->findLimit( |
|
122 | + list($limitSeconds, $logLevel) = $this->findLimit( |
|
123 | 123 | $this->constraintCheckDurationLimits, |
124 | 124 | $durationSeconds |
125 | 125 | ); |
126 | - if ( $limitSeconds === null ) { |
|
126 | + if ($limitSeconds === null) { |
|
127 | 127 | return; |
128 | 128 | } |
129 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
129 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
130 | 130 | // TODO log less details but still log something |
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | 134 | $resultMessage = $result->getMessage(); |
135 | - if ( $resultMessage !== null ) { |
|
135 | + if ($resultMessage !== null) { |
|
136 | 136 | $resultMessageKey = $resultMessage->getMessageKey(); |
137 | 137 | } else { |
138 | 138 | $resultMessageKey = null; |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | |
141 | 141 | $this->logger->log( |
142 | 142 | $logLevel, |
143 | - 'Constraint check with {constraintCheckerClassShortName} ' . |
|
144 | - 'took longer than {limitSeconds} second(s) ' . |
|
143 | + 'Constraint check with {constraintCheckerClassShortName} '. |
|
144 | + 'took longer than {limitSeconds} second(s) '. |
|
145 | 145 | '(duration: {durationSeconds} seconds).', |
146 | 146 | [ |
147 | 147 | 'method' => $method, |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | 'constraintId' => $constraint->getConstraintId(), |
152 | 152 | 'constraintPropertyId' => $constraint->getPropertyId()->getSerialization(), |
153 | 153 | 'constraintTypeItemId' => $constraintTypeItemId, |
154 | - 'constraintParameters' => json_encode( $constraint->getConstraintParameters() ), |
|
154 | + 'constraintParameters' => json_encode($constraint->getConstraintParameters()), |
|
155 | 155 | 'constraintCheckerClass' => $constraintCheckerClass, |
156 | 156 | 'constraintCheckerClassShortName' => $constraintCheckerClassShortName, |
157 | 157 | 'entityId' => $context->getEntity()->getId()->getSerialization(), |
158 | 158 | 'statementGuid' => $context->getSnakStatement()->getGuid(), |
159 | 159 | 'resultStatus' => $result->getStatus(), |
160 | - 'resultParameters' => json_encode( $result->getParameters() ), |
|
160 | + 'resultParameters' => json_encode($result->getParameters()), |
|
161 | 161 | 'resultMessage' => $resultMessageKey, |
162 | 162 | ] |
163 | 163 | ); |
@@ -187,18 +187,18 @@ discard block |
||
187 | 187 | ); |
188 | 188 | |
189 | 189 | // find the longest limit (and associated log level) that the duration exceeds |
190 | - list( $limitSeconds, $logLevel ) = $this->findLimit( |
|
190 | + list($limitSeconds, $logLevel) = $this->findLimit( |
|
191 | 191 | $this->constraintCheckOnEntityDurationLimits, |
192 | 192 | $durationSeconds |
193 | 193 | ); |
194 | - if ( $limitSeconds === null ) { |
|
194 | + if ($limitSeconds === null) { |
|
195 | 195 | return; |
196 | 196 | } |
197 | 197 | |
198 | 198 | $this->logger->log( |
199 | 199 | $logLevel, |
200 | - 'Full constraint check on {entityId} ' . |
|
201 | - 'took longer than {limitSeconds} second(s) ' . |
|
200 | + 'Full constraint check on {entityId} '. |
|
201 | + 'took longer than {limitSeconds} second(s) '. |
|
202 | 202 | '(duration: {durationSeconds} seconds).', |
203 | 203 | [ |
204 | 204 | 'method' => $method, |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @param EntityId $entityId |
218 | 218 | */ |
219 | - public function logCheckConstraintsCacheHit( EntityId $entityId ) { |
|
219 | + public function logCheckConstraintsCacheHit(EntityId $entityId) { |
|
220 | 220 | $this->dataFactory->increment( |
221 | 221 | 'wikibase.quality.constraints.cache.entity.hit' |
222 | 222 | ); |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @param EntityId[] $entityIds |
229 | 229 | */ |
230 | - public function logCheckConstraintsCacheMisses( array $entityIds ) { |
|
230 | + public function logCheckConstraintsCacheMisses(array $entityIds) { |
|
231 | 231 | $this->dataFactory->updateCount( |
232 | 232 | 'wikibase.quality.constraints.cache.entity.miss', |
233 | - count( $entityIds ) |
|
233 | + count($entityIds) |
|
234 | 234 | ); |
235 | 235 | } |
236 | 236 | |
@@ -257,17 +257,17 @@ discard block |
||
257 | 257 | * @param EntityId[] $entityIds |
258 | 258 | * @param int $maxRevisionIds |
259 | 259 | */ |
260 | - public function logHugeDependencyMetadata( array $entityIds, $maxRevisionIds ) { |
|
260 | + public function logHugeDependencyMetadata(array $entityIds, $maxRevisionIds) { |
|
261 | 261 | $this->logger->log( |
262 | 262 | 'warning', |
263 | - 'Dependency metadata for constraint check result has huge set of entity IDs ' . |
|
264 | - '(count ' . count( $entityIds ) . ', limit ' . $maxRevisionIds . '); ' . |
|
263 | + 'Dependency metadata for constraint check result has huge set of entity IDs '. |
|
264 | + '(count '.count($entityIds).', limit '.$maxRevisionIds.'); '. |
|
265 | 265 | 'caching disabled for this check result.', |
266 | 266 | [ |
267 | 267 | 'loggingMethod' => __METHOD__, |
268 | 268 | 'entityIds' => json_encode( |
269 | 269 | array_map( |
270 | - function ( EntityId $entityId ) { |
|
270 | + function(EntityId $entityId) { |
|
271 | 271 | return $entityId->getSerialization(); |
272 | 272 | }, |
273 | 273 | $entityIds |
@@ -144,20 +144,20 @@ 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 ) { |
|
150 | - $startTime = microtime( true ); |
|
149 | + if ($entity instanceof StatementListProvider) { |
|
150 | + $startTime = microtime(true); |
|
151 | 151 | |
152 | 152 | $checkResults = $this->checkEveryStatement( |
153 | - $this->entityLookup->getEntity( $entityId ), |
|
153 | + $this->entityLookup->getEntity($entityId), |
|
154 | 154 | $constraintIds, |
155 | 155 | $defaultResultsPerContext |
156 | 156 | ); |
157 | 157 | |
158 | - $endTime = microtime( true ); |
|
158 | + $endTime = microtime(true); |
|
159 | 159 | |
160 | - if ( $constraintIds === null ) { // only log full constraint checks |
|
160 | + if ($constraintIds === null) { // only log full constraint checks |
|
161 | 161 | $this->loggingHelper->logConstraintCheckOnEntity( |
162 | 162 | $entityId, |
163 | 163 | $checkResults, |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | } |
168 | 168 | } |
169 | 169 | |
170 | - if ( $defaultResultsPerEntity !== null ) { |
|
171 | - $checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults ); |
|
170 | + if ($defaultResultsPerEntity !== null) { |
|
171 | + $checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults); |
|
172 | 172 | } |
173 | 173 | |
174 | - return $this->sortResult( $checkResults ); |
|
174 | + return $this->sortResult($checkResults); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | callable $defaultResults = null |
194 | 194 | ) { |
195 | 195 | |
196 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
196 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
197 | 197 | $entityId = $parsedGuid->getEntityId(); |
198 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
199 | - if ( $entity instanceof StatementListProvider ) { |
|
200 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
201 | - if ( $statement ) { |
|
198 | + $entity = $this->entityLookup->getEntity($entityId); |
|
199 | + if ($entity instanceof StatementListProvider) { |
|
200 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
201 | + if ($statement) { |
|
202 | 202 | $result = $this->checkStatement( |
203 | 203 | $entity, |
204 | 204 | $statement, |
205 | 205 | $constraintIds, |
206 | 206 | $defaultResults |
207 | 207 | ); |
208 | - $output = $this->sortResult( $result ); |
|
208 | + $output = $this->sortResult($result); |
|
209 | 209 | return $output; |
210 | 210 | } |
211 | 211 | } |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | return []; |
214 | 214 | } |
215 | 215 | |
216 | - private function getAllowedContextTypes( Constraint $constraint ) { |
|
217 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
216 | + private function getAllowedContextTypes(Constraint $constraint) { |
|
217 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
218 | 218 | return [ |
219 | 219 | Context::TYPE_STATEMENT, |
220 | 220 | Context::TYPE_QUALIFIER, |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | ]; |
223 | 223 | } |
224 | 224 | |
225 | - return array_keys( array_filter( |
|
225 | + return array_keys(array_filter( |
|
226 | 226 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
227 | - function ( $resultStatus ) { |
|
227 | + function($resultStatus) { |
|
228 | 228 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
229 | 229 | } |
230 | - ) ); |
|
230 | + )); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -238,32 +238,32 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @return ConstraintParameterException[] |
240 | 240 | */ |
241 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
241 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
242 | 242 | $constraintParameters = $constraint->getConstraintParameters(); |
243 | 243 | try { |
244 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
245 | - } catch ( ConstraintParameterException $e ) { |
|
246 | - return [ $e ]; |
|
244 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
245 | + } catch (ConstraintParameterException $e) { |
|
246 | + return [$e]; |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | $problems = []; |
250 | 250 | try { |
251 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
252 | - } catch ( ConstraintParameterException $e ) { |
|
251 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
252 | + } catch (ConstraintParameterException $e) { |
|
253 | 253 | $problems[] = $e; |
254 | 254 | } |
255 | 255 | try { |
256 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
257 | - } catch ( ConstraintParameterException $e ) { |
|
256 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
257 | + } catch (ConstraintParameterException $e) { |
|
258 | 258 | $problems[] = $e; |
259 | 259 | } |
260 | 260 | try { |
261 | 261 | $this->constraintParameterParser->parseConstraintScopeParameter( |
262 | 262 | $constraintParameters, |
263 | 263 | $constraint->getConstraintTypeItemId(), |
264 | - $this->getAllowedContextTypes( $constraint ) |
|
264 | + $this->getAllowedContextTypes($constraint) |
|
265 | 265 | ); |
266 | - } catch ( ConstraintParameterException $e ) { |
|
266 | + } catch (ConstraintParameterException $e) { |
|
267 | 267 | $problems[] = $e; |
268 | 268 | } |
269 | 269 | return $problems; |
@@ -276,16 +276,16 @@ discard block |
||
276 | 276 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
277 | 277 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
278 | 278 | */ |
279 | - public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) { |
|
280 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
279 | + public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) { |
|
280 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
281 | 281 | $result = []; |
282 | 282 | |
283 | - foreach ( $constraints as $constraint ) { |
|
284 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
283 | + foreach ($constraints as $constraint) { |
|
284 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
285 | 285 | |
286 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
286 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
287 | 287 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
288 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
288 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | $result[$constraint->getConstraintId()] = $problems; |
@@ -302,17 +302,17 @@ discard block |
||
302 | 302 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
303 | 303 | * (empty means all parameters okay), or null if constraint is not found |
304 | 304 | */ |
305 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
306 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
307 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
305 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
306 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
307 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
308 | 308 | |
309 | - foreach ( $constraints as $constraint ) { |
|
310 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
311 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
309 | + foreach ($constraints as $constraint) { |
|
310 | + if ($constraint->getConstraintId() === $constraintId) { |
|
311 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
312 | 312 | |
313 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
313 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
314 | 314 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
315 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
315 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | return $problems; |
@@ -337,14 +337,14 @@ discard block |
||
337 | 337 | $result = []; |
338 | 338 | |
339 | 339 | /** @var Statement $statement */ |
340 | - foreach ( $entity->getStatements() as $statement ) { |
|
341 | - $result = array_merge( $result, |
|
340 | + foreach ($entity->getStatements() as $statement) { |
|
341 | + $result = array_merge($result, |
|
342 | 342 | $this->checkStatement( |
343 | 343 | $entity, |
344 | 344 | $statement, |
345 | 345 | $constraintIds, |
346 | 346 | $defaultResultsPerContext |
347 | - ) ); |
|
347 | + )); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | return $result; |
@@ -366,32 +366,32 @@ discard block |
||
366 | 366 | ) { |
367 | 367 | $result = []; |
368 | 368 | |
369 | - $result = array_merge( $result, |
|
369 | + $result = array_merge($result, |
|
370 | 370 | $this->checkConstraintsForMainSnak( |
371 | 371 | $entity, |
372 | 372 | $statement, |
373 | 373 | $constraintIds, |
374 | 374 | $defaultResultsPerContext |
375 | - ) ); |
|
375 | + )); |
|
376 | 376 | |
377 | - if ( $this->checkQualifiers ) { |
|
378 | - $result = array_merge( $result, |
|
377 | + if ($this->checkQualifiers) { |
|
378 | + $result = array_merge($result, |
|
379 | 379 | $this->checkConstraintsForQualifiers( |
380 | 380 | $entity, |
381 | 381 | $statement, |
382 | 382 | $constraintIds, |
383 | 383 | $defaultResultsPerContext |
384 | - ) ); |
|
384 | + )); |
|
385 | 385 | } |
386 | 386 | |
387 | - if ( $this->checkReferences ) { |
|
388 | - $result = array_merge( $result, |
|
387 | + if ($this->checkReferences) { |
|
388 | + $result = array_merge($result, |
|
389 | 389 | $this->checkConstraintsForReferences( |
390 | 390 | $entity, |
391 | 391 | $statement, |
392 | 392 | $constraintIds, |
393 | 393 | $defaultResultsPerContext |
394 | - ) ); |
|
394 | + )); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | return $result; |
@@ -406,12 +406,12 @@ discard block |
||
406 | 406 | * @param string[]|null $constraintIds |
407 | 407 | * @return Constraint[] |
408 | 408 | */ |
409 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
410 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
411 | - if ( $constraintIds !== null ) { |
|
409 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
410 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
411 | + if ($constraintIds !== null) { |
|
412 | 412 | $constraintsToUse = []; |
413 | - foreach ( $constraints as $constraint ) { |
|
414 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
413 | + foreach ($constraints as $constraint) { |
|
414 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
415 | 415 | $constraintsToUse[] = $constraint; |
416 | 416 | } |
417 | 417 | } |
@@ -435,29 +435,29 @@ discard block |
||
435 | 435 | array $constraintIds = null, |
436 | 436 | callable $defaultResults = null |
437 | 437 | ) { |
438 | - $context = new MainSnakContext( $entity, $statement ); |
|
438 | + $context = new MainSnakContext($entity, $statement); |
|
439 | 439 | $constraints = $this->getConstraintsToUse( |
440 | 440 | $statement->getPropertyId(), |
441 | 441 | $constraintIds |
442 | 442 | ); |
443 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
443 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
444 | 444 | |
445 | - foreach ( $constraints as $constraint ) { |
|
445 | + foreach ($constraints as $constraint) { |
|
446 | 446 | $parameters = $constraint->getConstraintParameters(); |
447 | 447 | try { |
448 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
449 | - } catch ( ConstraintParameterException $e ) { |
|
450 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
448 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
449 | + } catch (ConstraintParameterException $e) { |
|
450 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
451 | 451 | continue; |
452 | 452 | } |
453 | 453 | |
454 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
455 | - $message = new ViolationMessage( 'wbqc-violation-message-exception' ); |
|
456 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
454 | + if (in_array($entity->getId(), $exceptions)) { |
|
455 | + $message = new ViolationMessage('wbqc-violation-message-exception'); |
|
456 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
457 | 457 | continue; |
458 | 458 | } |
459 | 459 | |
460 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
460 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | return $result; |
@@ -479,24 +479,24 @@ discard block |
||
479 | 479 | ) { |
480 | 480 | $result = []; |
481 | 481 | |
482 | - if ( in_array( |
|
482 | + if (in_array( |
|
483 | 483 | $statement->getPropertyId()->getSerialization(), |
484 | 484 | $this->propertiesWithViolatingQualifiers |
485 | - ) ) { |
|
485 | + )) { |
|
486 | 486 | return $result; |
487 | 487 | } |
488 | 488 | |
489 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
490 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
491 | - if ( $defaultResultsPerContext !== null ) { |
|
492 | - $result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) ); |
|
489 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
490 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
491 | + if ($defaultResultsPerContext !== null) { |
|
492 | + $result = array_merge($result, $defaultResultsPerContext($qualifierContext)); |
|
493 | 493 | } |
494 | 494 | $qualifierConstraints = $this->getConstraintsToUse( |
495 | 495 | $qualifierContext->getSnak()->getPropertyId(), |
496 | 496 | $constraintIds |
497 | 497 | ); |
498 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
499 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
498 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
499 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
500 | 500 | } |
501 | 501 | } |
502 | 502 | |
@@ -520,19 +520,19 @@ discard block |
||
520 | 520 | $result = []; |
521 | 521 | |
522 | 522 | /** @var Reference $reference */ |
523 | - foreach ( $statement->getReferences() as $reference ) { |
|
524 | - foreach ( $reference->getSnaks() as $snak ) { |
|
523 | + foreach ($statement->getReferences() as $reference) { |
|
524 | + foreach ($reference->getSnaks() as $snak) { |
|
525 | 525 | $referenceContext = new ReferenceContext( |
526 | 526 | $entity, $statement, $reference, $snak |
527 | 527 | ); |
528 | - if ( $defaultResultsPerContext !== null ) { |
|
529 | - $result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) ); |
|
528 | + if ($defaultResultsPerContext !== null) { |
|
529 | + $result = array_merge($result, $defaultResultsPerContext($referenceContext)); |
|
530 | 530 | } |
531 | 531 | $referenceConstraints = $this->getConstraintsToUse( |
532 | 532 | $referenceContext->getSnak()->getPropertyId(), |
533 | 533 | $constraintIds |
534 | 534 | ); |
535 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
535 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
536 | 536 | $result[] = $this->getCheckResultFor( |
537 | 537 | $referenceContext, |
538 | 538 | $referenceConstraint |
@@ -551,65 +551,65 @@ discard block |
||
551 | 551 | * @throws InvalidArgumentException |
552 | 552 | * @return CheckResult |
553 | 553 | */ |
554 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
555 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
554 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
555 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
556 | 556 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
557 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
557 | + $result = $this->handleScope($checker, $context, $constraint); |
|
558 | 558 | |
559 | - if ( $result !== null ) { |
|
560 | - $this->addMetadata( $context, $result ); |
|
559 | + if ($result !== null) { |
|
560 | + $this->addMetadata($context, $result); |
|
561 | 561 | return $result; |
562 | 562 | } |
563 | 563 | |
564 | - $startTime = microtime( true ); |
|
564 | + $startTime = microtime(true); |
|
565 | 565 | try { |
566 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
567 | - } catch ( ConstraintParameterException $e ) { |
|
568 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
569 | - } catch ( SparqlHelperException $e ) { |
|
570 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
571 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, $message ); |
|
566 | + $result = $checker->checkConstraint($context, $constraint); |
|
567 | + } catch (ConstraintParameterException $e) { |
|
568 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
569 | + } catch (SparqlHelperException $e) { |
|
570 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
571 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, $message); |
|
572 | 572 | } |
573 | - $endTime = microtime( true ); |
|
573 | + $endTime = microtime(true); |
|
574 | 574 | |
575 | - $this->addMetadata( $context, $result ); |
|
575 | + $this->addMetadata($context, $result); |
|
576 | 576 | |
577 | 577 | try { |
578 | 578 | $constraintStatus = $this->constraintParameterParser |
579 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
580 | - } catch ( ConstraintParameterException $e ) { |
|
581 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
579 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
580 | + } catch (ConstraintParameterException $e) { |
|
581 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
582 | 582 | $constraintStatus = null; |
583 | 583 | } |
584 | - if ( $constraintStatus === null ) { |
|
584 | + if ($constraintStatus === null) { |
|
585 | 585 | // downgrade violation to warning |
586 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
587 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
586 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
587 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
588 | 588 | } |
589 | 589 | } else { |
590 | - if ( $constraintStatus !== 'mandatory' ) { |
|
590 | + if ($constraintStatus !== 'mandatory') { |
|
591 | 591 | // @codeCoverageIgnoreStart |
592 | 592 | throw new LogicException( |
593 | - "Unknown constraint status '$constraintStatus', " . |
|
593 | + "Unknown constraint status '$constraintStatus', ". |
|
594 | 594 | "only known status is 'mandatory'" |
595 | 595 | ); |
596 | 596 | // @codeCoverageIgnoreEnd |
597 | 597 | } |
598 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
598 | + $result->addParameter('constraint_status', $constraintStatus); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | $this->loggingHelper->logConstraintCheck( |
602 | 602 | $context, |
603 | 603 | $constraint, |
604 | 604 | $result, |
605 | - get_class( $checker ), |
|
605 | + get_class($checker), |
|
606 | 606 | $endTime - $startTime, |
607 | 607 | __METHOD__ |
608 | 608 | ); |
609 | 609 | |
610 | 610 | return $result; |
611 | 611 | } else { |
612 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
612 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
613 | 613 | } |
614 | 614 | } |
615 | 615 | |
@@ -623,29 +623,29 @@ discard block |
||
623 | 623 | $constraint->getConstraintParameters(), |
624 | 624 | $constraint->getConstraintTypeItemId() |
625 | 625 | ); |
626 | - } catch ( ConstraintParameterException $e ) { |
|
627 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
626 | + } catch (ConstraintParameterException $e) { |
|
627 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
628 | 628 | } |
629 | - if ( $checkedContextTypes === null ) { |
|
629 | + if ($checkedContextTypes === null) { |
|
630 | 630 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
631 | 631 | } |
632 | - if ( !in_array( $context->getType(), $checkedContextTypes ) ) { |
|
633 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
632 | + if (!in_array($context->getType(), $checkedContextTypes)) { |
|
633 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
634 | 634 | } |
635 | - if ( $checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO ) { |
|
636 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
635 | + if ($checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO) { |
|
636 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
637 | 637 | } |
638 | 638 | return null; |
639 | 639 | } |
640 | 640 | |
641 | - private function addMetadata( Context $context, CheckResult $result ) { |
|
642 | - $result->withMetadata( Metadata::merge( [ |
|
641 | + private function addMetadata(Context $context, CheckResult $result) { |
|
642 | + $result->withMetadata(Metadata::merge([ |
|
643 | 643 | $result->getMetadata(), |
644 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
645 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
646 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
647 | - ] ) ), |
|
648 | - ] ) ); |
|
644 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
645 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
646 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
647 | + ])), |
|
648 | + ])); |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | /** |
@@ -653,12 +653,12 @@ discard block |
||
653 | 653 | * |
654 | 654 | * @return CheckResult[] |
655 | 655 | */ |
656 | - private function sortResult( array $result ) { |
|
657 | - if ( count( $result ) < 2 ) { |
|
656 | + private function sortResult(array $result) { |
|
657 | + if (count($result) < 2) { |
|
658 | 658 | return $result; |
659 | 659 | } |
660 | 660 | |
661 | - $sortFunction = function ( CheckResult $a, CheckResult $b ) { |
|
661 | + $sortFunction = function(CheckResult $a, CheckResult $b) { |
|
662 | 662 | $orderNum = 0; |
663 | 663 | $order = [ |
664 | 664 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -674,55 +674,55 @@ discard block |
||
674 | 674 | $statusA = $a->getStatus(); |
675 | 675 | $statusB = $b->getStatus(); |
676 | 676 | |
677 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
678 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
677 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
678 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
679 | 679 | |
680 | - if ( $orderA === $orderB ) { |
|
680 | + if ($orderA === $orderB) { |
|
681 | 681 | $cursorA = $a->getContextCursor(); |
682 | 682 | $cursorB = $b->getContextCursor(); |
683 | 683 | |
684 | - if ( $cursorA instanceof EntityContextCursor ) { |
|
684 | + if ($cursorA instanceof EntityContextCursor) { |
|
685 | 685 | return $cursorB instanceof EntityContextCursor ? 0 : -1; |
686 | 686 | } |
687 | - if ( $cursorB instanceof EntityContextCursor ) { |
|
687 | + if ($cursorB instanceof EntityContextCursor) { |
|
688 | 688 | return $cursorA instanceof EntityContextCursor ? 0 : 1; |
689 | 689 | } |
690 | 690 | |
691 | 691 | $pidA = $cursorA->getSnakPropertyId(); |
692 | 692 | $pidB = $cursorB->getSnakPropertyId(); |
693 | 693 | |
694 | - if ( $pidA === $pidB ) { |
|
694 | + if ($pidA === $pidB) { |
|
695 | 695 | $hashA = $cursorA->getSnakHash(); |
696 | 696 | $hashB = $cursorB->getSnakHash(); |
697 | 697 | |
698 | - if ( $hashA === $hashB ) { |
|
699 | - if ( $a instanceof NullResult ) { |
|
698 | + if ($hashA === $hashB) { |
|
699 | + if ($a instanceof NullResult) { |
|
700 | 700 | return $b instanceof NullResult ? 0 : -1; |
701 | 701 | } |
702 | - if ( $b instanceof NullResult ) { |
|
702 | + if ($b instanceof NullResult) { |
|
703 | 703 | return $a instanceof NullResult ? 0 : 1; |
704 | 704 | } |
705 | 705 | |
706 | 706 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
707 | 707 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
708 | 708 | |
709 | - if ( $typeA == $typeB ) { |
|
709 | + if ($typeA == $typeB) { |
|
710 | 710 | return 0; |
711 | 711 | } else { |
712 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
712 | + return ($typeA > $typeB) ? 1 : -1; |
|
713 | 713 | } |
714 | 714 | } else { |
715 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
715 | + return ($hashA > $hashB) ? 1 : -1; |
|
716 | 716 | } |
717 | 717 | } else { |
718 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
718 | + return ($pidA > $pidB) ? 1 : -1; |
|
719 | 719 | } |
720 | 720 | } else { |
721 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
721 | + return ($orderA > $orderB) ? 1 : -1; |
|
722 | 722 | } |
723 | 723 | }; |
724 | 724 | |
725 | - uasort( $result, $sortFunction ); |
|
725 | + uasort($result, $sortFunction); |
|
726 | 726 | |
727 | 727 | return $result; |
728 | 728 | } |