Completed
Push — master ( 3a0f65...5ee1ae )
by
unknown
02:19
created
src/ConstraintReportFactory.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	public static function getDefaultInstance() {
153 153
 		static $instance = null;
154 154
 
155
-		if ( $instance === null ) {
155
+		if ($instance === null) {
156 156
 			$wikibaseRepo = WikibaseRepo::getDefaultInstance();
157 157
 			$entityIdFormatter = $wikibaseRepo->getEntityIdHtmlLinkFormatterFactory()->getEntityIdFormatter(
158 158
 				$wikibaseRepo->getLanguageFallbackLabelDescriptionLookupFactory()->newLabelDescriptionLookup(
@@ -233,21 +233,21 @@  discard block
 block discarded – undo
233 233
 	 * @return DelegatingConstraintChecker
234 234
 	 */
235 235
 	public function getConstraintChecker() {
236
-		if ( $this->delegatingConstraintChecker === null ) {
236
+		if ($this->delegatingConstraintChecker === null) {
237 237
 			$this->delegatingConstraintChecker = new DelegatingConstraintChecker(
238 238
 				$this->lookup,
239 239
 				$this->getConstraintCheckerMap(),
240
-				new CachingConstraintLookup( $this->getConstraintRepository() ),
240
+				new CachingConstraintLookup($this->getConstraintRepository()),
241 241
 				$this->constraintParameterParser,
242 242
 				$this->statementGuidParser,
243 243
 				new LoggingHelper(
244 244
 					$this->dataFactory,
245
-					LoggerFactory::getInstance( 'WikibaseQualityConstraints' ),
245
+					LoggerFactory::getInstance('WikibaseQualityConstraints'),
246 246
 					$this->config
247 247
 				),
248
-				$this->config->get( 'WBQualityConstraintsCheckQualifiers' ),
249
-				$this->config->get( 'WBQualityConstraintsCheckReferences' ),
250
-				$this->config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' )
248
+				$this->config->get('WBQualityConstraintsCheckQualifiers'),
249
+				$this->config->get('WBQualityConstraintsCheckReferences'),
250
+				$this->config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers')
251 251
 			);
252 252
 		}
253 253
 
@@ -258,10 +258,10 @@  discard block
 block discarded – undo
258 258
 	 * @return ConstraintChecker[]
259 259
 	 */
260 260
 	private function getConstraintCheckerMap() {
261
-		if ( $this->constraintCheckerMap === null ) {
261
+		if ($this->constraintCheckerMap === null) {
262 262
 			$connectionCheckerHelper = new ConnectionCheckerHelper();
263
-			$rangeCheckerHelper = new RangeCheckerHelper( $this->config, $this->unitConverter );
264
-			if ( $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ) !== '' ) {
263
+			$rangeCheckerHelper = new RangeCheckerHelper($this->config, $this->unitConverter);
264
+			if ($this->config->get('WBQualityConstraintsSparqlEndpoint') !== '') {
265 265
 				$sparqlHelper = new SparqlHelper(
266 266
 					$this->config,
267 267
 					$this->rdfVocabulary,
@@ -284,74 +284,74 @@  discard block
 block discarded – undo
284 284
 			);
285 285
 
286 286
 			$this->constraintCheckerMap = [
287
-				$this->config->get( 'WBQualityConstraintsConflictsWithConstraintId' )
287
+				$this->config->get('WBQualityConstraintsConflictsWithConstraintId')
288 288
 					=> new ConflictsWithChecker(
289 289
 						$this->lookup,
290 290
 						$this->constraintParameterParser,
291 291
 						$connectionCheckerHelper,
292 292
 						$this->constraintParameterRenderer
293 293
 					),
294
-				$this->config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' )
294
+				$this->config->get('WBQualityConstraintsItemRequiresClaimConstraintId')
295 295
 					=> new ItemChecker(
296 296
 						$this->lookup,
297 297
 						$this->constraintParameterParser,
298 298
 						$connectionCheckerHelper,
299 299
 						$this->constraintParameterRenderer
300 300
 					),
301
-				$this->config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' )
301
+				$this->config->get('WBQualityConstraintsValueRequiresClaimConstraintId')
302 302
 					=> new TargetRequiredClaimChecker(
303 303
 						$this->lookup,
304 304
 						$this->constraintParameterParser,
305 305
 						$connectionCheckerHelper,
306 306
 						$this->constraintParameterRenderer
307 307
 					),
308
-				$this->config->get( 'WBQualityConstraintsSymmetricConstraintId' )
308
+				$this->config->get('WBQualityConstraintsSymmetricConstraintId')
309 309
 					=> new SymmetricChecker(
310 310
 						$this->lookup,
311 311
 						$connectionCheckerHelper,
312 312
 						$this->constraintParameterRenderer
313 313
 					),
314
-				$this->config->get( 'WBQualityConstraintsInverseConstraintId' )
314
+				$this->config->get('WBQualityConstraintsInverseConstraintId')
315 315
 					=> new InverseChecker(
316 316
 						$this->lookup,
317 317
 						$this->constraintParameterParser,
318 318
 						$connectionCheckerHelper,
319 319
 						$this->constraintParameterRenderer
320 320
 					),
321
-				$this->config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' )
321
+				$this->config->get('WBQualityConstraintsUsedAsQualifierConstraintId')
322 322
 					=> new QualifierChecker(),
323
-				$this->config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' )
323
+				$this->config->get('WBQualityConstraintsAllowedQualifiersConstraintId')
324 324
 					=> new QualifiersChecker(
325 325
 						$this->constraintParameterParser,
326 326
 						$this->constraintParameterRenderer
327 327
 					),
328
-				$this->config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' )
328
+				$this->config->get('WBQualityConstraintsMandatoryQualifierConstraintId')
329 329
 					=> new MandatoryQualifiersChecker(
330 330
 						$this->constraintParameterParser,
331 331
 						$this->constraintParameterRenderer
332 332
 					),
333
-				$this->config->get( 'WBQualityConstraintsRangeConstraintId' )
333
+				$this->config->get('WBQualityConstraintsRangeConstraintId')
334 334
 					=> new RangeChecker(
335 335
 						$this->propertyDataTypeLookup,
336 336
 						$this->constraintParameterParser,
337 337
 						$rangeCheckerHelper,
338 338
 						$this->constraintParameterRenderer
339 339
 					),
340
-				$this->config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' )
340
+				$this->config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId')
341 341
 					=> new DiffWithinRangeChecker(
342 342
 						$this->constraintParameterParser,
343 343
 						$rangeCheckerHelper,
344 344
 						$this->constraintParameterRenderer,
345 345
 						$this->config
346 346
 					),
347
-				$this->config->get( 'WBQualityConstraintsTypeConstraintId' )
347
+				$this->config->get('WBQualityConstraintsTypeConstraintId')
348 348
 					=> new TypeChecker(
349 349
 						$this->lookup,
350 350
 						$this->constraintParameterParser,
351 351
 						$typeCheckerHelper,
352 352
 						$this->config
353 353
 					),
354
-				$this->config->get( 'WBQualityConstraintsValueTypeConstraintId' )
354
+				$this->config->get('WBQualityConstraintsValueTypeConstraintId')
355 355
 					=> new ValueTypeChecker(
356 356
 						$this->lookup,
357 357
 						$this->constraintParameterParser,
@@ -359,40 +359,40 @@  discard block
 block discarded – undo
359 359
 						$typeCheckerHelper,
360 360
 						$this->config
361 361
 					),
362
-				$this->config->get( 'WBQualityConstraintsSingleValueConstraintId' )
362
+				$this->config->get('WBQualityConstraintsSingleValueConstraintId')
363 363
 					=> new SingleValueChecker(),
364
-				$this->config->get( 'WBQualityConstraintsMultiValueConstraintId' )
364
+				$this->config->get('WBQualityConstraintsMultiValueConstraintId')
365 365
 					=> new MultiValueChecker(),
366
-				$this->config->get( 'WBQualityConstraintsDistinctValuesConstraintId' )
366
+				$this->config->get('WBQualityConstraintsDistinctValuesConstraintId')
367 367
 					=> new UniqueValueChecker(
368 368
 						$this->constraintParameterRenderer,
369 369
 						$sparqlHelper
370 370
 					),
371
-				$this->config->get( 'WBQualityConstraintsFormatConstraintId' )
371
+				$this->config->get('WBQualityConstraintsFormatConstraintId')
372 372
 					=> new FormatChecker(
373 373
 						$this->constraintParameterParser,
374 374
 						$this->constraintParameterRenderer,
375 375
 						$this->config,
376 376
 						$sparqlHelper
377 377
 					),
378
-				$this->config->get( 'WBQualityConstraintsCommonsLinkConstraintId' )
378
+				$this->config->get('WBQualityConstraintsCommonsLinkConstraintId')
379 379
 					=> new CommonsLinkChecker(
380 380
 						$this->constraintParameterParser,
381 381
 						$this->constraintParameterRenderer,
382 382
 						$this->titleParser
383 383
 					),
384
-				$this->config->get( 'WBQualityConstraintsOneOfConstraintId' )
384
+				$this->config->get('WBQualityConstraintsOneOfConstraintId')
385 385
 					=> new OneOfChecker(
386 386
 						$this->constraintParameterParser,
387 387
 						$this->constraintParameterRenderer
388 388
 					),
389
-				$this->config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' )
389
+				$this->config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId')
390 390
 					=> new ValueOnlyChecker(),
391
-				$this->config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' )
391
+				$this->config->get('WBQualityConstraintsUsedAsReferenceConstraintId')
392 392
 					=> new ReferenceChecker(),
393
-				$this->config->get( 'WBQualityConstraintsNoBoundsConstraintId' )
393
+				$this->config->get('WBQualityConstraintsNoBoundsConstraintId')
394 394
 					=> new NoBoundsChecker(),
395
-				$this->config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' )
395
+				$this->config->get('WBQualityConstraintsAllowedUnitsConstraintId')
396 396
 					=> new AllowedUnitsChecker(
397 397
 						$this->constraintParameterParser,
398 398
 						$this->unitConverter
@@ -407,26 +407,26 @@  discard block
 block discarded – undo
407 407
 	 * @return array[]
408 408
 	 */
409 409
 	public function getConstraintParameterMap() {
410
-		if ( $this->constraintParameterMap === null ) {
410
+		if ($this->constraintParameterMap === null) {
411 411
 			$this->constraintParameterMap = [
412
-				'Commons link' => [ 'namespace' ],
413
-				'Conflicts with' => [ 'property', 'item' ],
414
-				'Diff within range' => [ 'property', 'minimum_quantity', 'maximum_quantity' ],
415
-				'Format' => [ 'pattern' ],
416
-				'Inverse' => [ 'property' ],
417
-				'Item' => [ 'property', 'item' ],
418
-				'Mandatory qualifiers' => [ 'property' ],
412
+				'Commons link' => ['namespace'],
413
+				'Conflicts with' => ['property', 'item'],
414
+				'Diff within range' => ['property', 'minimum_quantity', 'maximum_quantity'],
415
+				'Format' => ['pattern'],
416
+				'Inverse' => ['property'],
417
+				'Item' => ['property', 'item'],
418
+				'Mandatory qualifiers' => ['property'],
419 419
 				'Multi value' => [],
420
-				'One of' => [ 'item' ],
420
+				'One of' => ['item'],
421 421
 				'Qualifier' => [],
422
-				'Qualifiers' => [ 'property' ],
423
-				'Range' => [ 'minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date' ],
422
+				'Qualifiers' => ['property'],
423
+				'Range' => ['minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date'],
424 424
 				'Single value' => [],
425 425
 				'Symmetric' => [],
426
-				'Target required claim' => [ 'property', 'item' ],
427
-				'Type' => [ 'class', 'relation' ],
426
+				'Target required claim' => ['property', 'item'],
427
+				'Type' => ['class', 'relation'],
428 428
 				'Unique value' => [],
429
-				'Value type' => [ 'class', 'relation' ]
429
+				'Value type' => ['class', 'relation']
430 430
 			];
431 431
 		}
432 432
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 	 * @return ConstraintRepository
438 438
 	 */
439 439
 	public function getConstraintRepository() {
440
-		if ( $this->constraintRepository === null ) {
440
+		if ($this->constraintRepository === null) {
441 441
 			$this->constraintRepository = new ConstraintRepository();
442 442
 		}
443 443
 
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/AllowedUnitsChecker.php 1 patch
Spacing   +34 added lines, -35 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 * @throws ConstraintParameterException
76 76
 	 * @return CheckResult
77 77
 	 */
78
-	public function checkConstraint( Context $context, Constraint $constraint ) {
78
+	public function checkConstraint(Context $context, Constraint $constraint) {
79 79
 		$parameters = [];
80 80
 		$constraintParameters = $constraint->getConstraintParameters();
81 81
 		$unitsParameter = $this->constraintParameterParser
@@ -85,50 +85,49 @@  discard block
 block discarded – undo
85 85
 			);
86 86
 
87 87
 		$snak = $context->getSnak();
88
-		if ( !$snak instanceof PropertyValueSnak ) {
88
+		if (!$snak instanceof PropertyValueSnak) {
89 89
 			// nothing to check
90
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
90
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
91 91
 		}
92 92
 
93 93
 		$dataValue = $snak->getDataValue();
94
-		if ( !$dataValue instanceof UnboundedQuantityValue ) {
95
-			$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) )
96
-				->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM )
97
-				->withDataValueType( 'quantity' );
98
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
94
+		if (!$dataValue instanceof UnboundedQuantityValue) {
95
+			$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type'))
96
+				->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM)
97
+				->withDataValueType('quantity');
98
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
99 99
 		}
100 100
 
101
-		if ( $dataValue->getUnit() === '1' ) {
102
-			return $this->checkUnitless( $context, $constraint, $unitsParameter, $snak );
101
+		if ($dataValue->getUnit() === '1') {
102
+			return $this->checkUnitless($context, $constraint, $unitsParameter, $snak);
103 103
 		}
104 104
 
105 105
 		$status = CheckResult::STATUS_VIOLATION;
106
-		$actualUnit = $this->standardize( $dataValue )->getUnit();
107
-		foreach ( $unitsParameter->getUnitQuantities() as $unitQuantity ) {
108
-			$allowedUnit = $this->standardize( $unitQuantity )->getUnit();
109
-			if ( $actualUnit === $allowedUnit ) {
106
+		$actualUnit = $this->standardize($dataValue)->getUnit();
107
+		foreach ($unitsParameter->getUnitQuantities() as $unitQuantity) {
108
+			$allowedUnit = $this->standardize($unitQuantity)->getUnit();
109
+			if ($actualUnit === $allowedUnit) {
110 110
 				$status = CheckResult::STATUS_COMPLIANCE;
111 111
 				break;
112 112
 			}
113 113
 		}
114 114
 
115
-		if ( $status === CheckResult::STATUS_VIOLATION ) {
116
-			if ( $unitsParameter->getUnitItemIds() === [] ) {
117
-				$message = ( new ViolationMessage( 'wbqc-violation-message-units-none' ) )
118
-					->withEntityId( $snak->getPropertyId(), Role::CONSTRAINT_PROPERTY );
115
+		if ($status === CheckResult::STATUS_VIOLATION) {
116
+			if ($unitsParameter->getUnitItemIds() === []) {
117
+				$message = (new ViolationMessage('wbqc-violation-message-units-none'))
118
+					->withEntityId($snak->getPropertyId(), Role::CONSTRAINT_PROPERTY);
119 119
 			} else {
120 120
 				$messageKey = $unitsParameter->getUnitlessAllowed() ?
121
-					'wbqc-violation-message-units-or-none' :
122
-					'wbqc-violation-message-units';
123
-				$message = ( new ViolationMessage( $messageKey ) )
124
-					->withEntityId( $snak->getPropertyId(), Role::CONSTRAINT_PROPERTY )
125
-					->withEntityIdList( $unitsParameter->getUnitItemIds(), Role::CONSTRAINT_PARAMETER_VALUE );
121
+					'wbqc-violation-message-units-or-none' : 'wbqc-violation-message-units';
122
+				$message = (new ViolationMessage($messageKey))
123
+					->withEntityId($snak->getPropertyId(), Role::CONSTRAINT_PROPERTY)
124
+					->withEntityIdList($unitsParameter->getUnitItemIds(), Role::CONSTRAINT_PARAMETER_VALUE);
126 125
 			}
127 126
 		} else {
128 127
 			$message = null;
129 128
 		}
130 129
 
131
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
130
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
132 131
 	}
133 132
 
134 133
 	/**
@@ -144,17 +143,17 @@  discard block
 block discarded – undo
144 143
 		UnitsParameter $unitsParameter,
145 144
 		PropertyValueSnak $snak
146 145
 	) {
147
-		if ( $unitsParameter->getUnitlessAllowed() ) {
146
+		if ($unitsParameter->getUnitlessAllowed()) {
148 147
 			$message = null;
149 148
 			$status = CheckResult::STATUS_COMPLIANCE;
150 149
 		} else {
151
-			$message = ( new ViolationMessage( 'wbqc-violation-message-units' ) )
152
-				->withEntityId( $snak->getPropertyId(), Role::CONSTRAINT_PROPERTY )
153
-				->withEntityIdList( $unitsParameter->getUnitItemIds(), Role::CONSTRAINT_PARAMETER_VALUE );
150
+			$message = (new ViolationMessage('wbqc-violation-message-units'))
151
+				->withEntityId($snak->getPropertyId(), Role::CONSTRAINT_PROPERTY)
152
+				->withEntityIdList($unitsParameter->getUnitItemIds(), Role::CONSTRAINT_PARAMETER_VALUE);
154 153
 			$status = CheckResult::STATUS_VIOLATION;
155 154
 		}
156 155
 
157
-		return new CheckResult( $context, $constraint, [], $status, $message );
156
+		return new CheckResult($context, $constraint, [], $status, $message);
158 157
 	}
159 158
 
160 159
 	/**
@@ -163,20 +162,20 @@  discard block
 block discarded – undo
163 162
 	 * @param UnboundedQuantityValue $value
164 163
 	 * @return UnboundedQuantityValue
165 164
 	 */
166
-	private function standardize( UnboundedQuantityValue $value ) {
167
-		if ( $this->unitConverter === null ) {
165
+	private function standardize(UnboundedQuantityValue $value) {
166
+		if ($this->unitConverter === null) {
168 167
 			return $value;
169 168
 		}
170 169
 
171
-		$standard = $this->unitConverter->toStandardUnits( $value );
172
-		if ( $standard !== null ) {
170
+		$standard = $this->unitConverter->toStandardUnits($value);
171
+		if ($standard !== null) {
173 172
 			return $standard;
174 173
 		} else {
175 174
 			return $value;
176 175
 		}
177 176
 	}
178 177
 
179
-	public function checkConstraintParameters( Constraint $constraint ) {
178
+	public function checkConstraintParameters(Constraint $constraint) {
180 179
 		$constraintParameters = $constraint->getConstraintParameters();
181 180
 		$exceptions = [];
182 181
 		try {
@@ -185,7 +184,7 @@  discard block
 block discarded – undo
185 184
 				$constraint->getConstraintTypeItemId(),
186 185
 				true
187 186
 			);
188
-		} catch ( ConstraintParameterException $e ) {
187
+		} catch (ConstraintParameterException $e) {
189 188
 			$exceptions[] = $e;
190 189
 		}
191 190
 		return $exceptions;
Please login to merge, or discard this patch.