@@ -79,19 +79,19 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return self |
81 | 81 | */ |
82 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
82 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
83 | 83 | $repo = WikibaseRepo::getDefaultInstance(); |
84 | 84 | |
85 | 85 | $language = $repo->getUserLanguage(); |
86 | 86 | $formatterOptions = new FormatterOptions(); |
87 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
87 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
88 | 88 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
89 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
89 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
90 | 90 | |
91 | 91 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
92 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $language ); |
|
92 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($language); |
|
93 | 93 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
94 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $language ); |
|
94 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($language); |
|
95 | 95 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
96 | 96 | $dataFactory = MediaWikiServices::getInstance()->getStatsdDataFactory(); |
97 | 97 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $prefix, |
114 | 114 | $repo->getEntityIdParser(), |
115 | 115 | $repo->getStatementGuidValidator(), |
116 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
116 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
117 | 117 | $resultsSource, |
118 | 118 | $checkResultsRenderer, |
119 | 119 | $dataFactory |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | CheckResultsRenderer $checkResultsRenderer, |
143 | 143 | IBufferingStatsdDataFactory $dataFactory |
144 | 144 | ) { |
145 | - parent::__construct( $main, $name, $prefix ); |
|
145 | + parent::__construct($main, $name, $prefix); |
|
146 | 146 | $this->entityIdParser = $entityIdParser; |
147 | 147 | $this->statementGuidValidator = $statementGuidValidator; |
148 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
149 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
148 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
149 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
150 | 150 | $this->resultsSource = $resultsSource; |
151 | 151 | $this->checkResultsRenderer = $checkResultsRenderer; |
152 | 152 | $this->dataFactory = $dataFactory; |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | |
163 | 163 | $params = $this->extractRequestParams(); |
164 | 164 | |
165 | - $this->validateParameters( $params ); |
|
166 | - $entityIds = $this->parseEntityIds( $params ); |
|
167 | - $claimIds = $this->parseClaimIds( $params ); |
|
165 | + $this->validateParameters($params); |
|
166 | + $entityIds = $this->parseEntityIds($params); |
|
167 | + $claimIds = $this->parseClaimIds($params); |
|
168 | 168 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
169 | 169 | $statuses = $params[self::PARAM_STATUS]; |
170 | 170 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | ) |
181 | 181 | )->getArray() |
182 | 182 | ); |
183 | - $this->resultBuilder->markSuccess( 1 ); |
|
183 | + $this->resultBuilder->markSuccess(1); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -188,24 +188,24 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @return EntityId[] |
190 | 190 | */ |
191 | - private function parseEntityIds( array $params ) { |
|
191 | + private function parseEntityIds(array $params) { |
|
192 | 192 | $ids = $params[self::PARAM_ID]; |
193 | 193 | |
194 | - if ( $ids === null ) { |
|
194 | + if ($ids === null) { |
|
195 | 195 | return []; |
196 | - } elseif ( $ids === [] ) { |
|
196 | + } elseif ($ids === []) { |
|
197 | 197 | $this->errorReporter->dieError( |
198 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
198 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
199 | 199 | } |
200 | 200 | |
201 | - return array_map( function ( $id ) { |
|
201 | + return array_map(function($id) { |
|
202 | 202 | try { |
203 | - return $this->entityIdParser->parse( $id ); |
|
204 | - } catch ( EntityIdParsingException $e ) { |
|
203 | + return $this->entityIdParser->parse($id); |
|
204 | + } catch (EntityIdParsingException $e) { |
|
205 | 205 | $this->errorReporter->dieError( |
206 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
206 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
207 | 207 | } |
208 | - }, $ids ); |
|
208 | + }, $ids); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -213,35 +213,35 @@ discard block |
||
213 | 213 | * |
214 | 214 | * @return string[] |
215 | 215 | */ |
216 | - private function parseClaimIds( array $params ) { |
|
216 | + private function parseClaimIds(array $params) { |
|
217 | 217 | $ids = $params[self::PARAM_CLAIM_ID]; |
218 | 218 | |
219 | - if ( $ids === null ) { |
|
219 | + if ($ids === null) { |
|
220 | 220 | return []; |
221 | - } elseif ( $ids === [] ) { |
|
221 | + } elseif ($ids === []) { |
|
222 | 222 | $this->errorReporter->dieError( |
223 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
223 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
224 | 224 | } |
225 | 225 | |
226 | - foreach ( $ids as $id ) { |
|
227 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
226 | + foreach ($ids as $id) { |
|
227 | + if (!$this->statementGuidValidator->validate($id)) { |
|
228 | 228 | $this->errorReporter->dieError( |
229 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
229 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
230 | 230 | } |
231 | 231 | } |
232 | 232 | |
233 | 233 | return $ids; |
234 | 234 | } |
235 | 235 | |
236 | - private function validateParameters( array $params ) { |
|
237 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
238 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
236 | + private function validateParameters(array $params) { |
|
237 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
238 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
239 | 239 | ) { |
240 | 240 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
241 | 241 | $this->errorReporter->dieError( |
242 | 242 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
243 | 243 | } |
244 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
244 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
245 | 245 | $paramId = self::PARAM_ID; |
246 | 246 | $paramClaimId = self::PARAM_CLAIM_ID; |
247 | 247 | $this->errorReporter->dieError( |
@@ -282,12 +282,12 @@ discard block |
||
282 | 282 | ], |
283 | 283 | ApiBase::PARAM_ISMULTI => true, |
284 | 284 | ApiBase::PARAM_ALL => true, |
285 | - ApiBase::PARAM_DFLT => implode( '|', [ |
|
285 | + ApiBase::PARAM_DFLT => implode('|', [ |
|
286 | 286 | CheckResult::STATUS_VIOLATION, |
287 | 287 | CheckResult::STATUS_WARNING, |
288 | 288 | CheckResult::STATUS_SUGGESTION, |
289 | 289 | CheckResult::STATUS_BAD_PARAMETERS, |
290 | - ] ), |
|
290 | + ]), |
|
291 | 291 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
292 | 292 | ], |
293 | 293 | ]; |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | Config $config, |
137 | 137 | IBufferingStatsdDataFactory $dataFactory |
138 | 138 | ) { |
139 | - parent::__construct( 'ConstraintReport' ); |
|
139 | + parent::__construct('ConstraintReport'); |
|
140 | 140 | |
141 | 141 | $this->entityLookup = $entityLookup; |
142 | 142 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $language = $this->getLanguage(); |
146 | 146 | |
147 | 147 | $formatterOptions = new FormatterOptions(); |
148 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
148 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
149 | 149 | $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter( |
150 | 150 | SnakFormatter::FORMAT_HTML, |
151 | 151 | $formatterOptions |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * @return string |
206 | 206 | */ |
207 | 207 | public function getDescription() { |
208 | - return $this->msg( 'wbqc-constraintreport' )->escaped(); |
|
208 | + return $this->msg('wbqc-constraintreport')->escaped(); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -217,43 +217,43 @@ discard block |
||
217 | 217 | * @throws EntityIdParsingException |
218 | 218 | * @throws UnexpectedValueException |
219 | 219 | */ |
220 | - public function execute( $subPage ) { |
|
220 | + public function execute($subPage) { |
|
221 | 221 | $out = $this->getOutput(); |
222 | 222 | |
223 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
224 | - if ( $postRequest ) { |
|
225 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
223 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
224 | + if ($postRequest) { |
|
225 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
226 | 226 | return; |
227 | 227 | } |
228 | 228 | |
229 | 229 | $out->enableOOUI(); |
230 | - $out->addModules( $this->getModules() ); |
|
230 | + $out->addModules($this->getModules()); |
|
231 | 231 | |
232 | 232 | $this->setHeaders(); |
233 | 233 | |
234 | - $out->addHTML( $this->getExplanationText() ); |
|
234 | + $out->addHTML($this->getExplanationText()); |
|
235 | 235 | $this->buildEntityIdForm(); |
236 | 236 | |
237 | - if ( !$subPage ) { |
|
237 | + if (!$subPage) { |
|
238 | 238 | return; |
239 | 239 | } |
240 | 240 | |
241 | - if ( !is_string( $subPage ) ) { |
|
242 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
241 | + if (!is_string($subPage)) { |
|
242 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | try { |
246 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
247 | - } catch ( EntityIdParsingException $e ) { |
|
246 | + $entityId = $this->entityIdParser->parse($subPage); |
|
247 | + } catch (EntityIdParsingException $e) { |
|
248 | 248 | $out->addHTML( |
249 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
249 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
250 | 250 | ); |
251 | 251 | return; |
252 | 252 | } |
253 | 253 | |
254 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
254 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
255 | 255 | $out->addHTML( |
256 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
256 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
257 | 257 | ); |
258 | 258 | return; |
259 | 259 | } |
@@ -261,18 +261,18 @@ discard block |
||
261 | 261 | $this->dataFactory->increment( |
262 | 262 | 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck' |
263 | 263 | ); |
264 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
264 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
265 | 265 | |
266 | - if ( $results !== [] ) { |
|
266 | + if ($results !== []) { |
|
267 | 267 | $out->addHTML( |
268 | - $this->buildResultHeader( $entityId ) |
|
269 | - . $this->buildSummary( $results ) |
|
270 | - . $this->buildResultTable( $entityId, $results ) |
|
268 | + $this->buildResultHeader($entityId) |
|
269 | + . $this->buildSummary($results) |
|
270 | + . $this->buildResultTable($entityId, $results) |
|
271 | 271 | ); |
272 | 272 | } else { |
273 | 273 | $out->addHTML( |
274 | - $this->buildResultHeader( $entityId ) |
|
275 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
274 | + $this->buildResultHeader($entityId) |
|
275 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
276 | 276 | ); |
277 | 277 | } |
278 | 278 | } |
@@ -288,15 +288,15 @@ discard block |
||
288 | 288 | 'name' => 'entityid', |
289 | 289 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
290 | 290 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
291 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped() |
|
291 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped() |
|
292 | 292 | ] |
293 | 293 | ]; |
294 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
295 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
296 | - $htmlForm->setSubmitCallback( function() { |
|
294 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
295 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
296 | + $htmlForm->setSubmitCallback(function() { |
|
297 | 297 | return false; |
298 | 298 | } ); |
299 | - $htmlForm->setMethod( 'post' ); |
|
299 | + $htmlForm->setMethod('post'); |
|
300 | 300 | $htmlForm->show(); |
301 | 301 | } |
302 | 302 | |
@@ -310,16 +310,16 @@ discard block |
||
310 | 310 | * |
311 | 311 | * @return string HTML |
312 | 312 | */ |
313 | - private function buildNotice( $messageKey, $error = false ) { |
|
314 | - if ( !is_string( $messageKey ) ) { |
|
315 | - throw new InvalidArgumentException( '$message must be string.' ); |
|
313 | + private function buildNotice($messageKey, $error = false) { |
|
314 | + if (!is_string($messageKey)) { |
|
315 | + throw new InvalidArgumentException('$message must be string.'); |
|
316 | 316 | } |
317 | - if ( !is_bool( $error ) ) { |
|
318 | - throw new InvalidArgumentException( '$error must be bool.' ); |
|
317 | + if (!is_bool($error)) { |
|
318 | + throw new InvalidArgumentException('$error must be bool.'); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | $cssClasses = 'wbqc-constraintreport-notice'; |
322 | - if ( $error ) { |
|
322 | + if ($error) { |
|
323 | 323 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
324 | 324 | } |
325 | 325 | |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | [ |
329 | 329 | 'class' => $cssClasses |
330 | 330 | ], |
331 | - $this->msg( $messageKey )->escaped() |
|
331 | + $this->msg($messageKey)->escaped() |
|
332 | 332 | ); |
333 | 333 | } |
334 | 334 | |
@@ -338,16 +338,16 @@ discard block |
||
338 | 338 | private function getExplanationText() { |
339 | 339 | return Html::rawElement( |
340 | 340 | 'div', |
341 | - [ 'class' => 'wbqc-explanation' ], |
|
341 | + ['class' => 'wbqc-explanation'], |
|
342 | 342 | Html::rawElement( |
343 | 343 | 'p', |
344 | 344 | [], |
345 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
345 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
346 | 346 | ) |
347 | 347 | . Html::rawElement( |
348 | 348 | 'p', |
349 | 349 | [], |
350 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
350 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
351 | 351 | ) |
352 | 352 | ); |
353 | 353 | } |
@@ -358,72 +358,72 @@ discard block |
||
358 | 358 | * |
359 | 359 | * @return string HTML |
360 | 360 | */ |
361 | - private function buildResultTable( EntityId $entityId, array $results ) { |
|
361 | + private function buildResultTable(EntityId $entityId, array $results) { |
|
362 | 362 | // Set table headers |
363 | 363 | $table = new HtmlTableBuilder( |
364 | 364 | [ |
365 | 365 | new HtmlTableHeaderBuilder( |
366 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(), |
|
366 | + $this->msg('wbqc-constraintreport-result-table-header-status')->escaped(), |
|
367 | 367 | true |
368 | 368 | ), |
369 | 369 | new HtmlTableHeaderBuilder( |
370 | - $this->msg( 'wbqc-constraintreport-result-table-header-property' )->escaped(), |
|
370 | + $this->msg('wbqc-constraintreport-result-table-header-property')->escaped(), |
|
371 | 371 | true |
372 | 372 | ), |
373 | 373 | new HtmlTableHeaderBuilder( |
374 | - $this->msg( 'wbqc-constraintreport-result-table-header-message' )->escaped(), |
|
374 | + $this->msg('wbqc-constraintreport-result-table-header-message')->escaped(), |
|
375 | 375 | true |
376 | 376 | ), |
377 | 377 | new HtmlTableHeaderBuilder( |
378 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(), |
|
378 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(), |
|
379 | 379 | true |
380 | 380 | ) |
381 | 381 | ] |
382 | 382 | ); |
383 | 383 | |
384 | - foreach ( $results as $result ) { |
|
385 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
384 | + foreach ($results as $result) { |
|
385 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | return $table->toHtml(); |
389 | 389 | } |
390 | 390 | |
391 | - private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) { |
|
391 | + private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) { |
|
392 | 392 | $message = $result->getMessage(); |
393 | - if ( $message === null ) { |
|
393 | + if ($message === null) { |
|
394 | 394 | // no row for this result |
395 | 395 | return $table; |
396 | 396 | } |
397 | 397 | |
398 | 398 | // Status column |
399 | - $statusColumn = $this->formatStatus( $result->getStatus() ); |
|
399 | + $statusColumn = $this->formatStatus($result->getStatus()); |
|
400 | 400 | |
401 | 401 | // Property column |
402 | - $propertyId = new PropertyId( $result->getContextCursor()->getSnakPropertyId() ); |
|
402 | + $propertyId = new PropertyId($result->getContextCursor()->getSnakPropertyId()); |
|
403 | 403 | $propertyColumn = $this->getClaimLink( |
404 | 404 | $entityId, |
405 | 405 | $propertyId, |
406 | - $this->entityIdLabelFormatter->formatEntityId( $propertyId ) |
|
406 | + $this->entityIdLabelFormatter->formatEntityId($propertyId) |
|
407 | 407 | ); |
408 | 408 | |
409 | 409 | // Message column |
410 | - $messageColumn = $this->violationMessageRenderer->render( $message ); |
|
410 | + $messageColumn = $this->violationMessageRenderer->render($message); |
|
411 | 411 | |
412 | 412 | // Constraint column |
413 | 413 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
414 | 414 | try { |
415 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
416 | - } catch ( InvalidArgumentException $e ) { |
|
417 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
415 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
416 | + } catch (InvalidArgumentException $e) { |
|
417 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
418 | 418 | } |
419 | 419 | $constraintLink = $this->getClaimLink( |
420 | 420 | $propertyId, |
421 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
421 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
422 | 422 | $constraintTypeLabel |
423 | 423 | ); |
424 | 424 | $constraintColumn = $this->buildExpandableElement( |
425 | 425 | $constraintLink, |
426 | - $this->constraintParameterRenderer->formatParameters( $result->getParameters() ), |
|
426 | + $this->constraintParameterRenderer->formatParameters($result->getParameters()), |
|
427 | 427 | '[...]' |
428 | 428 | ); |
429 | 429 | |
@@ -463,15 +463,15 @@ discard block |
||
463 | 463 | * |
464 | 464 | * @return string HTML |
465 | 465 | */ |
466 | - protected function buildResultHeader( EntityId $entityId ) { |
|
467 | - $entityLink = sprintf( '%s (%s)', |
|
468 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
469 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
466 | + protected function buildResultHeader(EntityId $entityId) { |
|
467 | + $entityLink = sprintf('%s (%s)', |
|
468 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
469 | + htmlspecialchars($entityId->getSerialization())); |
|
470 | 470 | |
471 | 471 | return Html::rawElement( |
472 | 472 | 'h3', |
473 | 473 | [], |
474 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
474 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
475 | 475 | ); |
476 | 476 | } |
477 | 477 | |
@@ -482,24 +482,24 @@ discard block |
||
482 | 482 | * |
483 | 483 | * @return string HTML |
484 | 484 | */ |
485 | - protected function buildSummary( array $results ) { |
|
485 | + protected function buildSummary(array $results) { |
|
486 | 486 | $statuses = []; |
487 | - foreach ( $results as $result ) { |
|
488 | - $status = strtolower( $result->getStatus() ); |
|
489 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
487 | + foreach ($results as $result) { |
|
488 | + $status = strtolower($result->getStatus()); |
|
489 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | $statusElements = []; |
493 | - foreach ( $statuses as $status => $count ) { |
|
494 | - if ( $count > 0 ) { |
|
493 | + foreach ($statuses as $status => $count) { |
|
494 | + if ($count > 0) { |
|
495 | 495 | $statusElements[] = |
496 | - $this->formatStatus( $status ) |
|
496 | + $this->formatStatus($status) |
|
497 | 497 | . ': ' |
498 | 498 | . $count; |
499 | 499 | } |
500 | 500 | } |
501 | 501 | |
502 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
502 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | /** |
@@ -514,15 +514,15 @@ discard block |
||
514 | 514 | * |
515 | 515 | * @return string HTML |
516 | 516 | */ |
517 | - protected function buildExpandableElement( $content, $expandableContent, $indicator ) { |
|
518 | - if ( !is_string( $content ) ) { |
|
519 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
517 | + protected function buildExpandableElement($content, $expandableContent, $indicator) { |
|
518 | + if (!is_string($content)) { |
|
519 | + throw new InvalidArgumentException('$content has to be string.'); |
|
520 | 520 | } |
521 | - if ( $expandableContent && ( !is_string( $expandableContent ) ) ) { |
|
522 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
521 | + if ($expandableContent && (!is_string($expandableContent))) { |
|
522 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
523 | 523 | } |
524 | 524 | |
525 | - if ( empty( $expandableContent ) ) { |
|
525 | + if (empty($expandableContent)) { |
|
526 | 526 | return $content; |
527 | 527 | } |
528 | 528 | |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | $expandableContent |
543 | 543 | ); |
544 | 544 | |
545 | - return sprintf( '%s %s %s', $content, $tooltipIndicator, $expandableContent ); |
|
545 | + return sprintf('%s %s %s', $content, $tooltipIndicator, $expandableContent); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -554,8 +554,8 @@ discard block |
||
554 | 554 | * |
555 | 555 | * @return string HTML |
556 | 556 | */ |
557 | - private function formatStatus( $status ) { |
|
558 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
557 | + private function formatStatus($status) { |
|
558 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
559 | 559 | $statusIcons = [ |
560 | 560 | CheckResult::STATUS_SUGGESTION => [ |
561 | 561 | 'icon' => 'suggestion-constraint-violation', |
@@ -572,25 +572,25 @@ discard block |
||
572 | 572 | ], |
573 | 573 | ]; |
574 | 574 | |
575 | - if ( array_key_exists( $status, $statusIcons ) ) { |
|
576 | - $iconWidget = new IconWidget( $statusIcons[$status] ); |
|
577 | - $iconHtml = $iconWidget->toString() . ' '; |
|
575 | + if (array_key_exists($status, $statusIcons)) { |
|
576 | + $iconWidget = new IconWidget($statusIcons[$status]); |
|
577 | + $iconHtml = $iconWidget->toString().' '; |
|
578 | 578 | } else { |
579 | 579 | $iconHtml = ''; |
580 | 580 | } |
581 | 581 | |
582 | - $labelWidget = new LabelWidget( [ |
|
583 | - 'label' => $this->msg( $messageName )->text(), |
|
584 | - ] ); |
|
582 | + $labelWidget = new LabelWidget([ |
|
583 | + 'label' => $this->msg($messageName)->text(), |
|
584 | + ]); |
|
585 | 585 | $labelHtml = $labelWidget->toString(); |
586 | 586 | |
587 | 587 | $formattedStatus = |
588 | 588 | Html::rawElement( |
589 | 589 | 'span', |
590 | 590 | [ |
591 | - 'class' => 'wbqc-status wbqc-status-' . $status |
|
591 | + 'class' => 'wbqc-status wbqc-status-'.$status |
|
592 | 592 | ], |
593 | - $iconHtml . $labelHtml |
|
593 | + $iconHtml.$labelHtml |
|
594 | 594 | ); |
595 | 595 | |
596 | 596 | return $formattedStatus; |
@@ -606,26 +606,26 @@ discard block |
||
606 | 606 | * |
607 | 607 | * @return string HTML |
608 | 608 | */ |
609 | - protected function formatDataValues( $dataValues, $separator = ', ' ) { |
|
610 | - if ( $dataValues instanceof DataValue ) { |
|
611 | - $dataValues = [ $dataValues ]; |
|
612 | - } elseif ( !is_array( $dataValues ) ) { |
|
613 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
609 | + protected function formatDataValues($dataValues, $separator = ', ') { |
|
610 | + if ($dataValues instanceof DataValue) { |
|
611 | + $dataValues = [$dataValues]; |
|
612 | + } elseif (!is_array($dataValues)) { |
|
613 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | $formattedDataValues = []; |
617 | - foreach ( $dataValues as $dataValue ) { |
|
618 | - if ( !( $dataValue instanceof DataValue ) ) { |
|
619 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
617 | + foreach ($dataValues as $dataValue) { |
|
618 | + if (!($dataValue instanceof DataValue)) { |
|
619 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
620 | 620 | } |
621 | - if ( $dataValue instanceof EntityIdValue ) { |
|
622 | - $formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() ); |
|
621 | + if ($dataValue instanceof EntityIdValue) { |
|
622 | + $formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId()); |
|
623 | 623 | } else { |
624 | - $formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue ); |
|
624 | + $formattedDataValues[] = $this->dataValueFormatter->format($dataValue); |
|
625 | 625 | } |
626 | 626 | } |
627 | 627 | |
628 | - return implode( $separator, $formattedDataValues ); |
|
628 | + return implode($separator, $formattedDataValues); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | /** |
@@ -637,11 +637,11 @@ discard block |
||
637 | 637 | * |
638 | 638 | * @return string HTML |
639 | 639 | */ |
640 | - private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) { |
|
640 | + private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) { |
|
641 | 641 | return Html::rawElement( |
642 | 642 | 'a', |
643 | 643 | [ |
644 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
644 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
645 | 645 | 'target' => '_blank' |
646 | 646 | ], |
647 | 647 | $text |
@@ -656,9 +656,9 @@ discard block |
||
656 | 656 | * |
657 | 657 | * @return string |
658 | 658 | */ |
659 | - private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) { |
|
660 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
661 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
659 | + private function getClaimUrl(EntityId $entityId, PropertyId $propertyId) { |
|
660 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
661 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
662 | 662 | |
663 | 663 | return $entityUrl; |
664 | 664 | } |
@@ -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,43 +551,43 @@ 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 | - $this->downgradeResultStatus( $context, $result ); |
|
577 | + $this->downgradeResultStatus($context, $result); |
|
578 | 578 | |
579 | 579 | $this->loggingHelper->logConstraintCheck( |
580 | 580 | $context, |
581 | 581 | $constraint, |
582 | 582 | $result, |
583 | - get_class( $checker ), |
|
583 | + get_class($checker), |
|
584 | 584 | $endTime - $startTime, |
585 | 585 | __METHOD__ |
586 | 586 | ); |
587 | 587 | |
588 | 588 | return $result; |
589 | 589 | } else { |
590 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
590 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
591 | 591 | } |
592 | 592 | } |
593 | 593 | |
@@ -601,61 +601,61 @@ discard block |
||
601 | 601 | $constraint->getConstraintParameters(), |
602 | 602 | $constraint->getConstraintTypeItemId() |
603 | 603 | ); |
604 | - } catch ( ConstraintParameterException $e ) { |
|
605 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
604 | + } catch (ConstraintParameterException $e) { |
|
605 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
606 | 606 | } |
607 | - if ( $checkedContextTypes === null ) { |
|
607 | + if ($checkedContextTypes === null) { |
|
608 | 608 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
609 | 609 | } |
610 | - if ( !in_array( $context->getType(), $checkedContextTypes ) ) { |
|
611 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
610 | + if (!in_array($context->getType(), $checkedContextTypes)) { |
|
611 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
612 | 612 | } |
613 | - if ( $checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO ) { |
|
614 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
613 | + if ($checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO) { |
|
614 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
615 | 615 | } |
616 | 616 | return null; |
617 | 617 | } |
618 | 618 | |
619 | - private function addMetadata( Context $context, CheckResult $result ) { |
|
620 | - $result->withMetadata( Metadata::merge( [ |
|
619 | + private function addMetadata(Context $context, CheckResult $result) { |
|
620 | + $result->withMetadata(Metadata::merge([ |
|
621 | 621 | $result->getMetadata(), |
622 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
623 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
624 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
625 | - ] ) ), |
|
626 | - ] ) ); |
|
622 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
623 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
624 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
625 | + ])), |
|
626 | + ])); |
|
627 | 627 | } |
628 | 628 | |
629 | - private function downgradeResultStatus( Context $context, CheckResult &$result ) { |
|
629 | + private function downgradeResultStatus(Context $context, CheckResult &$result) { |
|
630 | 630 | $constraint = $result->getConstraint(); |
631 | 631 | try { |
632 | 632 | $constraintStatus = $this->constraintParameterParser |
633 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
634 | - } catch ( ConstraintParameterException $e ) { |
|
635 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
633 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
634 | + } catch (ConstraintParameterException $e) { |
|
635 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
636 | 636 | $constraintStatus = null; |
637 | 637 | } |
638 | - if ( $constraintStatus === null ) { |
|
638 | + if ($constraintStatus === null) { |
|
639 | 639 | // downgrade violation to warning |
640 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
641 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
640 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
641 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
642 | 642 | } |
643 | - } elseif ( $constraintStatus === 'suggestion' ) { |
|
643 | + } elseif ($constraintStatus === 'suggestion') { |
|
644 | 644 | // downgrade violation to suggestion |
645 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
646 | - $result->setStatus( CheckResult::STATUS_SUGGESTION ); |
|
645 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
646 | + $result->setStatus(CheckResult::STATUS_SUGGESTION); |
|
647 | 647 | } |
648 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
648 | + $result->addParameter('constraint_status', $constraintStatus); |
|
649 | 649 | } else { |
650 | - if ( $constraintStatus !== 'mandatory' ) { |
|
650 | + if ($constraintStatus !== 'mandatory') { |
|
651 | 651 | // @codeCoverageIgnoreStart |
652 | 652 | throw new LogicException( |
653 | - "Unknown constraint status '$constraintStatus', " . |
|
653 | + "Unknown constraint status '$constraintStatus', ". |
|
654 | 654 | "only known status is 'mandatory'" |
655 | 655 | ); |
656 | 656 | // @codeCoverageIgnoreEnd |
657 | 657 | } |
658 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
658 | + $result->addParameter('constraint_status', $constraintStatus); |
|
659 | 659 | } |
660 | 660 | } |
661 | 661 | |
@@ -664,12 +664,12 @@ discard block |
||
664 | 664 | * |
665 | 665 | * @return CheckResult[] |
666 | 666 | */ |
667 | - private function sortResult( array $result ) { |
|
668 | - if ( count( $result ) < 2 ) { |
|
667 | + private function sortResult(array $result) { |
|
668 | + if (count($result) < 2) { |
|
669 | 669 | return $result; |
670 | 670 | } |
671 | 671 | |
672 | - $sortFunction = function ( CheckResult $a, CheckResult $b ) { |
|
672 | + $sortFunction = function(CheckResult $a, CheckResult $b) { |
|
673 | 673 | $orderNum = 0; |
674 | 674 | $order = [ |
675 | 675 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -686,55 +686,55 @@ discard block |
||
686 | 686 | $statusA = $a->getStatus(); |
687 | 687 | $statusB = $b->getStatus(); |
688 | 688 | |
689 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
690 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
689 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
690 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
691 | 691 | |
692 | - if ( $orderA === $orderB ) { |
|
692 | + if ($orderA === $orderB) { |
|
693 | 693 | $cursorA = $a->getContextCursor(); |
694 | 694 | $cursorB = $b->getContextCursor(); |
695 | 695 | |
696 | - if ( $cursorA instanceof EntityContextCursor ) { |
|
696 | + if ($cursorA instanceof EntityContextCursor) { |
|
697 | 697 | return $cursorB instanceof EntityContextCursor ? 0 : -1; |
698 | 698 | } |
699 | - if ( $cursorB instanceof EntityContextCursor ) { |
|
699 | + if ($cursorB instanceof EntityContextCursor) { |
|
700 | 700 | return $cursorA instanceof EntityContextCursor ? 0 : 1; |
701 | 701 | } |
702 | 702 | |
703 | 703 | $pidA = $cursorA->getSnakPropertyId(); |
704 | 704 | $pidB = $cursorB->getSnakPropertyId(); |
705 | 705 | |
706 | - if ( $pidA === $pidB ) { |
|
706 | + if ($pidA === $pidB) { |
|
707 | 707 | $hashA = $cursorA->getSnakHash(); |
708 | 708 | $hashB = $cursorB->getSnakHash(); |
709 | 709 | |
710 | - if ( $hashA === $hashB ) { |
|
711 | - if ( $a instanceof NullResult ) { |
|
710 | + if ($hashA === $hashB) { |
|
711 | + if ($a instanceof NullResult) { |
|
712 | 712 | return $b instanceof NullResult ? 0 : -1; |
713 | 713 | } |
714 | - if ( $b instanceof NullResult ) { |
|
714 | + if ($b instanceof NullResult) { |
|
715 | 715 | return $a instanceof NullResult ? 0 : 1; |
716 | 716 | } |
717 | 717 | |
718 | 718 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
719 | 719 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
720 | 720 | |
721 | - if ( $typeA == $typeB ) { |
|
721 | + if ($typeA == $typeB) { |
|
722 | 722 | return 0; |
723 | 723 | } else { |
724 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
724 | + return ($typeA > $typeB) ? 1 : -1; |
|
725 | 725 | } |
726 | 726 | } else { |
727 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
727 | + return ($hashA > $hashB) ? 1 : -1; |
|
728 | 728 | } |
729 | 729 | } else { |
730 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
730 | + return ($pidA > $pidB) ? 1 : -1; |
|
731 | 731 | } |
732 | 732 | } else { |
733 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
733 | + return ($orderA > $orderB) ? 1 : -1; |
|
734 | 734 | } |
735 | 735 | }; |
736 | 736 | |
737 | - uasort( $result, $sortFunction ); |
|
737 | + uasort($result, $sortFunction); |
|
738 | 738 | |
739 | 739 | return $result; |
740 | 740 | } |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | * @param array $parameters |
79 | 79 | * @throws ConstraintParameterException |
80 | 80 | */ |
81 | - public function checkError( array $parameters ) { |
|
82 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
81 | + public function checkError(array $parameters) { |
|
82 | + if (array_key_exists('@error', $parameters)) { |
|
83 | 83 | $error = $parameters['@error']; |
84 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
84 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
85 | 85 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
86 | 86 | } else { |
87 | 87 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
88 | 88 | } |
89 | - throw new ConstraintParameterException( new ViolationMessage( $msg ) ); |
|
89 | + throw new ConstraintParameterException(new ViolationMessage($msg)); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | * @param string $parameterId |
97 | 97 | * @throws ConstraintParameterException |
98 | 98 | */ |
99 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
100 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
99 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
100 | + if (count($parameters[$parameterId]) !== 1) { |
|
101 | 101 | throw new ConstraintParameterException( |
102 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) ) |
|
103 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
102 | + (new ViolationMessage('wbqc-violation-message-parameter-single')) |
|
103 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
104 | 104 | ); |
105 | 105 | } |
106 | 106 | } |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * @return void |
113 | 113 | * @throws ConstraintParameterException |
114 | 114 | */ |
115 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
116 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
115 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
116 | + if (!($snak instanceof PropertyValueSnak)) { |
|
117 | 117 | throw new ConstraintParameterException( |
118 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
119 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
118 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
119 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
120 | 120 | ); |
121 | 121 | } |
122 | 122 | } |
@@ -128,17 +128,17 @@ discard block |
||
128 | 128 | * @throws ConstraintParameterException |
129 | 129 | * @return EntityId |
130 | 130 | */ |
131 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
132 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
133 | - $this->requireValueParameter( $snak, $parameterId ); |
|
131 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
132 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
133 | + $this->requireValueParameter($snak, $parameterId); |
|
134 | 134 | $value = $snak->getDataValue(); |
135 | - if ( $value instanceof EntityIdValue ) { |
|
135 | + if ($value instanceof EntityIdValue) { |
|
136 | 136 | return $value->getEntityId(); |
137 | 137 | } else { |
138 | 138 | throw new ConstraintParameterException( |
139 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) ) |
|
140 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
141 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
139 | + (new ViolationMessage('wbqc-violation-message-parameter-entity')) |
|
140 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
141 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
142 | 142 | ); |
143 | 143 | } |
144 | 144 | } |
@@ -149,20 +149,20 @@ discard block |
||
149 | 149 | * @throws ConstraintParameterException if the parameter is invalid or missing |
150 | 150 | * @return string[] class entity ID serializations |
151 | 151 | */ |
152 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
153 | - $this->checkError( $constraintParameters ); |
|
154 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
155 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
152 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
153 | + $this->checkError($constraintParameters); |
|
154 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
155 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
156 | 156 | throw new ConstraintParameterException( |
157 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
158 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
159 | - ->withEntityId( new PropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
157 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
158 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
159 | + ->withEntityId(new PropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
160 | 160 | ); |
161 | 161 | } |
162 | 162 | |
163 | 163 | $classes = []; |
164 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
165 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
164 | + foreach ($constraintParameters[$classId] as $class) { |
|
165 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
166 | 166 | } |
167 | 167 | return $classes; |
168 | 168 | } |
@@ -173,23 +173,23 @@ discard block |
||
173 | 173 | * @throws ConstraintParameterException if the parameter is invalid or missing |
174 | 174 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
175 | 175 | */ |
176 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
177 | - $this->checkError( $constraintParameters ); |
|
178 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
179 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
176 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
177 | + $this->checkError($constraintParameters); |
|
178 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
179 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
180 | 180 | throw new ConstraintParameterException( |
181 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
182 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
183 | - ->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
181 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
182 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
183 | + ->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
184 | 184 | ); |
185 | 185 | } |
186 | 186 | |
187 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
188 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
189 | - $instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ); |
|
190 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ); |
|
191 | - $instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ); |
|
192 | - switch ( $relationEntityId ) { |
|
187 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
188 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
189 | + $instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId'); |
|
190 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId'); |
|
191 | + $instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId'); |
|
192 | + switch ($relationEntityId) { |
|
193 | 193 | case $instanceId: |
194 | 194 | return 'instance'; |
195 | 195 | case $subclassId: |
@@ -198,13 +198,13 @@ discard block |
||
198 | 198 | return 'instanceOrSubclass'; |
199 | 199 | default: |
200 | 200 | throw new ConstraintParameterException( |
201 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
202 | - ->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
201 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
202 | + ->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
203 | 203 | ->withEntityIdList( |
204 | 204 | [ |
205 | - new ItemId( $instanceId ), |
|
206 | - new ItemId( $subclassId ), |
|
207 | - new ItemId( $instanceOrSubclassId ), |
|
205 | + new ItemId($instanceId), |
|
206 | + new ItemId($subclassId), |
|
207 | + new ItemId($instanceOrSubclassId), |
|
208 | 208 | ], |
209 | 209 | Role::CONSTRAINT_PARAMETER_VALUE |
210 | 210 | ) |
@@ -219,20 +219,20 @@ discard block |
||
219 | 219 | * @throws ConstraintParameterException |
220 | 220 | * @return PropertyId |
221 | 221 | */ |
222 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
223 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
224 | - $this->requireValueParameter( $snak, $parameterId ); |
|
222 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
223 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
224 | + $this->requireValueParameter($snak, $parameterId); |
|
225 | 225 | $value = $snak->getDataValue(); |
226 | - if ( $value instanceof EntityIdValue ) { |
|
226 | + if ($value instanceof EntityIdValue) { |
|
227 | 227 | $id = $value->getEntityId(); |
228 | - if ( $id instanceof PropertyId ) { |
|
228 | + if ($id instanceof PropertyId) { |
|
229 | 229 | return $id; |
230 | 230 | } |
231 | 231 | } |
232 | 232 | throw new ConstraintParameterException( |
233 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) ) |
|
234 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
235 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
233 | + (new ViolationMessage('wbqc-violation-message-parameter-property')) |
|
234 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
235 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
236 | 236 | ); |
237 | 237 | } |
238 | 238 | |
@@ -243,32 +243,32 @@ discard block |
||
243 | 243 | * @throws ConstraintParameterException if the parameter is invalid or missing |
244 | 244 | * @return PropertyId |
245 | 245 | */ |
246 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
247 | - $this->checkError( $constraintParameters ); |
|
248 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
249 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
246 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
247 | + $this->checkError($constraintParameters); |
|
248 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
249 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
250 | 250 | throw new ConstraintParameterException( |
251 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
252 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
253 | - ->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
251 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
252 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
253 | + ->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
254 | 254 | ); |
255 | 255 | } |
256 | 256 | |
257 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
258 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
257 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
258 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
259 | 259 | } |
260 | 260 | |
261 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
261 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
262 | 262 | $dataValue = $snak->getDataValue(); |
263 | - if ( $dataValue instanceof EntityIdValue && |
|
263 | + if ($dataValue instanceof EntityIdValue && |
|
264 | 264 | $dataValue->getEntityId() instanceof ItemId |
265 | 265 | ) { |
266 | - return ItemIdSnakValue::fromItemId( $dataValue->getEntityId() ); |
|
266 | + return ItemIdSnakValue::fromItemId($dataValue->getEntityId()); |
|
267 | 267 | } else { |
268 | 268 | throw new ConstraintParameterException( |
269 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
270 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
271 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
269 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
270 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
271 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
272 | 272 | ); |
273 | 273 | } |
274 | 274 | } |
@@ -287,16 +287,16 @@ discard block |
||
287 | 287 | $required, |
288 | 288 | $parameterId = null |
289 | 289 | ) { |
290 | - $this->checkError( $constraintParameters ); |
|
291 | - if ( $parameterId === null ) { |
|
292 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
290 | + $this->checkError($constraintParameters); |
|
291 | + if ($parameterId === null) { |
|
292 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
293 | 293 | } |
294 | - if ( !array_key_exists( $parameterId, $constraintParameters ) ) { |
|
295 | - if ( $required ) { |
|
294 | + if (!array_key_exists($parameterId, $constraintParameters)) { |
|
295 | + if ($required) { |
|
296 | 296 | throw new ConstraintParameterException( |
297 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
298 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
299 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
297 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
298 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
299 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
300 | 300 | ); |
301 | 301 | } else { |
302 | 302 | return []; |
@@ -304,11 +304,11 @@ discard block |
||
304 | 304 | } |
305 | 305 | |
306 | 306 | $values = []; |
307 | - foreach ( $constraintParameters[$parameterId] as $parameter ) { |
|
308 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
309 | - switch ( true ) { |
|
307 | + foreach ($constraintParameters[$parameterId] as $parameter) { |
|
308 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
309 | + switch (true) { |
|
310 | 310 | case $snak instanceof PropertyValueSnak: |
311 | - $values[] = $this->parseItemIdParameter( $snak, $parameterId ); |
|
311 | + $values[] = $this->parseItemIdParameter($snak, $parameterId); |
|
312 | 312 | break; |
313 | 313 | case $snak instanceof PropertySomeValueSnak: |
314 | 314 | $values[] = ItemIdSnakValue::someValue(); |
@@ -327,27 +327,27 @@ discard block |
||
327 | 327 | * @throws ConstraintParameterException if the parameter is invalid or missing |
328 | 328 | * @return PropertyId[] |
329 | 329 | */ |
330 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
331 | - $this->checkError( $constraintParameters ); |
|
332 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
333 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
330 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
331 | + $this->checkError($constraintParameters); |
|
332 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
333 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
334 | 334 | throw new ConstraintParameterException( |
335 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
336 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
337 | - ->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
335 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
336 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
337 | + ->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
338 | 338 | ); |
339 | 339 | } |
340 | 340 | |
341 | 341 | $parameters = $constraintParameters[$propertyId]; |
342 | - if ( count( $parameters ) === 1 && |
|
343 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
342 | + if (count($parameters) === 1 && |
|
343 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
344 | 344 | ) { |
345 | 345 | return []; |
346 | 346 | } |
347 | 347 | |
348 | 348 | $properties = []; |
349 | - foreach ( $parameters as $parameter ) { |
|
350 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
349 | + foreach ($parameters as $parameter) { |
|
350 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
351 | 351 | } |
352 | 352 | return $properties; |
353 | 353 | } |
@@ -358,16 +358,16 @@ discard block |
||
358 | 358 | * @throws ConstraintParameterException |
359 | 359 | * @return DataValue|null |
360 | 360 | */ |
361 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
362 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
363 | - if ( $snak instanceof PropertyValueSnak ) { |
|
361 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
362 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
363 | + if ($snak instanceof PropertyValueSnak) { |
|
364 | 364 | return $snak->getDataValue(); |
365 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
365 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
366 | 366 | return null; |
367 | 367 | } else { |
368 | 368 | throw new ConstraintParameterException( |
369 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
370 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
369 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
370 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
371 | 371 | ); |
372 | 372 | } |
373 | 373 | } |
@@ -377,10 +377,10 @@ discard block |
||
377 | 377 | * @param string $parameterId |
378 | 378 | * @return DataValue|null |
379 | 379 | */ |
380 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
380 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
381 | 381 | try { |
382 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
383 | - } catch ( ConstraintParameterException $e ) { |
|
382 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
383 | + } catch (ConstraintParameterException $e) { |
|
384 | 384 | // unknown value means “now” |
385 | 385 | return new NowValue(); |
386 | 386 | } |
@@ -393,14 +393,14 @@ discard block |
||
393 | 393 | * @param string $unit |
394 | 394 | * @return bool |
395 | 395 | */ |
396 | - private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) { |
|
397 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
398 | - !( $max instanceof UnboundedQuantityValue ) |
|
396 | + private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) { |
|
397 | + if (!($min instanceof UnboundedQuantityValue) || |
|
398 | + !($max instanceof UnboundedQuantityValue) |
|
399 | 399 | ) { |
400 | 400 | return false; |
401 | 401 | } |
402 | 402 | |
403 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
403 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -413,42 +413,42 @@ discard block |
||
413 | 413 | * @throws ConstraintParameterException if the parameter is invalid or missing |
414 | 414 | * @return DataValue[] if the parameter is invalid or missing |
415 | 415 | */ |
416 | - private function parseRangeParameter( array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type ) { |
|
417 | - $this->checkError( $constraintParameters ); |
|
418 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
419 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
416 | + private function parseRangeParameter(array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type) { |
|
417 | + $this->checkError($constraintParameters); |
|
418 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
419 | + !array_key_exists($maximumId, $constraintParameters) |
|
420 | 420 | ) { |
421 | 421 | throw new ConstraintParameterException( |
422 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) ) |
|
423 | - ->withDataValueType( $type ) |
|
424 | - ->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
425 | - ->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
426 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
422 | + (new ViolationMessage('wbqc-violation-message-range-parameters-needed')) |
|
423 | + ->withDataValueType($type) |
|
424 | + ->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
425 | + ->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
426 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
427 | 427 | ); |
428 | 428 | } |
429 | 429 | |
430 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
431 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
430 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
431 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
432 | 432 | $parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
433 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
434 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
433 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
434 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
435 | 435 | |
436 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
437 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
436 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
437 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
438 | 438 | throw new ConstraintParameterException( |
439 | - new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
439 | + new ViolationMessage('wbqc-violation-message-range-parameters-one-year') |
|
440 | 440 | ); |
441 | 441 | } |
442 | - if ( $min === null && $max === null || |
|
443 | - $min !== null && $max !== null && $min->equals( $max ) ) { |
|
442 | + if ($min === null && $max === null || |
|
443 | + $min !== null && $max !== null && $min->equals($max)) { |
|
444 | 444 | throw new ConstraintParameterException( |
445 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) ) |
|
446 | - ->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
447 | - ->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
445 | + (new ViolationMessage('wbqc-violation-message-range-parameters-same')) |
|
446 | + ->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
447 | + ->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
448 | 448 | ); |
449 | 449 | } |
450 | 450 | |
451 | - return [ $min, $max ]; |
|
451 | + return [$min, $max]; |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
@@ -458,11 +458,11 @@ discard block |
||
458 | 458 | * @throws ConstraintParameterException if the parameter is invalid or missing |
459 | 459 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
460 | 460 | */ |
461 | - public function parseQuantityRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
461 | + public function parseQuantityRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
462 | 462 | return $this->parseRangeParameter( |
463 | 463 | $constraintParameters, |
464 | - $this->config->get( 'WBQualityConstraintsMinimumQuantityId' ), |
|
465 | - $this->config->get( 'WBQualityConstraintsMaximumQuantityId' ), |
|
464 | + $this->config->get('WBQualityConstraintsMinimumQuantityId'), |
|
465 | + $this->config->get('WBQualityConstraintsMaximumQuantityId'), |
|
466 | 466 | $constraintTypeItemId, |
467 | 467 | 'quantity' |
468 | 468 | ); |
@@ -475,11 +475,11 @@ discard block |
||
475 | 475 | * @throws ConstraintParameterException if the parameter is invalid or missing |
476 | 476 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
477 | 477 | */ |
478 | - public function parseTimeRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
478 | + public function parseTimeRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
479 | 479 | return $this->parseRangeParameter( |
480 | 480 | $constraintParameters, |
481 | - $this->config->get( 'WBQualityConstraintsMinimumDateId' ), |
|
482 | - $this->config->get( 'WBQualityConstraintsMaximumDateId' ), |
|
481 | + $this->config->get('WBQualityConstraintsMinimumDateId'), |
|
482 | + $this->config->get('WBQualityConstraintsMaximumDateId'), |
|
483 | 483 | $constraintTypeItemId, |
484 | 484 | 'time' |
485 | 485 | ); |
@@ -492,17 +492,17 @@ discard block |
||
492 | 492 | * @throws ConstraintParameterException |
493 | 493 | * @return string |
494 | 494 | */ |
495 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
496 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
497 | - $this->requireValueParameter( $snak, $parameterId ); |
|
495 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
496 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
497 | + $this->requireValueParameter($snak, $parameterId); |
|
498 | 498 | $value = $snak->getDataValue(); |
499 | - if ( $value instanceof StringValue ) { |
|
499 | + if ($value instanceof StringValue) { |
|
500 | 500 | return $value->getValue(); |
501 | 501 | } else { |
502 | 502 | throw new ConstraintParameterException( |
503 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) ) |
|
504 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
505 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
503 | + (new ViolationMessage('wbqc-violation-message-parameter-string')) |
|
504 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
505 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
506 | 506 | ); |
507 | 507 | } |
508 | 508 | } |
@@ -513,15 +513,15 @@ discard block |
||
513 | 513 | * @throws ConstraintParameterException if the parameter is invalid or missing |
514 | 514 | * @return string |
515 | 515 | */ |
516 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
517 | - $this->checkError( $constraintParameters ); |
|
518 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
519 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
516 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
517 | + $this->checkError($constraintParameters); |
|
518 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
519 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
520 | 520 | return ''; |
521 | 521 | } |
522 | 522 | |
523 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
524 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
523 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
524 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -530,19 +530,19 @@ discard block |
||
530 | 530 | * @throws ConstraintParameterException if the parameter is invalid or missing |
531 | 531 | * @return string |
532 | 532 | */ |
533 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
534 | - $this->checkError( $constraintParameters ); |
|
535 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
536 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
533 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
534 | + $this->checkError($constraintParameters); |
|
535 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
536 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
537 | 537 | throw new ConstraintParameterException( |
538 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
539 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
540 | - ->withEntityId( new PropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
538 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
539 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
540 | + ->withEntityId(new PropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
541 | 541 | ); |
542 | 542 | } |
543 | 543 | |
544 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
545 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
544 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
545 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -550,16 +550,16 @@ discard block |
||
550 | 550 | * @throws ConstraintParameterException if the parameter is invalid |
551 | 551 | * @return EntityId[] |
552 | 552 | */ |
553 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
554 | - $this->checkError( $constraintParameters ); |
|
555 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
556 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
553 | + public function parseExceptionParameter(array $constraintParameters) { |
|
554 | + $this->checkError($constraintParameters); |
|
555 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
556 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
557 | 557 | return []; |
558 | 558 | } |
559 | 559 | |
560 | 560 | return array_map( |
561 | - function( $snakSerialization ) use ( $exceptionId ) { |
|
562 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
561 | + function($snakSerialization) use ($exceptionId) { |
|
562 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
563 | 563 | }, |
564 | 564 | $constraintParameters[$exceptionId] |
565 | 565 | ); |
@@ -570,35 +570,35 @@ discard block |
||
570 | 570 | * @throws ConstraintParameterException if the parameter is invalid |
571 | 571 | * @return string|null 'mandatory', 'suggestion' or null |
572 | 572 | */ |
573 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
574 | - $this->checkError( $constraintParameters ); |
|
575 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
576 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
573 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
574 | + $this->checkError($constraintParameters); |
|
575 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
576 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
577 | 577 | return null; |
578 | 578 | } |
579 | 579 | |
580 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
581 | - $supportedStatuses = [ new ItemId( $mandatoryId ) ]; |
|
582 | - if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) { |
|
583 | - $suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' ); |
|
584 | - $supportedStatuses[] = new ItemId( $suggestionId ); |
|
580 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
581 | + $supportedStatuses = [new ItemId($mandatoryId)]; |
|
582 | + if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) { |
|
583 | + $suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId'); |
|
584 | + $supportedStatuses[] = new ItemId($suggestionId); |
|
585 | 585 | } else { |
586 | 586 | $suggestionId = null; |
587 | 587 | } |
588 | 588 | |
589 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
590 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
591 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
589 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
590 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
591 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
592 | 592 | $statusId = $snak->getDataValue()->getEntityId()->getSerialization(); |
593 | 593 | |
594 | - if ( $statusId === $mandatoryId ) { |
|
594 | + if ($statusId === $mandatoryId) { |
|
595 | 595 | return 'mandatory'; |
596 | - } elseif ( $statusId === $suggestionId ) { |
|
596 | + } elseif ($statusId === $suggestionId) { |
|
597 | 597 | return 'suggestion'; |
598 | 598 | } else { |
599 | 599 | throw new ConstraintParameterException( |
600 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
601 | - ->withEntityId( new PropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
600 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
601 | + ->withEntityId(new PropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
602 | 602 | ->withEntityIdList( |
603 | 603 | $supportedStatuses, |
604 | 604 | Role::CONSTRAINT_PARAMETER_VALUE |
@@ -614,12 +614,12 @@ discard block |
||
614 | 614 | * @return void |
615 | 615 | * @throws ConstraintParameterException |
616 | 616 | */ |
617 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
618 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
617 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
618 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
619 | 619 | throw new ConstraintParameterException( |
620 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) ) |
|
621 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
622 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
620 | + (new ViolationMessage('wbqc-violation-message-parameter-monolingualtext')) |
|
621 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
622 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
623 | 623 | ); |
624 | 624 | } |
625 | 625 | } |
@@ -632,30 +632,30 @@ discard block |
||
632 | 632 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
633 | 633 | * @return MultilingualTextValue |
634 | 634 | */ |
635 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
635 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
636 | 636 | $result = []; |
637 | 637 | |
638 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
639 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
640 | - $this->requireValueParameter( $snak, $parameterId ); |
|
638 | + foreach ($snakSerializations as $snakSerialization) { |
|
639 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
640 | + $this->requireValueParameter($snak, $parameterId); |
|
641 | 641 | |
642 | 642 | $value = $snak->getDataValue(); |
643 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
643 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
644 | 644 | /** @var MonolingualTextValue $value */ |
645 | 645 | |
646 | 646 | $code = $value->getLanguageCode(); |
647 | - if ( array_key_exists( $code, $result ) ) { |
|
647 | + if (array_key_exists($code, $result)) { |
|
648 | 648 | throw new ConstraintParameterException( |
649 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) ) |
|
650 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
651 | - ->withLanguage( $code ) |
|
649 | + (new ViolationMessage('wbqc-violation-message-parameter-single-per-language')) |
|
650 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
651 | + ->withLanguage($code) |
|
652 | 652 | ); |
653 | 653 | } |
654 | 654 | |
655 | 655 | $result[$code] = $value; |
656 | 656 | } |
657 | 657 | |
658 | - return new MultilingualTextValue( $result ); |
|
658 | + return new MultilingualTextValue($result); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | /** |
@@ -663,11 +663,11 @@ discard block |
||
663 | 663 | * @throws ConstraintParameterException if the parameter is invalid |
664 | 664 | * @return MultilingualTextValue |
665 | 665 | */ |
666 | - public function parseSyntaxClarificationParameter( array $constraintParameters ) { |
|
667 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
666 | + public function parseSyntaxClarificationParameter(array $constraintParameters) { |
|
667 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
668 | 668 | |
669 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
670 | - return new MultilingualTextValue( [] ); |
|
669 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
670 | + return new MultilingualTextValue([]); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -686,9 +686,9 @@ discard block |
||
686 | 686 | * @throws ConstraintParameterException if the parameter is invalid |
687 | 687 | * @return string[]|null Context::TYPE_* constants |
688 | 688 | */ |
689 | - public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) { |
|
689 | + public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) { |
|
690 | 690 | $contextTypes = []; |
691 | - $parameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
691 | + $parameterId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
692 | 692 | $items = $this->parseItemsParameter( |
693 | 693 | $constraintParameters, |
694 | 694 | $constraintTypeItemId, |
@@ -696,23 +696,23 @@ discard block |
||
696 | 696 | $parameterId |
697 | 697 | ); |
698 | 698 | |
699 | - if ( $items === [] ) { |
|
699 | + if ($items === []) { |
|
700 | 700 | return null; |
701 | 701 | } |
702 | 702 | |
703 | - foreach ( $items as $item ) { |
|
704 | - $contextTypes[] = $this->parseContextTypeItem( $item, 'constraint scope', $parameterId ); |
|
703 | + foreach ($items as $item) { |
|
704 | + $contextTypes[] = $this->parseContextTypeItem($item, 'constraint scope', $parameterId); |
|
705 | 705 | } |
706 | 706 | |
707 | - if ( $validScopes !== null ) { |
|
708 | - $invalidScopes = array_diff( $contextTypes, $validScopes ); |
|
709 | - if ( $invalidScopes !== [] ) { |
|
710 | - $invalidScope = array_pop( $invalidScopes ); |
|
707 | + if ($validScopes !== null) { |
|
708 | + $invalidScopes = array_diff($contextTypes, $validScopes); |
|
709 | + if ($invalidScopes !== []) { |
|
710 | + $invalidScope = array_pop($invalidScopes); |
|
711 | 711 | throw new ConstraintParameterException( |
712 | - ( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) ) |
|
713 | - ->withConstraintScope( $invalidScope, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
714 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
715 | - ->withConstraintScopeList( $validScopes, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
712 | + (new ViolationMessage('wbqc-violation-message-invalid-scope')) |
|
713 | + ->withConstraintScope($invalidScope, Role::CONSTRAINT_PARAMETER_VALUE) |
|
714 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
715 | + ->withConstraintScopeList($validScopes, Role::CONSTRAINT_PARAMETER_VALUE) |
|
716 | 716 | ); |
717 | 717 | } |
718 | 718 | } |
@@ -726,15 +726,15 @@ discard block |
||
726 | 726 | * @param ItemId $unitId |
727 | 727 | * @return string unit |
728 | 728 | */ |
729 | - private function parseUnitParameter( ItemId $unitId ) { |
|
729 | + private function parseUnitParameter(ItemId $unitId) { |
|
730 | 730 | $unitRepositoryName = $unitId->getRepositoryName(); |
731 | - if ( !array_key_exists( $unitRepositoryName, $this->conceptBaseUris ) ) { |
|
731 | + if (!array_key_exists($unitRepositoryName, $this->conceptBaseUris)) { |
|
732 | 732 | throw new LogicException( |
733 | - 'No base URI for concept URI for repository: ' . $unitRepositoryName |
|
733 | + 'No base URI for concept URI for repository: '.$unitRepositoryName |
|
734 | 734 | ); |
735 | 735 | } |
736 | 736 | $baseUri = $this->conceptBaseUris[$unitRepositoryName]; |
737 | - return $baseUri . $unitId->getSerialization(); |
|
737 | + return $baseUri.$unitId->getSerialization(); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | /** |
@@ -744,23 +744,23 @@ discard block |
||
744 | 744 | * @return UnitsParameter |
745 | 745 | * @throws ConstraintParameterException |
746 | 746 | */ |
747 | - private function parseUnitItem( ItemIdSnakValue $item ) { |
|
748 | - switch ( true ) { |
|
747 | + private function parseUnitItem(ItemIdSnakValue $item) { |
|
748 | + switch (true) { |
|
749 | 749 | case $item->isValue(): |
750 | - $unit = $this->parseUnitParameter( $item->getItemId() ); |
|
750 | + $unit = $this->parseUnitParameter($item->getItemId()); |
|
751 | 751 | return new UnitsParameter( |
752 | - [ $item->getItemId() ], |
|
753 | - [ UnboundedQuantityValue::newFromNumber( 1, $unit ) ], |
|
752 | + [$item->getItemId()], |
|
753 | + [UnboundedQuantityValue::newFromNumber(1, $unit)], |
|
754 | 754 | false |
755 | 755 | ); |
756 | 756 | case $item->isSomeValue(): |
757 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
757 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
758 | 758 | throw new ConstraintParameterException( |
759 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
760 | - ->withEntityId( new PropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
759 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
760 | + ->withEntityId(new PropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
761 | 761 | ); |
762 | 762 | case $item->isNoValue(): |
763 | - return new UnitsParameter( [], [], true ); |
|
763 | + return new UnitsParameter([], [], true); |
|
764 | 764 | } |
765 | 765 | } |
766 | 766 | |
@@ -770,26 +770,26 @@ discard block |
||
770 | 770 | * @throws ConstraintParameterException if the parameter is invalid or missing |
771 | 771 | * @return UnitsParameter |
772 | 772 | */ |
773 | - public function parseUnitsParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
774 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
773 | + public function parseUnitsParameter(array $constraintParameters, $constraintTypeItemId) { |
|
774 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
775 | 775 | $unitItems = []; |
776 | 776 | $unitQuantities = []; |
777 | 777 | $unitlessAllowed = false; |
778 | 778 | |
779 | - foreach ( $items as $item ) { |
|
780 | - $unit = $this->parseUnitItem( $item ); |
|
781 | - $unitItems = array_merge( $unitItems, $unit->getUnitItemIds() ); |
|
782 | - $unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() ); |
|
779 | + foreach ($items as $item) { |
|
780 | + $unit = $this->parseUnitItem($item); |
|
781 | + $unitItems = array_merge($unitItems, $unit->getUnitItemIds()); |
|
782 | + $unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities()); |
|
783 | 783 | $unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed(); |
784 | 784 | } |
785 | 785 | |
786 | - if ( $unitQuantities === [] && !$unitlessAllowed ) { |
|
786 | + if ($unitQuantities === [] && !$unitlessAllowed) { |
|
787 | 787 | throw new LogicException( |
788 | 788 | 'The "units" parameter is required, and yet we seem to be missing any allowed unit' |
789 | 789 | ); |
790 | 790 | } |
791 | 791 | |
792 | - return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed ); |
|
792 | + return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | /** |
@@ -799,49 +799,49 @@ discard block |
||
799 | 799 | * @return EntityTypesParameter |
800 | 800 | * @throws ConstraintParameterException |
801 | 801 | */ |
802 | - private function parseEntityTypeItem( ItemIdSnakValue $item ) { |
|
803 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
802 | + private function parseEntityTypeItem(ItemIdSnakValue $item) { |
|
803 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
804 | 804 | |
805 | - if ( !$item->isValue() ) { |
|
805 | + if (!$item->isValue()) { |
|
806 | 806 | throw new ConstraintParameterException( |
807 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
808 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
807 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
808 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
809 | 809 | ); |
810 | 810 | } |
811 | 811 | |
812 | 812 | $itemId = $item->getItemId(); |
813 | - switch ( $itemId->getSerialization() ) { |
|
814 | - case $this->config->get( 'WBQualityConstraintsWikibaseItemId' ): |
|
813 | + switch ($itemId->getSerialization()) { |
|
814 | + case $this->config->get('WBQualityConstraintsWikibaseItemId'): |
|
815 | 815 | $entityType = 'item'; |
816 | 816 | break; |
817 | - case $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ): |
|
817 | + case $this->config->get('WBQualityConstraintsWikibasePropertyId'): |
|
818 | 818 | $entityType = 'property'; |
819 | 819 | break; |
820 | - case $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ): |
|
820 | + case $this->config->get('WBQualityConstraintsWikibaseLexemeId'): |
|
821 | 821 | $entityType = 'lexeme'; |
822 | 822 | break; |
823 | - case $this->config->get( 'WBQualityConstraintsWikibaseFormId' ): |
|
823 | + case $this->config->get('WBQualityConstraintsWikibaseFormId'): |
|
824 | 824 | $entityType = 'form'; |
825 | 825 | break; |
826 | - case $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ): |
|
826 | + case $this->config->get('WBQualityConstraintsWikibaseSenseId'): |
|
827 | 827 | $entityType = 'sense'; |
828 | 828 | break; |
829 | 829 | default: |
830 | 830 | $allowed = [ |
831 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseItemId' ) ), |
|
832 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) ), |
|
833 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) ), |
|
834 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseFormId' ) ), |
|
835 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) ), |
|
831 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseItemId')), |
|
832 | + new ItemId($this->config->get('WBQualityConstraintsWikibasePropertyId')), |
|
833 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseLexemeId')), |
|
834 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseFormId')), |
|
835 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseSenseId')), |
|
836 | 836 | ]; |
837 | 837 | throw new ConstraintParameterException( |
838 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
839 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
840 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
838 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
839 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
840 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
841 | 841 | ); |
842 | 842 | } |
843 | 843 | |
844 | - return new EntityTypesParameter( [ $entityType ], [ $itemId ] ); |
|
844 | + return new EntityTypesParameter([$entityType], [$itemId]); |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | /** |
@@ -850,27 +850,27 @@ discard block |
||
850 | 850 | * @throws ConstraintParameterException if the parameter is invalid or missing |
851 | 851 | * @return EntityTypesParameter |
852 | 852 | */ |
853 | - public function parseEntityTypesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
853 | + public function parseEntityTypesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
854 | 854 | $entityTypes = []; |
855 | 855 | $entityTypeItemIds = []; |
856 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
856 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
857 | 857 | |
858 | - foreach ( $items as $item ) { |
|
859 | - $entityType = $this->parseEntityTypeItem( $item ); |
|
860 | - $entityTypes = array_merge( $entityTypes, $entityType->getEntityTypes() ); |
|
861 | - $entityTypeItemIds = array_merge( $entityTypeItemIds, $entityType->getEntityTypeItemIds() ); |
|
858 | + foreach ($items as $item) { |
|
859 | + $entityType = $this->parseEntityTypeItem($item); |
|
860 | + $entityTypes = array_merge($entityTypes, $entityType->getEntityTypes()); |
|
861 | + $entityTypeItemIds = array_merge($entityTypeItemIds, $entityType->getEntityTypeItemIds()); |
|
862 | 862 | } |
863 | 863 | |
864 | - if ( empty( $entityTypes ) ) { |
|
864 | + if (empty($entityTypes)) { |
|
865 | 865 | // @codeCoverageIgnoreStart |
866 | 866 | throw new LogicException( |
867 | - 'The "entity types" parameter is required, ' . |
|
867 | + 'The "entity types" parameter is required, '. |
|
868 | 868 | 'and yet we seem to be missing any allowed entity type' |
869 | 869 | ); |
870 | 870 | // @codeCoverageIgnoreEnd |
871 | 871 | } |
872 | 872 | |
873 | - return new EntityTypesParameter( $entityTypes, $entityTypeItemIds ); |
|
873 | + return new EntityTypesParameter($entityTypes, $entityTypeItemIds); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | /** |
@@ -878,18 +878,18 @@ discard block |
||
878 | 878 | * @throws ConstraintParameterException if the parameter is invalid |
879 | 879 | * @return PropertyId[] |
880 | 880 | */ |
881 | - public function parseSeparatorsParameter( array $constraintParameters ) { |
|
882 | - $separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' ); |
|
881 | + public function parseSeparatorsParameter(array $constraintParameters) { |
|
882 | + $separatorId = $this->config->get('WBQualityConstraintsSeparatorId'); |
|
883 | 883 | |
884 | - if ( !array_key_exists( $separatorId, $constraintParameters ) ) { |
|
884 | + if (!array_key_exists($separatorId, $constraintParameters)) { |
|
885 | 885 | return []; |
886 | 886 | } |
887 | 887 | |
888 | 888 | $parameters = $constraintParameters[$separatorId]; |
889 | 889 | $separators = []; |
890 | 890 | |
891 | - foreach ( $parameters as $parameter ) { |
|
892 | - $separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId ); |
|
891 | + foreach ($parameters as $parameter) { |
|
892 | + $separators[] = $this->parsePropertyIdParameter($parameter, $separatorId); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | return $separators; |
@@ -904,26 +904,26 @@ discard block |
||
904 | 904 | * @return string one of the Context::TYPE_* constants |
905 | 905 | * @throws ConstraintParameterException |
906 | 906 | */ |
907 | - private function parseContextTypeItem( ItemIdSnakValue $item, $use, $parameterId ) { |
|
908 | - if ( !$item->isValue() ) { |
|
907 | + private function parseContextTypeItem(ItemIdSnakValue $item, $use, $parameterId) { |
|
908 | + if (!$item->isValue()) { |
|
909 | 909 | throw new ConstraintParameterException( |
910 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
911 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
910 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
911 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
912 | 912 | ); |
913 | 913 | } |
914 | 914 | |
915 | - if ( $use === 'constraint scope' ) { |
|
916 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ); |
|
917 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ); |
|
918 | - $referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ); |
|
915 | + if ($use === 'constraint scope') { |
|
916 | + $mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId'); |
|
917 | + $qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId'); |
|
918 | + $referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId'); |
|
919 | 919 | } else { |
920 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
921 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
922 | - $referencesId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
920 | + $mainSnakId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
921 | + $qualifiersId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
922 | + $referencesId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
923 | 923 | } |
924 | 924 | |
925 | 925 | $itemId = $item->getItemId(); |
926 | - switch ( $itemId->getSerialization() ) { |
|
926 | + switch ($itemId->getSerialization()) { |
|
927 | 927 | case $mainSnakId: |
928 | 928 | return Context::TYPE_STATEMENT; |
929 | 929 | case $qualifiersId: |
@@ -931,11 +931,11 @@ discard block |
||
931 | 931 | case $referencesId: |
932 | 932 | return Context::TYPE_REFERENCE; |
933 | 933 | default: |
934 | - $allowed = [ $mainSnakId, $qualifiersId, $referencesId ]; |
|
934 | + $allowed = [$mainSnakId, $qualifiersId, $referencesId]; |
|
935 | 935 | throw new ConstraintParameterException( |
936 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
937 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
938 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
936 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
937 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
938 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
939 | 939 | ); |
940 | 940 | } |
941 | 941 | } |
@@ -946,9 +946,9 @@ discard block |
||
946 | 946 | * @throws ConstraintParameterException if the parameter is invalid or missing |
947 | 947 | * @return string[] list of Context::TYPE_* constants |
948 | 948 | */ |
949 | - public function parsePropertyScopeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
949 | + public function parsePropertyScopeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
950 | 950 | $contextTypes = []; |
951 | - $parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' ); |
|
951 | + $parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId'); |
|
952 | 952 | $items = $this->parseItemsParameter( |
953 | 953 | $constraintParameters, |
954 | 954 | $constraintTypeItemId, |
@@ -956,14 +956,14 @@ discard block |
||
956 | 956 | $parameterId |
957 | 957 | ); |
958 | 958 | |
959 | - foreach ( $items as $item ) { |
|
960 | - $contextTypes[] = $this->parseContextTypeItem( $item, 'property scope', $parameterId ); |
|
959 | + foreach ($items as $item) { |
|
960 | + $contextTypes[] = $this->parseContextTypeItem($item, 'property scope', $parameterId); |
|
961 | 961 | } |
962 | 962 | |
963 | - if ( empty( $contextTypes ) ) { |
|
963 | + if (empty($contextTypes)) { |
|
964 | 964 | // @codeCoverageIgnoreStart |
965 | 965 | throw new LogicException( |
966 | - 'The "property scope" parameter is required, ' . |
|
966 | + 'The "property scope" parameter is required, '. |
|
967 | 967 | 'and yet we seem to be missing any allowed scope' |
968 | 968 | ); |
969 | 969 | // @codeCoverageIgnoreEnd |