Completed
Push — master ( 0bf068...f61502 )
by
unknown
03:54
created
src/UpdateConstraintsTableJob.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 
27 27
 	const BATCH_SIZE = 10;
28 28
 
29
-	public static function newFromGlobalState( Title $title, array $params ) {
30
-		Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' );
29
+	public static function newFromGlobalState(Title $title, array $params) {
30
+		Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]');
31 31
 		$repo = WikibaseRepo::getDefaultInstance();
32 32
 		return new UpdateConstraintsTableJob(
33 33
 			$title,
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 		EntityLookup $entityLookup,
84 84
 		Serializer $snakSerializer
85 85
 	) {
86
-		parent::__construct( 'constraintsTableUpdate', $title, $params );
86
+		parent::__construct('constraintsTableUpdate', $title, $params);
87 87
 
88 88
 		$this->propertyId = $propertyId;
89 89
 		$this->config = $config;
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
 		$this->snakSerializer = $snakSerializer;
93 93
 	}
94 94
 
95
-	public function extractParametersFromQualifiers( SnakList $qualifiers ) {
95
+	public function extractParametersFromQualifiers(SnakList $qualifiers) {
96 96
 		$parameters = [];
97
-		foreach ( $qualifiers as $qualifier ) {
97
+		foreach ($qualifiers as $qualifier) {
98 98
 			$qualifierId = $qualifier->getPropertyId()->getSerialization();
99
-			$paramSerialization = $this->snakSerializer->serialize( $qualifier );
99
+			$paramSerialization = $this->snakSerializer->serialize($qualifier);
100 100
 			$parameters[$qualifierId][] = $paramSerialization;
101 101
 		}
102 102
 		return $parameters;
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	) {
109 109
 		$constraintId = $constraintStatement->getGuid();
110 110
 		$constraintTypeQid = $constraintStatement->getMainSnak()->getDataValue()->getEntityId()->getSerialization();
111
-		$parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() );
111
+		$parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers());
112 112
 		return new Constraint(
113 113
 			$constraintId,
114 114
 			$propertyId,
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 		PropertyId $propertyConstraintPropertyId
124 124
 	) {
125 125
 		$constraintsStatements = $property->getStatements()
126
-			->getByPropertyId( $propertyConstraintPropertyId )
127
-			->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] );
126
+			->getByPropertyId($propertyConstraintPropertyId)
127
+			->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]);
128 128
 		$constraints = [];
129
-		foreach ( $constraintsStatements->getIterator() as $constraintStatement ) {
130
-			$constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement );
131
-			if ( count( $constraints ) >= self::BATCH_SIZE ) {
132
-				$constraintRepo->insertBatch( $constraints );
129
+		foreach ($constraintsStatements->getIterator() as $constraintStatement) {
130
+			$constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement);
131
+			if (count($constraints) >= self::BATCH_SIZE) {
132
+				$constraintRepo->insertBatch($constraints);
133 133
 				$constraints = [];
134 134
 			}
135 135
 		}
136
-		$constraintRepo->insertBatch( $constraints );
136
+		$constraintRepo->insertBatch($constraints);
137 137
 	}
138 138
 
139 139
 	/**
@@ -144,15 +144,15 @@  discard block
 block discarded – undo
144 144
 	public function run() {
145 145
 		// TODO in the future: only touch constraints affected by the edit (requires T163465)
146 146
 
147
-		$propertyId = new PropertyId( $this->propertyId );
148
-		$this->constraintRepo->deleteForPropertyWhereConstraintIdIsStatementId( $propertyId );
147
+		$propertyId = new PropertyId($this->propertyId);
148
+		$this->constraintRepo->deleteForPropertyWhereConstraintIdIsStatementId($propertyId);
149 149
 
150 150
 		/** @var Property $property */
151
-		$property = $this->entityLookup->getEntity( $propertyId );
151
+		$property = $this->entityLookup->getEntity($propertyId);
152 152
 		$this->importConstraintsForProperty(
153 153
 			$property,
154 154
 			$this->constraintRepo,
155
-			new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) )
155
+			new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId'))
156 156
 		);
157 157
 
158 158
 		return true;
Please login to merge, or discard this patch.
src/Api/CheckingResultsBuilder.php 1 patch
Spacing   +29 added lines, -30 removed lines patch added patch discarded remove patch
@@ -75,54 +75,53 @@  discard block
 block discarded – undo
75 75
 	) {
76 76
 		$response = [];
77 77
 		$metadatas = [];
78
-		$statusesFlipped = array_flip( $statuses );
79
-		foreach ( $entityIds as $entityId ) {
78
+		$statusesFlipped = array_flip($statuses);
79
+		foreach ($entityIds as $entityId) {
80 80
 			$results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnEntityId(
81 81
 				$entityId,
82 82
 				$constraintIds,
83
-				[ $this, 'defaultResults' ]
83
+				[$this, 'defaultResults']
84 84
 			);
85
-			$results = array_filter( $results, $this->statusSelected( $statusesFlipped ) );
86
-			foreach ( $results as $result ) {
85
+			$results = array_filter($results, $this->statusSelected($statusesFlipped));
86
+			foreach ($results as $result) {
87 87
 				$metadatas[] = $result->getMetadata();
88
-				$resultArray = $this->checkResultToArray( $result );
89
-				$result->getContext()->storeCheckResultInArray( $resultArray, $response );
88
+				$resultArray = $this->checkResultToArray($result);
89
+				$result->getContext()->storeCheckResultInArray($resultArray, $response);
90 90
 			}
91 91
 		}
92
-		foreach ( $claimIds as $claimId ) {
92
+		foreach ($claimIds as $claimId) {
93 93
 			$results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnClaimId(
94 94
 				$claimId,
95 95
 				$constraintIds,
96
-				[ $this, 'defaultResults' ]
96
+				[$this, 'defaultResults']
97 97
 			);
98
-			$results = array_filter( $results, $this->statusSelected( $statusesFlipped ) );
99
-			foreach ( $results as $result ) {
98
+			$results = array_filter($results, $this->statusSelected($statusesFlipped));
99
+			foreach ($results as $result) {
100 100
 				$metadatas[] = $result->getMetadata();
101
-				$resultArray = $this->checkResultToArray( $result );
102
-				$result->getContext()->storeCheckResultInArray( $resultArray, $response );
101
+				$resultArray = $this->checkResultToArray($result);
102
+				$result->getContext()->storeCheckResultInArray($resultArray, $response);
103 103
 			}
104 104
 		}
105 105
 		return new CachedCheckConstraintsResponse(
106 106
 			$response,
107
-			Metadata::merge( $metadatas )
107
+			Metadata::merge($metadatas)
108 108
 		);
109 109
 	}
110 110
 
111
-	public function defaultResults( Context $context ) {
111
+	public function defaultResults(Context $context) {
112 112
 		return $context->getType() === Context::TYPE_STATEMENT ?
113
-			[ new NullResult( $context ) ] :
114
-			[];
113
+			[new NullResult($context)] : [];
115 114
 	}
116 115
 
117
-	public function statusSelected( array $statusesFlipped ) {
118
-		return function( CheckResult $result ) use ( $statusesFlipped ) {
119
-			return array_key_exists( $result->getStatus(), $statusesFlipped ) ||
116
+	public function statusSelected(array $statusesFlipped) {
117
+		return function(CheckResult $result) use ($statusesFlipped) {
118
+			return array_key_exists($result->getStatus(), $statusesFlipped) ||
120 119
 				$result instanceof NullResult;
121 120
 		};
122 121
 	}
123 122
 
124
-	public function checkResultToArray( CheckResult $checkResult ) {
125
-		if ( $checkResult instanceof NullResult ) {
123
+	public function checkResultToArray(CheckResult $checkResult) {
124
+		if ($checkResult instanceof NullResult) {
126 125
 			return null;
127 126
 		}
128 127
 
@@ -130,10 +129,10 @@  discard block
 block discarded – undo
130 129
 		$typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId();
131 130
 		$constraintPropertyId = $checkResult->getContext()->getSnak()->getPropertyId();
132 131
 
133
-		$title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId );
134
-		$typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) );
132
+		$title = $this->entityTitleLookup->getTitleForId($constraintPropertyId);
133
+		$typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId));
135 134
 		// TODO link to the statement when possible (T169224)
136
-		$link = $title->getFullURL() . '#' . $this->config->get( 'WBQualityConstraintsPropertyConstraintId' );
135
+		$link = $title->getFullURL().'#'.$this->config->get('WBQualityConstraintsPropertyConstraintId');
137 136
 
138 137
 		$constraint = [
139 138
 			'id' => $constraintId,
@@ -142,11 +141,11 @@  discard block
 block discarded – undo
142 141
 			'link' => $link,
143 142
 			'discussLink' => $title->getTalkPage()->getFullURL(),
144 143
 		];
145
-		if ( $this->config->get( 'WBQualityConstraintsIncludeDetailInApi' ) ) {
144
+		if ($this->config->get('WBQualityConstraintsIncludeDetailInApi')) {
146 145
 			$parameters = $checkResult->getParameters();
147 146
 			$constraint += [
148 147
 				'detail' => $parameters,
149
-				'detailHTML' => $this->constraintParameterRenderer->formatParameters( $parameters ),
148
+				'detailHTML' => $this->constraintParameterRenderer->formatParameters($parameters),
150 149
 			];
151 150
 		}
152 151
 
@@ -156,14 +155,14 @@  discard block
 block discarded – undo
156 155
 			'constraint' => $constraint
157 156
 		];
158 157
 		$message = $checkResult->getMessage();
159
-		if ( $message ) {
158
+		if ($message) {
160 159
 			$result['message-html'] = $message;
161 160
 		}
162
-		if ( $checkResult->getContext()->getType() === Context::TYPE_STATEMENT ) {
161
+		if ($checkResult->getContext()->getType() === Context::TYPE_STATEMENT) {
163 162
 			$result['claim'] = $checkResult->getContext()->getSnakStatement()->getGuid();
164 163
 		}
165 164
 		$cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray();
166
-		if ( $cachingMetadataArray !== null ) {
165
+		if ($cachingMetadataArray !== null) {
167 166
 			$result['cached'] = $cachingMetadataArray;
168 167
 		}
169 168
 
Please login to merge, or discard this patch.
src/Api/CachingResultsBuilder.php 1 patch
Spacing   +50 added lines, -51 removed lines patch added patch discarded remove patch
@@ -134,11 +134,11 @@  discard block
 block discarded – undo
134 134
 	) {
135 135
 		$results = [];
136 136
 		$metadatas = [];
137
-		if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) {
137
+		if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) {
138 138
 			$storedEntityIds = [];
139
-			foreach ( $entityIds as $entityId ) {
140
-				$storedResults = $this->getStoredResults( $entityId );
141
-				if ( $storedResults !== null ) {
139
+			foreach ($entityIds as $entityId) {
140
+				$storedResults = $this->getStoredResults($entityId);
141
+				if ($storedResults !== null) {
142 142
 					$this->dataFactory->increment(
143 143
 						'wikibase.quality.constraints.cache.entity.hit'
144 144
 					);
@@ -147,20 +147,20 @@  discard block
 block discarded – undo
147 147
 					$storedEntityIds[] = $entityId;
148 148
 				}
149 149
 			}
150
-			$entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) );
150
+			$entityIds = array_values(array_diff($entityIds, $storedEntityIds));
151 151
 		}
152
-		if ( $entityIds !== [] || $claimIds !== [] ) {
152
+		if ($entityIds !== [] || $claimIds !== []) {
153 153
 			$this->dataFactory->updateCount(
154 154
 				'wikibase.quality.constraints.cache.entity.miss',
155
-				count( $entityIds )
155
+				count($entityIds)
156 156
 			);
157
-			$response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses );
157
+			$response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses);
158 158
 			$results += $response->getArray();
159 159
 			$metadatas[] = $response->getMetadata();
160 160
 		}
161 161
 		return new CachedCheckConstraintsResponse(
162 162
 			$results,
163
-			Metadata::merge( $metadatas )
163
+			Metadata::merge($metadatas)
164 164
 		);
165 165
 	}
166 166
 
@@ -189,13 +189,13 @@  discard block
 block discarded – undo
189 189
 		array $constraintIds = null,
190 190
 		array $statuses
191 191
 	) {
192
-		if ( $claimIds !== [] ) {
192
+		if ($claimIds !== []) {
193 193
 			return false;
194 194
 		}
195
-		if ( $constraintIds !== null ) {
195
+		if ($constraintIds !== null) {
196 196
 			return false;
197 197
 		}
198
-		if ( $statuses != $this->cachedStatuses ) {
198
+		if ($statuses != $this->cachedStatuses) {
199 199
 			return false;
200 200
 		}
201 201
 		return true;
@@ -214,17 +214,17 @@  discard block
 block discarded – undo
214 214
 		array $constraintIds = null,
215 215
 		array $statuses
216 216
 	) {
217
-		$results = $this->resultsBuilder->getResults( $entityIds, $claimIds, $constraintIds, $statuses );
217
+		$results = $this->resultsBuilder->getResults($entityIds, $claimIds, $constraintIds, $statuses);
218 218
 
219
-		if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) {
220
-			foreach ( $entityIds as $entityId ) {
219
+		if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) {
220
+			foreach ($entityIds as $entityId) {
221 221
 				$value = [
222 222
 					'results' => $results->getArray()[$entityId->getSerialization()],
223 223
 					'latestRevisionIds' => $this->getLatestRevisionIds(
224 224
 						$results->getMetadata()->getDependencyMetadata()->getEntityIds()
225 225
 					),
226 226
 				];
227
-				$this->cache->set( $entityId, $value, $this->ttlInSeconds );
227
+				$this->cache->set($entityId, $value, $this->ttlInSeconds);
228 228
 			}
229 229
 		}
230 230
 
@@ -256,10 +256,10 @@  discard block
 block discarded – undo
256 256
 		array $constraintIds = null,
257 257
 		array $statuses
258 258
 	) {
259
-		if ( $constraintIds !== null ) {
259
+		if ($constraintIds !== null) {
260 260
 			return false;
261 261
 		}
262
-		if ( $statuses != $this->cachedStatuses ) {
262
+		if ($statuses != $this->cachedStatuses) {
263 263
 			return false;
264 264
 		}
265 265
 		return true;
@@ -272,45 +272,44 @@  discard block
 block discarded – undo
272 272
 	public function getStoredResults(
273 273
 		EntityId $entityId
274 274
 	) {
275
-		$value = $this->cache->get( $entityId, $curTTL, [], $asOf );
276
-		$now = call_user_func( $this->microtime, true );
275
+		$value = $this->cache->get($entityId, $curTTL, [], $asOf);
276
+		$now = call_user_func($this->microtime, true);
277 277
 
278
-		if ( $value === false ) {
278
+		if ($value === false) {
279 279
 			return null;
280 280
 		}
281 281
 
282
-		$ageInSeconds = (int)ceil( $now - $asOf );
282
+		$ageInSeconds = (int) ceil($now - $asOf);
283 283
 
284 284
 		$dependedEntityIds = array_map(
285
-			[ $this->entityIdParser, "parse" ],
286
-			array_keys( $value['latestRevisionIds'] )
285
+			[$this->entityIdParser, "parse"],
286
+			array_keys($value['latestRevisionIds'])
287 287
 		);
288 288
 
289
-		if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) {
289
+		if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) {
290 290
 			return null;
291 291
 		}
292 292
 
293 293
 		$cachingMetadata = $ageInSeconds > 0 ?
294
-			CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) :
295
-			CachingMetadata::fresh();
294
+			CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh();
296 295
 
297
-		if ( is_array( $value['results'] ) ) {
298
-			array_walk( $value['results'], [ $this, 'updateCachingMetadata' ], $cachingMetadata );
296
+		if (is_array($value['results'])) {
297
+			array_walk($value['results'], [$this, 'updateCachingMetadata'], $cachingMetadata);
299 298
 		}
300 299
 
301 300
 		return new CachedCheckConstraintsResponse(
302
-			[ $entityId->getSerialization() => $value['results'] ],
301
+			[$entityId->getSerialization() => $value['results']],
303 302
 			array_reduce(
304 303
 				$dependedEntityIds,
305
-				function( Metadata $metadata, EntityId $entityId ) {
306
-					return Metadata::merge( [
304
+				function(Metadata $metadata, EntityId $entityId) {
305
+					return Metadata::merge([
307 306
 						$metadata,
308 307
 						Metadata::ofDependencyMetadata(
309
-							DependencyMetadata::ofEntityId( $entityId )
308
+							DependencyMetadata::ofEntityId($entityId)
310 309
 						)
311
-					] );
310
+					]);
312 311
 				},
313
-				Metadata::ofCachingMetadata( $cachingMetadata )
312
+				Metadata::ofCachingMetadata($cachingMetadata)
314 313
 			)
315 314
 		);
316 315
 	}
@@ -319,39 +318,39 @@  discard block
 block discarded – undo
319 318
 	 * @param EntityId[] $entityIds
320 319
 	 * @return int[]
321 320
 	 */
322
-	private function getLatestRevisionIds( array $entityIds ) {
321
+	private function getLatestRevisionIds(array $entityIds) {
323 322
 		$revisionInformations = $this->wikiPageEntityMetaDataAccessor->loadRevisionInformation(
324 323
 			$entityIds,
325 324
 			EntityRevisionLookup::LATEST_FROM_REPLICA
326 325
 		);
327 326
 		$latestRevisionIds = [];
328
-		foreach ( $revisionInformations as $serialization => $revisionInformation ) {
327
+		foreach ($revisionInformations as $serialization => $revisionInformation) {
329 328
 			$latestRevisionIds[$serialization] = $revisionInformation->page_latest;
330 329
 		}
331 330
 		return $latestRevisionIds;
332 331
 	}
333 332
 
334
-	public function updateCachingMetadata( &$element, $key, CachingMetadata $cachingMetadata ) {
335
-		if ( $key === 'cached' ) {
336
-			$element = CachingMetadata::merge( [
333
+	public function updateCachingMetadata(&$element, $key, CachingMetadata $cachingMetadata) {
334
+		if ($key === 'cached') {
335
+			$element = CachingMetadata::merge([
337 336
 				$cachingMetadata,
338
-				CachingMetadata::ofArray( $element ),
339
-			] )->toArray();
337
+				CachingMetadata::ofArray($element),
338
+			])->toArray();
340 339
 		}
341 340
 		if (
342
-			is_array( $element ) &&
343
-			array_key_exists( 'constraint', $element ) &&
344
-			in_array( $element['constraint']['type'], $this->possiblyStaleConstraintTypes, true )
341
+			is_array($element) &&
342
+			array_key_exists('constraint', $element) &&
343
+			in_array($element['constraint']['type'], $this->possiblyStaleConstraintTypes, true)
345 344
 		) {
346
-			$element['cached'] = CachingMetadata::merge( [
345
+			$element['cached'] = CachingMetadata::merge([
347 346
 				$cachingMetadata,
348 347
 				CachingMetadata::ofArray(
349
-					array_key_exists( 'cached', $element ) ? $element['cached'] : null
348
+					array_key_exists('cached', $element) ? $element['cached'] : null
350 349
 				),
351
-			] )->toArray();
350
+			])->toArray();
352 351
 		}
353
-		if ( is_array( $element ) ) {
354
-			array_walk( $element, [ $this, __FUNCTION__ ], $cachingMetadata );
352
+		if (is_array($element)) {
353
+			array_walk($element, [$this, __FUNCTION__], $cachingMetadata);
355 354
 		}
356 355
 	}
357 356
 
@@ -360,7 +359,7 @@  discard block
 block discarded – undo
360 359
 	 *
361 360
 	 * @param callable $microtime
362 361
 	 */
363
-	public function setMicrotimeFunction( callable $microtime ) {
362
+	public function setMicrotimeFunction(callable $microtime) {
364 363
 		$this->microtime = $microtime;
365 364
 	}
366 365
 
Please login to merge, or discard this patch.
src/Api/CheckConstraints.php 1 patch
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -76,21 +76,21 @@  discard block
 block discarded – undo
76 76
 	 *
77 77
 	 * @return self
78 78
 	 */
79
-	public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) {
79
+	public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') {
80 80
 		$repo = WikibaseRepo::getDefaultInstance();
81 81
 
82 82
 		$language = $repo->getUserLanguage();
83 83
 		$formatterOptions = new FormatterOptions();
84
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
84
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
85 85
 		$valueFormatterFactory = $repo->getValueFormatterFactory();
86
-		$valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
86
+		$valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
87 87
 
88 88
 		$languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory();
89
-		$labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language );
89
+		$labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language);
90 90
 		$entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory();
91
-		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup );
91
+		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup);
92 92
 		$entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory();
93
-		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup );
93
+		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup);
94 94
 		$config = MediaWikiServices::getInstance()->getMainConfig();
95 95
 		$titleParser = MediaWikiServices::getInstance()->getTitleParser();
96 96
 		$unitConverter = $repo->getUnitConverter();
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 			$constraintParameterRenderer,
126 126
 			$config
127 127
 		);
128
-		if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) {
128
+		if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) {
129 129
 			$wikiPageEntityMetaDataAccessor = new WikiPageEntityMetaDataLookup(
130 130
 				$repo->getEntityNamespaceLookup()
131 131
 			);
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
 				ResultsCache::getDefaultInstance(),
137 137
 				$wikiPageEntityMetaDataAccessor,
138 138
 				$entityIdParser,
139
-				$config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ),
139
+				$config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'),
140 140
 				[
141
-					$config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ),
142
-					$config->get( 'WBQualityConstraintsTypeConstraintId' ),
143
-					$config->get( 'WBQualityConstraintsValueTypeConstraintId' ),
144
-					$config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ),
141
+					$config->get('WBQualityConstraintsCommonsLinkConstraintId'),
142
+					$config->get('WBQualityConstraintsTypeConstraintId'),
143
+					$config->get('WBQualityConstraintsValueTypeConstraintId'),
144
+					$config->get('WBQualityConstraintsDistinctValuesConstraintId'),
145 145
 				],
146 146
 				$dataFactory
147 147
 			);
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 			$prefix,
154 154
 			$repo->getEntityIdParser(),
155 155
 			$repo->getStatementGuidValidator(),
156
-			$repo->getApiHelperFactory( RequestContext::getMain() ),
156
+			$repo->getApiHelperFactory(RequestContext::getMain()),
157 157
 			$resultsBuilder,
158 158
 			$dataFactory
159 159
 		);
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 		ResultsBuilder $resultsBuilder,
180 180
 		IBufferingStatsdDataFactory $dataFactory
181 181
 	) {
182
-		parent::__construct( $main, $name, $prefix );
182
+		parent::__construct($main, $name, $prefix);
183 183
 		$this->entityIdParser = $entityIdParser;
184 184
 		$this->statementGuidValidator = $statementGuidValidator;
185
-		$this->resultBuilder = $apiHelperFactory->getResultBuilder( $this );
186
-		$this->errorReporter = $apiHelperFactory->getErrorReporter( $this );
185
+		$this->resultBuilder = $apiHelperFactory->getResultBuilder($this);
186
+		$this->errorReporter = $apiHelperFactory->getErrorReporter($this);
187 187
 		$this->resultsBuilder = $resultsBuilder;
188 188
 		$this->dataFactory = $dataFactory;
189 189
 	}
@@ -198,9 +198,9 @@  discard block
 block discarded – undo
198 198
 
199 199
 		$params = $this->extractRequestParams();
200 200
 
201
-		$this->validateParameters( $params );
202
-		$entityIds = $this->parseEntityIds( $params );
203
-		$claimIds = $this->parseClaimIds( $params );
201
+		$this->validateParameters($params);
202
+		$entityIds = $this->parseEntityIds($params);
203
+		$claimIds = $this->parseClaimIds($params);
204 204
 		$constraintIDs = $params[self::PARAM_CONSTRAINT_ID];
205 205
 		$statuses = $params[self::PARAM_STATUS];
206 206
 
@@ -215,13 +215,13 @@  discard block
 block discarded – undo
215 215
 			)->getArray()
216 216
 		);
217 217
 		// ensure that result contains the given entity IDs even if they have no statements
218
-		foreach ( $entityIds as $entityId ) {
218
+		foreach ($entityIds as $entityId) {
219 219
 			$this->getResult()->addArrayType(
220
-				[ $this->getModuleName(), $entityId->getSerialization() ],
220
+				[$this->getModuleName(), $entityId->getSerialization()],
221 221
 				'assoc'
222 222
 			);
223 223
 		}
224
-		$this->resultBuilder->markSuccess( 1 );
224
+		$this->resultBuilder->markSuccess(1);
225 225
 	}
226 226
 
227 227
 	/**
@@ -229,24 +229,24 @@  discard block
 block discarded – undo
229 229
 	 *
230 230
 	 * @return EntityId[]
231 231
 	 */
232
-	private function parseEntityIds( array $params ) {
232
+	private function parseEntityIds(array $params) {
233 233
 		$ids = $params[self::PARAM_ID];
234 234
 
235
-		if ( $ids === null ) {
235
+		if ($ids === null) {
236 236
 			return [];
237
-		} elseif ( $ids === [] ) {
237
+		} elseif ($ids === []) {
238 238
 			$this->errorReporter->dieError(
239
-				'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' );
239
+				'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' );
240 240
 		}
241 241
 
242
-		return array_map( function ( $id ) {
242
+		return array_map(function($id) {
243 243
 			try {
244
-				return $this->entityIdParser->parse( $id );
245
-			} catch ( EntityIdParsingException $e ) {
244
+				return $this->entityIdParser->parse($id);
245
+			} catch (EntityIdParsingException $e) {
246 246
 				$this->errorReporter->dieError(
247
-					"Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] );
247
+					"Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] );
248 248
 			}
249
-		}, $ids );
249
+		}, $ids);
250 250
 	}
251 251
 
252 252
 	/**
@@ -254,35 +254,35 @@  discard block
 block discarded – undo
254 254
 	 *
255 255
 	 * @return string[]
256 256
 	 */
257
-	private function parseClaimIds( array $params ) {
257
+	private function parseClaimIds(array $params) {
258 258
 		$ids = $params[self::PARAM_CLAIM_ID];
259 259
 
260
-		if ( $ids === null ) {
260
+		if ($ids === null) {
261 261
 			return [];
262
-		} elseif ( $ids === [] ) {
262
+		} elseif ($ids === []) {
263 263
 			$this->errorReporter->dieError(
264
-				'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' );
264
+				'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' );
265 265
 		}
266 266
 
267
-		foreach ( $ids as $id ) {
268
-			if ( !$this->statementGuidValidator->validate( $id ) ) {
267
+		foreach ($ids as $id) {
268
+			if (!$this->statementGuidValidator->validate($id)) {
269 269
 				$this->errorReporter->dieError(
270
-					"Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] );
270
+					"Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] );
271 271
 			}
272 272
 		}
273 273
 
274 274
 		return $ids;
275 275
 	}
276 276
 
277
-	private function validateParameters( array $params ) {
278
-		if ( $params[self::PARAM_CONSTRAINT_ID] !== null
279
-			 && empty( $params[self::PARAM_CONSTRAINT_ID] )
277
+	private function validateParameters(array $params) {
278
+		if ($params[self::PARAM_CONSTRAINT_ID] !== null
279
+			 && empty($params[self::PARAM_CONSTRAINT_ID])
280 280
 		) {
281 281
 			$paramConstraintId = self::PARAM_CONSTRAINT_ID;
282 282
 			$this->errorReporter->dieError(
283 283
 				"If $paramConstraintId is specified, it must be nonempty.", 'no-data' );
284 284
 		}
285
-		if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) {
285
+		if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) {
286 286
 			$paramId = self::PARAM_ID;
287 287
 			$paramClaimId = self::PARAM_CLAIM_ID;
288 288
 			$this->errorReporter->dieError(
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/ValueTypeChecker.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -104,37 +104,37 @@  discard block
 block discarded – undo
104 104
 	 * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs
105 105
 	 * @return CheckResult
106 106
 	 */
107
-	public function checkConstraint( Context $context, Constraint $constraint ) {
108
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
109
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
107
+	public function checkConstraint(Context $context, Constraint $constraint) {
108
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
109
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
110 110
 		}
111 111
 
112 112
 		$parameters = [];
113 113
 		$constraintParameters = $constraint->getConstraintParameters();
114 114
 
115
-		$classes = $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
115
+		$classes = $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId());
116 116
 		$parameters['class'] = array_map(
117
-			function( $id ) {
118
-				return new ItemId( $id );
117
+			function($id) {
118
+				return new ItemId($id);
119 119
 			},
120 120
 			$classes
121 121
 		);
122 122
 
123
-		$relation = $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
123
+		$relation = $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId());
124 124
 		$relationIds = [];
125
-		if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) {
126
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' );
125
+		if ($relation === 'instance' || $relation === 'instanceOrSubclass') {
126
+			$relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId');
127 127
 		}
128
-		if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) {
129
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
128
+		if ($relation === 'subclass' || $relation === 'instanceOrSubclass') {
129
+			$relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId');
130 130
 		}
131
-		$parameters['relation'] = [ $relation ];
131
+		$parameters['relation'] = [$relation];
132 132
 
133 133
 		$snak = $context->getSnak();
134 134
 
135
-		if ( !$snak instanceof PropertyValueSnak ) {
135
+		if (!$snak instanceof PropertyValueSnak) {
136 136
 			// nothing to check
137
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' );
137
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '');
138 138
 		}
139 139
 
140 140
 		$dataValue = $snak->getDataValue();
@@ -143,22 +143,22 @@  discard block
 block discarded – undo
143 143
 		 * error handling:
144 144
 		 *   type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid'
145 145
 		 */
146
-		if ( $dataValue->getType() !== 'wikibase-entityid' ) {
147
-			$message = wfMessage( "wbqc-violation-message-value-needed-of-type" )
146
+		if ($dataValue->getType() !== 'wikibase-entityid') {
147
+			$message = wfMessage("wbqc-violation-message-value-needed-of-type")
148 148
 				->rawParams(
149
-					$this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ),
149
+					$this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM),
150 150
 					'wikibase-entityid' // TODO is there a message for this type so we can localize it?
151 151
 				)
152 152
 				->escaped();
153
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
153
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
154 154
 		}
155 155
 		/** @var EntityIdValue $dataValue */
156 156
 
157
-		$item = $this->entityLookup->getEntity( $dataValue->getEntityId() );
157
+		$item = $this->entityLookup->getEntity($dataValue->getEntityId());
158 158
 
159
-		if ( !( $item instanceof StatementListProvider ) ) {
160
-			$message = wfMessage( "wbqc-violation-message-value-entity-must-exist" )->escaped();
161
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
159
+		if (!($item instanceof StatementListProvider)) {
160
+			$message = wfMessage("wbqc-violation-message-value-entity-must-exist")->escaped();
161
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
162 162
 		}
163 163
 
164 164
 		$statements = $item->getStatements();
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 			$classes
170 170
 		);
171 171
 
172
-		if ( $result->getBool() ) {
172
+		if ($result->getBool()) {
173 173
 			$message = '';
174 174
 			$status = CheckResult::STATUS_COMPLIANCE;
175 175
 		} else {
@@ -183,21 +183,21 @@  discard block
 block discarded – undo
183 183
 			$status = CheckResult::STATUS_VIOLATION;
184 184
 		}
185 185
 
186
-		return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) )
187
-			->withMetadata( $result->getMetadata() );
186
+		return (new CheckResult($context, $constraint, $parameters, $status, $message))
187
+			->withMetadata($result->getMetadata());
188 188
 	}
189 189
 
190
-	public function checkConstraintParameters( Constraint $constraint ) {
190
+	public function checkConstraintParameters(Constraint $constraint) {
191 191
 		$constraintParameters = $constraint->getConstraintParameters();
192 192
 		$exceptions = [];
193 193
 		try {
194
-			$this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
195
-		} catch ( ConstraintParameterException $e ) {
194
+			$this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId());
195
+		} catch (ConstraintParameterException $e) {
196 196
 			$exceptions[] = $e;
197 197
 		}
198 198
 		try {
199
-			$this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
200
-		} catch ( ConstraintParameterException $e ) {
199
+			$this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId());
200
+		} catch (ConstraintParameterException $e) {
201 201
 			$exceptions[] = $e;
202 202
 		}
203 203
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/TypeChecker.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -89,34 +89,34 @@  discard block
 block discarded – undo
89 89
 	 * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs
90 90
 	 * @return CheckResult
91 91
 	 */
92
-	public function checkConstraint( Context $context, Constraint $constraint ) {
93
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
94
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
92
+	public function checkConstraint(Context $context, Constraint $constraint) {
93
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
94
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
95 95
 		}
96
-		if ( $context->getType() === Context::TYPE_REFERENCE ) {
97
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE );
96
+		if ($context->getType() === Context::TYPE_REFERENCE) {
97
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE);
98 98
 		}
99 99
 
100 100
 		$parameters = [];
101 101
 		$constraintParameters = $constraint->getConstraintParameters();
102 102
 
103
-		$classes = $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
103
+		$classes = $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId());
104 104
 		$parameters['class'] = array_map(
105
-			function( $id ) {
106
-				return new ItemId( $id );
105
+			function($id) {
106
+				return new ItemId($id);
107 107
 			},
108 108
 			$classes
109 109
 		);
110 110
 
111
-		$relation = $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
111
+		$relation = $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId());
112 112
 		$relationIds = [];
113
-		if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) {
114
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' );
113
+		if ($relation === 'instance' || $relation === 'instanceOrSubclass') {
114
+			$relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId');
115 115
 		}
116
-		if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) {
117
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
116
+		if ($relation === 'subclass' || $relation === 'instanceOrSubclass') {
117
+			$relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId');
118 118
 		}
119
-		$parameters['relation'] = [ $relation ];
119
+		$parameters['relation'] = [$relation];
120 120
 
121 121
 		$result = $this->typeCheckerHelper->hasClassInRelation(
122 122
 			$context->getEntity()->getStatements(),
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 			$classes
125 125
 		);
126 126
 
127
-		if ( $result->getBool() ) {
127
+		if ($result->getBool()) {
128 128
 			$message = '';
129 129
 			$status = CheckResult::STATUS_COMPLIANCE;
130 130
 		} else {
@@ -138,21 +138,21 @@  discard block
 block discarded – undo
138 138
 			$status = CheckResult::STATUS_VIOLATION;
139 139
 		}
140 140
 
141
-		return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) )
142
-			->withMetadata( $result->getMetadata() );
141
+		return (new CheckResult($context, $constraint, $parameters, $status, $message))
142
+			->withMetadata($result->getMetadata());
143 143
 	}
144 144
 
145
-	public function checkConstraintParameters( Constraint $constraint ) {
145
+	public function checkConstraintParameters(Constraint $constraint) {
146 146
 		$constraintParameters = $constraint->getConstraintParameters();
147 147
 		$exceptions = [];
148 148
 		try {
149
-			$this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
150
-		} catch ( ConstraintParameterException $e ) {
149
+			$this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId());
150
+		} catch (ConstraintParameterException $e) {
151 151
 			$exceptions[] = $e;
152 152
 		}
153 153
 		try {
154
-			$this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
155
-		} catch ( ConstraintParameterException $e ) {
154
+			$this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId());
155
+		} catch (ConstraintParameterException $e) {
156 156
 			$exceptions[] = $e;
157 157
 		}
158 158
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/ConstraintParameterParser.php 1 patch
Spacing   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
 	 * @param array $parameters
78 78
 	 * @throws ConstraintParameterException
79 79
 	 */
80
-	public function checkError( array $parameters ) {
81
-		if ( array_key_exists( '@error', $parameters ) ) {
80
+	public function checkError(array $parameters) {
81
+		if (array_key_exists('@error', $parameters)) {
82 82
 			$error = $parameters['@error'];
83
-			if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) {
83
+			if (array_key_exists('toolong', $error) && $error['toolong']) {
84 84
 				$msg = 'wbqc-violation-message-parameters-error-toolong';
85 85
 			} else {
86 86
 				$msg = 'wbqc-violation-message-parameters-error-unknown';
87 87
 			}
88
-			throw new ConstraintParameterException( wfMessage( $msg )->escaped() );
88
+			throw new ConstraintParameterException(wfMessage($msg)->escaped());
89 89
 		}
90 90
 	}
91 91
 
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
 	 * @param string $parameterId
96 96
 	 * @throws ConstraintParameterException
97 97
 	 */
98
-	private function requireSingleParameter( array $parameters, $parameterId ) {
99
-		if ( count( $parameters[$parameterId] ) !== 1 ) {
98
+	private function requireSingleParameter(array $parameters, $parameterId) {
99
+		if (count($parameters[$parameterId]) !== 1) {
100 100
 			throw new ConstraintParameterException(
101
-				wfMessage( 'wbqc-violation-message-parameter-single' )
102
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
101
+				wfMessage('wbqc-violation-message-parameter-single')
102
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY))
103 103
 					->escaped()
104 104
 			);
105 105
 		}
@@ -112,11 +112,11 @@  discard block
 block discarded – undo
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
-				wfMessage( 'wbqc-violation-message-parameter-value' )
119
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
118
+				wfMessage('wbqc-violation-message-parameter-value')
119
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY))
120 120
 					->escaped()
121 121
 			);
122 122
 		}
@@ -129,18 +129,18 @@  discard block
 block discarded – undo
129 129
 	 * @throws ConstraintParameterException
130 130
 	 * @return EntityId
131 131
 	 */
132
-	private function parseEntityIdParameter( array $snakSerialization, $parameterId ) {
133
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
134
-		$this->requireValueParameter( $snak, $parameterId );
132
+	private function parseEntityIdParameter(array $snakSerialization, $parameterId) {
133
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
134
+		$this->requireValueParameter($snak, $parameterId);
135 135
 		$value = $snak->getDataValue();
136
-		if ( $value instanceof EntityIdValue ) {
136
+		if ($value instanceof EntityIdValue) {
137 137
 			return $value->getEntityId();
138 138
 		} else {
139 139
 			throw new ConstraintParameterException(
140
-				wfMessage( 'wbqc-violation-message-parameter-entity' )
140
+				wfMessage('wbqc-violation-message-parameter-entity')
141 141
 					->rawParams(
142
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
143
-						$this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
142
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
143
+						$this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
144 144
 					)
145 145
 					->escaped()
146 146
 			);
@@ -153,21 +153,21 @@  discard block
 block discarded – undo
153 153
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
154 154
 	 * @return string[] class entity ID serializations
155 155
 	 */
156
-	public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) {
157
-		$this->checkError( $constraintParameters );
158
-		$classId = $this->config->get( 'WBQualityConstraintsClassId' );
159
-		if ( !array_key_exists( $classId, $constraintParameters ) ) {
156
+	public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) {
157
+		$this->checkError($constraintParameters);
158
+		$classId = $this->config->get('WBQualityConstraintsClassId');
159
+		if (!array_key_exists($classId, $constraintParameters)) {
160 160
 			throw new ConstraintParameterException(
161
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
162
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
163
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $classId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
161
+				wfMessage('wbqc-violation-message-parameter-needed')
162
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
163
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($classId, Role::CONSTRAINT_PARAMETER_PROPERTY))
164 164
 					->escaped()
165 165
 			);
166 166
 		}
167 167
 
168 168
 		$classes = [];
169
-		foreach ( $constraintParameters[$classId] as $class ) {
170
-			$classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization();
169
+		foreach ($constraintParameters[$classId] as $class) {
170
+			$classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization();
171 171
 		}
172 172
 		return $classes;
173 173
 	}
@@ -178,24 +178,24 @@  discard block
 block discarded – undo
178 178
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
179 179
 	 * @return string 'instance', 'subclass', or 'instanceOrSubclass'
180 180
 	 */
181
-	public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) {
182
-		$this->checkError( $constraintParameters );
183
-		$relationId = $this->config->get( 'WBQualityConstraintsRelationId' );
184
-		if ( !array_key_exists( $relationId, $constraintParameters ) ) {
181
+	public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) {
182
+		$this->checkError($constraintParameters);
183
+		$relationId = $this->config->get('WBQualityConstraintsRelationId');
184
+		if (!array_key_exists($relationId, $constraintParameters)) {
185 185
 			throw new ConstraintParameterException(
186
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
187
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
188
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
186
+				wfMessage('wbqc-violation-message-parameter-needed')
187
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
188
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY))
189 189
 					->escaped()
190 190
 			);
191 191
 		}
192 192
 
193
-		$this->requireSingleParameter( $constraintParameters, $relationId );
194
-		$relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId );
195
-		$instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' );
196
-		$subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' );
197
-		$instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' );
198
-		switch ( $relationEntityId ) {
193
+		$this->requireSingleParameter($constraintParameters, $relationId);
194
+		$relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId);
195
+		$instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId');
196
+		$subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId');
197
+		$instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId');
198
+		switch ($relationEntityId) {
199 199
 			case $instanceId:
200 200
 				return 'instance';
201 201
 			case $subclassId:
@@ -204,13 +204,13 @@  discard block
 block discarded – undo
204 204
 				return 'instanceOrSubclass';
205 205
 			default:
206 206
 				throw new ConstraintParameterException(
207
-					wfMessage( 'wbqc-violation-message-parameter-oneof' )
208
-						->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
209
-						->numParams( 3 )
210
-						->rawParams( $this->constraintParameterRenderer->formatItemIdList(
211
-							[ $instanceId, $subclassId, $instanceOrSubclassId ],
207
+					wfMessage('wbqc-violation-message-parameter-oneof')
208
+						->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY))
209
+						->numParams(3)
210
+						->rawParams($this->constraintParameterRenderer->formatItemIdList(
211
+							[$instanceId, $subclassId, $instanceOrSubclassId],
212 212
 							Role::CONSTRAINT_PARAMETER_VALUE
213
-						) )
213
+						))
214 214
 						->escaped()
215 215
 				);
216 216
 		}
@@ -223,21 +223,21 @@  discard block
 block discarded – undo
223 223
 	 * @throws ConstraintParameterException
224 224
 	 * @return PropertyId
225 225
 	 */
226
-	private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) {
227
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
228
-		$this->requireValueParameter( $snak, $parameterId );
226
+	private function parsePropertyIdParameter(array $snakSerialization, $parameterId) {
227
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
228
+		$this->requireValueParameter($snak, $parameterId);
229 229
 		$value = $snak->getDataValue();
230
-		if ( $value instanceof EntityIdValue ) {
230
+		if ($value instanceof EntityIdValue) {
231 231
 			$id = $value->getEntityId();
232
-			if ( $id instanceof PropertyId ) {
232
+			if ($id instanceof PropertyId) {
233 233
 				return $id;
234 234
 			}
235 235
 		}
236 236
 		throw new ConstraintParameterException(
237
-			wfMessage( 'wbqc-violation-message-parameter-property' )
237
+			wfMessage('wbqc-violation-message-parameter-property')
238 238
 				->rawParams(
239
-					$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
240
-					$this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
239
+					$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
240
+					$this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
241 241
 				)
242 242
 				->escaped()
243 243
 		);
@@ -250,34 +250,34 @@  discard block
 block discarded – undo
250 250
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
251 251
 	 * @return PropertyId
252 252
 	 */
253
-	public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) {
254
-		$this->checkError( $constraintParameters );
255
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
256
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
253
+	public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) {
254
+		$this->checkError($constraintParameters);
255
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
256
+		if (!array_key_exists($propertyId, $constraintParameters)) {
257 257
 			throw new ConstraintParameterException(
258
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
259
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
260
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
258
+				wfMessage('wbqc-violation-message-parameter-needed')
259
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
260
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY))
261 261
 					->escaped()
262 262
 			);
263 263
 		}
264 264
 
265
-		$this->requireSingleParameter( $constraintParameters, $propertyId );
266
-		return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId );
265
+		$this->requireSingleParameter($constraintParameters, $propertyId);
266
+		return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId);
267 267
 	}
268 268
 
269
-	private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) {
269
+	private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) {
270 270
 		$dataValue = $snak->getDataValue();
271
-		if ( $dataValue instanceof EntityIdValue &&
271
+		if ($dataValue instanceof EntityIdValue &&
272 272
 			$dataValue->getEntityId() instanceof ItemId
273 273
 		) {
274
-			return ItemIdSnakValue::fromItemId( $dataValue->getEntityId() );
274
+			return ItemIdSnakValue::fromItemId($dataValue->getEntityId());
275 275
 		} else {
276 276
 			throw new ConstraintParameterException(
277
-				wfMessage( 'wbqc-violation-message-parameter-item' )
277
+				wfMessage('wbqc-violation-message-parameter-item')
278 278
 					->rawParams(
279
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
280
-						$this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
279
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
280
+						$this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
281 281
 					)
282 282
 					->escaped()
283 283
 			);
@@ -291,15 +291,15 @@  discard block
 block discarded – undo
291 291
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
292 292
 	 * @return ItemIdSnakValue[] array of values
293 293
 	 */
294
-	public function parseItemsParameter( array $constraintParameters, $constraintTypeItemId, $required ) {
295
-		$this->checkError( $constraintParameters );
296
-		$qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' );
297
-		if ( !array_key_exists( $qualifierId, $constraintParameters ) ) {
298
-			if ( $required ) {
294
+	public function parseItemsParameter(array $constraintParameters, $constraintTypeItemId, $required) {
295
+		$this->checkError($constraintParameters);
296
+		$qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId');
297
+		if (!array_key_exists($qualifierId, $constraintParameters)) {
298
+			if ($required) {
299 299
 				throw new ConstraintParameterException(
300
-					wfMessage( 'wbqc-violation-message-parameter-needed' )
301
-						->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
302
-						->rawParams( $this->constraintParameterRenderer->formatPropertyId( $qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
300
+					wfMessage('wbqc-violation-message-parameter-needed')
301
+						->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
302
+						->rawParams($this->constraintParameterRenderer->formatPropertyId($qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY))
303 303
 						->escaped()
304 304
 				);
305 305
 			} else {
@@ -308,11 +308,11 @@  discard block
 block discarded – undo
308 308
 		}
309 309
 
310 310
 		$values = [];
311
-		foreach ( $constraintParameters[$qualifierId] as $parameter ) {
312
-			$snak = $this->snakDeserializer->deserialize( $parameter );
313
-			switch ( true ) {
311
+		foreach ($constraintParameters[$qualifierId] as $parameter) {
312
+			$snak = $this->snakDeserializer->deserialize($parameter);
313
+			switch (true) {
314 314
 				case $snak instanceof PropertyValueSnak:
315
-					$values[] = $this->parseItemIdParameter( $snak, $qualifierId );
315
+					$values[] = $this->parseItemIdParameter($snak, $qualifierId);
316 316
 					break;
317 317
 				case $snak instanceof PropertySomeValueSnak:
318 318
 					$values[] = ItemIdSnakValue::someValue();
@@ -331,28 +331,28 @@  discard block
 block discarded – undo
331 331
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
332 332
 	 * @return PropertyId[]
333 333
 	 */
334
-	public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) {
335
-		$this->checkError( $constraintParameters );
336
-		$propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' );
337
-		if ( !array_key_exists( $propertyId, $constraintParameters ) ) {
334
+	public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) {
335
+		$this->checkError($constraintParameters);
336
+		$propertyId = $this->config->get('WBQualityConstraintsPropertyId');
337
+		if (!array_key_exists($propertyId, $constraintParameters)) {
338 338
 			throw new ConstraintParameterException(
339
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
340
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
341
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
339
+				wfMessage('wbqc-violation-message-parameter-needed')
340
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
341
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY))
342 342
 					->escaped()
343 343
 			);
344 344
 		}
345 345
 
346 346
 		$parameters = $constraintParameters[$propertyId];
347
-		if ( count( $parameters ) === 1 &&
348
-			$this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak
347
+		if (count($parameters) === 1 &&
348
+			$this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak
349 349
 		) {
350 350
 			return [];
351 351
 		}
352 352
 
353 353
 		$properties = [];
354
-		foreach ( $parameters as $parameter ) {
355
-			$properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId );
354
+		foreach ($parameters as $parameter) {
355
+			$properties[] = $this->parsePropertyIdParameter($parameter, $propertyId);
356 356
 		}
357 357
 		return $properties;
358 358
 	}
@@ -363,16 +363,16 @@  discard block
 block discarded – undo
363 363
 	 * @throws ConstraintParameterException
364 364
 	 * @return DataValue|null
365 365
 	 */
366
-	private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) {
367
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
368
-		if ( $snak instanceof PropertyValueSnak ) {
366
+	private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) {
367
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
368
+		if ($snak instanceof PropertyValueSnak) {
369 369
 			return $snak->getDataValue();
370
-		} elseif ( $snak instanceof PropertyNoValueSnak ) {
370
+		} elseif ($snak instanceof PropertyNoValueSnak) {
371 371
 			return null;
372 372
 		} else {
373 373
 			throw new ConstraintParameterException(
374
-				wfMessage( 'wbqc-violation-message-parameter-value-or-novalue' )
375
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
374
+				wfMessage('wbqc-violation-message-parameter-value-or-novalue')
375
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY))
376 376
 					->escaped()
377 377
 			);
378 378
 		}
@@ -383,13 +383,13 @@  discard block
 block discarded – undo
383 383
 	 * @param string $parameterId
384 384
 	 * @return DataValue|null
385 385
 	 */
386
-	private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) {
386
+	private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) {
387 387
 		try {
388
-			return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId );
389
-		} catch ( ConstraintParameterException $e ) {
388
+			return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId);
389
+		} catch (ConstraintParameterException $e) {
390 390
 			// unknown value means “now”
391
-			$timeParser = ( new TimeParserFactory() )->getTimeParser();
392
-			return $timeParser->parse( gmdate( '+Y-m-d\T00:00:00\Z' ) );
391
+			$timeParser = (new TimeParserFactory())->getTimeParser();
392
+			return $timeParser->parse(gmdate('+Y-m-d\T00:00:00\Z'));
393 393
 		}
394 394
 	}
395 395
 
@@ -400,14 +400,14 @@  discard block
 block discarded – undo
400 400
 	 * @param string $unit
401 401
 	 * @return bool
402 402
 	 */
403
-	private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) {
404
-		if ( !( $min instanceof UnboundedQuantityValue ) ||
405
-			!( $max instanceof UnboundedQuantityValue )
403
+	private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) {
404
+		if (!($min instanceof UnboundedQuantityValue) ||
405
+			!($max instanceof UnboundedQuantityValue)
406 406
 		) {
407 407
 			return false;
408 408
 		}
409 409
 
410
-		return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit );
410
+		return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit);
411 411
 	}
412 412
 
413 413
 	/**
@@ -418,9 +418,9 @@  discard block
 block discarded – undo
418 418
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
419 419
 	 * @return DataValue[] a pair of two quantity-type data values, either of which may be null to signify an open range
420 420
 	 */
421
-	public function parseRangeParameter( array $constraintParameters, $constraintTypeItemId, $type ) {
422
-		$this->checkError( $constraintParameters );
423
-		switch ( $type ) {
421
+	public function parseRangeParameter(array $constraintParameters, $constraintTypeItemId, $type) {
422
+		$this->checkError($constraintParameters);
423
+		switch ($type) {
424 424
 			case 'quantity':
425 425
 				$configKey = 'Quantity';
426 426
 				break;
@@ -429,46 +429,46 @@  discard block
 block discarded – undo
429 429
 				break;
430 430
 			default:
431 431
 				throw new ConstraintParameterException(
432
-					wfMessage( 'wbqc-violation-message-value-needed-of-types-2' )
432
+					wfMessage('wbqc-violation-message-value-needed-of-types-2')
433 433
 						->rawParams(
434
-							wfMessage( 'datatypes-type-quantity' )->escaped(),
435
-							wfMessage( 'datatypes-type-time' )->escaped()
434
+							wfMessage('datatypes-type-quantity')->escaped(),
435
+							wfMessage('datatypes-type-time')->escaped()
436 436
 						)
437 437
 						->escaped()
438 438
 				);
439 439
 		}
440
-		$minimumId = $this->config->get( 'WBQualityConstraintsMinimum' . $configKey . 'Id' );
441
-		$maximumId = $this->config->get( 'WBQualityConstraintsMaximum' . $configKey . 'Id' );
442
-		if ( !array_key_exists( $minimumId, $constraintParameters ) ||
443
-			!array_key_exists( $maximumId, $constraintParameters )
440
+		$minimumId = $this->config->get('WBQualityConstraintsMinimum'.$configKey.'Id');
441
+		$maximumId = $this->config->get('WBQualityConstraintsMaximum'.$configKey.'Id');
442
+		if (!array_key_exists($minimumId, $constraintParameters) ||
443
+			!array_key_exists($maximumId, $constraintParameters)
444 444
 		) {
445 445
 			throw new ConstraintParameterException(
446
-				wfMessage( 'wbqc-violation-message-range-parameters-needed' )
446
+				wfMessage('wbqc-violation-message-range-parameters-needed')
447 447
 					->rawParams(
448
-						wfMessage( 'datatypes-type-' . $type )->escaped(),
449
-						$this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
450
-						$this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY )
448
+						wfMessage('datatypes-type-'.$type)->escaped(),
449
+						$this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY),
450
+						$this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY)
451 451
 					)
452
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
452
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
453 453
 					->escaped()
454 454
 			);
455 455
 		}
456 456
 
457
-		$this->requireSingleParameter( $constraintParameters, $minimumId );
458
-		$this->requireSingleParameter( $constraintParameters, $maximumId );
457
+		$this->requireSingleParameter($constraintParameters, $minimumId);
458
+		$this->requireSingleParameter($constraintParameters, $maximumId);
459 459
 		$parseFunction = $configKey === 'Date' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter';
460
-		$min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId );
461
-		$max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId );
460
+		$min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId);
461
+		$max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId);
462 462
 
463
-		$yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' );
464
-		if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) {
463
+		$yearUnit = $this->config->get('WBQualityConstraintsYearUnit');
464
+		if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) {
465 465
 			throw new ConstraintParameterException(
466
-				wfMessage( 'wbqc-violation-message-range-parameters-one-year' )
466
+				wfMessage('wbqc-violation-message-range-parameters-one-year')
467 467
 					->escaped()
468 468
 			);
469 469
 		}
470 470
 
471
-		return [ $min, $max ];
471
+		return [$min, $max];
472 472
 	}
473 473
 
474 474
 	/**
@@ -478,18 +478,18 @@  discard block
 block discarded – undo
478 478
 	 * @throws ConstraintParameterException
479 479
 	 * @return string
480 480
 	 */
481
-	private function parseStringParameter( array $snakSerialization, $parameterId ) {
482
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
483
-		$this->requireValueParameter( $snak, $parameterId );
481
+	private function parseStringParameter(array $snakSerialization, $parameterId) {
482
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
483
+		$this->requireValueParameter($snak, $parameterId);
484 484
 		$value = $snak->getDataValue();
485
-		if ( $value instanceof StringValue ) {
485
+		if ($value instanceof StringValue) {
486 486
 			return $value->getValue();
487 487
 		} else {
488 488
 			throw new ConstraintParameterException(
489
-				wfMessage( 'wbqc-violation-message-parameter-string' )
489
+				wfMessage('wbqc-violation-message-parameter-string')
490 490
 					->rawParams(
491
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
492
-						$this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
491
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
492
+						$this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
493 493
 					)
494 494
 					->escaped()
495 495
 			);
@@ -502,15 +502,15 @@  discard block
 block discarded – undo
502 502
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
503 503
 	 * @return string
504 504
 	 */
505
-	public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) {
506
-		$this->checkError( $constraintParameters );
507
-		$namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' );
508
-		if ( !array_key_exists( $namespaceId, $constraintParameters ) ) {
505
+	public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) {
506
+		$this->checkError($constraintParameters);
507
+		$namespaceId = $this->config->get('WBQualityConstraintsNamespaceId');
508
+		if (!array_key_exists($namespaceId, $constraintParameters)) {
509 509
 			return '';
510 510
 		}
511 511
 
512
-		$this->requireSingleParameter( $constraintParameters, $namespaceId );
513
-		return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId );
512
+		$this->requireSingleParameter($constraintParameters, $namespaceId);
513
+		return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId);
514 514
 	}
515 515
 
516 516
 	/**
@@ -519,20 +519,20 @@  discard block
 block discarded – undo
519 519
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
520 520
 	 * @return string
521 521
 	 */
522
-	public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) {
523
-		$this->checkError( $constraintParameters );
524
-		$formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' );
525
-		if ( !array_key_exists( $formatId, $constraintParameters ) ) {
522
+	public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) {
523
+		$this->checkError($constraintParameters);
524
+		$formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId');
525
+		if (!array_key_exists($formatId, $constraintParameters)) {
526 526
 			throw new ConstraintParameterException(
527
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
528
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
529
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $formatId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
527
+				wfMessage('wbqc-violation-message-parameter-needed')
528
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
529
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($formatId, Role::CONSTRAINT_PARAMETER_PROPERTY))
530 530
 					->escaped()
531 531
 			);
532 532
 		}
533 533
 
534
-		$this->requireSingleParameter( $constraintParameters, $formatId );
535
-		return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId );
534
+		$this->requireSingleParameter($constraintParameters, $formatId);
535
+		return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId);
536 536
 	}
537 537
 
538 538
 	/**
@@ -540,16 +540,16 @@  discard block
 block discarded – undo
540 540
 	 * @throws ConstraintParameterException if the parameter is invalid
541 541
 	 * @return EntityId[]
542 542
 	 */
543
-	public function parseExceptionParameter( array $constraintParameters ) {
544
-		$this->checkError( $constraintParameters );
545
-		$exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' );
546
-		if ( !array_key_exists( $exceptionId, $constraintParameters ) ) {
543
+	public function parseExceptionParameter(array $constraintParameters) {
544
+		$this->checkError($constraintParameters);
545
+		$exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId');
546
+		if (!array_key_exists($exceptionId, $constraintParameters)) {
547 547
 			return [];
548 548
 		}
549 549
 
550 550
 		return array_map(
551
-			function( $snakSerialization ) use ( $exceptionId ) {
552
-				return $this->parseEntityIdParameter( $snakSerialization, $exceptionId );
551
+			function($snakSerialization) use ($exceptionId) {
552
+				return $this->parseEntityIdParameter($snakSerialization, $exceptionId);
553 553
 			},
554 554
 			$constraintParameters[$exceptionId]
555 555
 		);
@@ -560,27 +560,27 @@  discard block
 block discarded – undo
560 560
 	 * @throws ConstraintParameterException if the parameter is invalid
561 561
 	 * @return string|null 'mandatory' or null
562 562
 	 */
563
-	public function parseConstraintStatusParameter( array $constraintParameters ) {
564
-		$this->checkError( $constraintParameters );
565
-		$constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' );
566
-		if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) {
563
+	public function parseConstraintStatusParameter(array $constraintParameters) {
564
+		$this->checkError($constraintParameters);
565
+		$constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId');
566
+		if (!array_key_exists($constraintStatusId, $constraintParameters)) {
567 567
 			return null;
568 568
 		}
569 569
 
570
-		$mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' );
571
-		$this->requireSingleParameter( $constraintParameters, $constraintStatusId );
572
-		$snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] );
573
-		$this->requireValueParameter( $snak, $constraintStatusId );
570
+		$mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId');
571
+		$this->requireSingleParameter($constraintParameters, $constraintStatusId);
572
+		$snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]);
573
+		$this->requireValueParameter($snak, $constraintStatusId);
574 574
 		$statusId = $snak->getDataValue()->getEntityId()->getSerialization();
575 575
 
576
-		if ( $statusId === $mandatoryId ) {
576
+		if ($statusId === $mandatoryId) {
577 577
 			return 'mandatory';
578 578
 		} else {
579 579
 			throw new ConstraintParameterException(
580
-				wfMessage( 'wbqc-violation-message-parameter-oneof' )
581
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
582
-					->numParams( 1 )
583
-					->rawParams( $this->constraintParameterRenderer->formatItemIdList( [ $mandatoryId ], Role::CONSTRAINT_PARAMETER_VALUE ) )
580
+				wfMessage('wbqc-violation-message-parameter-oneof')
581
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY))
582
+					->numParams(1)
583
+					->rawParams($this->constraintParameterRenderer->formatItemIdList([$mandatoryId], Role::CONSTRAINT_PARAMETER_VALUE))
584 584
 					->escaped()
585 585
 			);
586 586
 		}
@@ -593,13 +593,13 @@  discard block
 block discarded – undo
593 593
 	 * @return void
594 594
 	 * @throws ConstraintParameterException
595 595
 	 */
596
-	private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) {
597
-		if ( !( $dataValue instanceof MonolingualTextValue ) ) {
596
+	private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) {
597
+		if (!($dataValue instanceof MonolingualTextValue)) {
598 598
 			throw new ConstraintParameterException(
599
-				wfMessage( 'wbqc-violation-message-parameter-monolingualtext' )
599
+				wfMessage('wbqc-violation-message-parameter-monolingualtext')
600 600
 					->rawParams(
601
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
602
-						$this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
601
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
602
+						$this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
603 603
 					)
604 604
 					->escaped()
605 605
 			);
@@ -614,26 +614,26 @@  discard block
 block discarded – undo
614 614
 	 * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts
615 615
 	 * @return string[]
616 616
 	 */
617
-	private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) {
617
+	private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) {
618 618
 		$result = [];
619 619
 
620
-		foreach ( $snakSerializations as $snakSerialization ) {
621
-			$snak = $this->snakDeserializer->deserialize( $snakSerialization );
622
-			$this->requireValueParameter( $snak, $parameterId );
620
+		foreach ($snakSerializations as $snakSerialization) {
621
+			$snak = $this->snakDeserializer->deserialize($snakSerialization);
622
+			$this->requireValueParameter($snak, $parameterId);
623 623
 
624 624
 			$value = $snak->getDataValue();
625
-			$this->requireMonolingualTextParameter( $value, $parameterId );
625
+			$this->requireMonolingualTextParameter($value, $parameterId);
626 626
 			/** @var MonolingualTextValue $value */
627 627
 
628 628
 			$code = $value->getLanguageCode();
629
-			if ( array_key_exists( $code, $result ) ) {
629
+			if (array_key_exists($code, $result)) {
630 630
 				throw new ConstraintParameterException(
631
-					wfMessage( 'wbqc-violation-message-parameter-single-per-language' )
631
+					wfMessage('wbqc-violation-message-parameter-single-per-language')
632 632
 						->rawParams(
633
-							$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY )
633
+							$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)
634 634
 						)
635 635
 						->plaintextParams(
636
-							Language::fetchLanguageName( $code ),
636
+							Language::fetchLanguageName($code),
637 637
 							$code
638 638
 						)
639 639
 						->escaped()
@@ -652,23 +652,23 @@  discard block
 block discarded – undo
652 652
 	 * @throws ConstraintParameterException if the parameter is invalid
653 653
 	 * @return string|null
654 654
 	 */
655
-	public function parseSyntaxClarificationParameter( array $constraintParameters, Language $language ) {
656
-		$syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' );
655
+	public function parseSyntaxClarificationParameter(array $constraintParameters, Language $language) {
656
+		$syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId');
657 657
 
658
-		if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) {
658
+		if (!array_key_exists($syntaxClarificationId, $constraintParameters)) {
659 659
 			return null;
660 660
 		}
661 661
 
662 662
 		$languageCodes = $language->getFallbackLanguages();
663
-		array_unshift( $languageCodes, $language->getCode() );
663
+		array_unshift($languageCodes, $language->getCode());
664 664
 
665 665
 		$syntaxClarifications = $this->parseMultilingualTextParameter(
666 666
 			$constraintParameters[$syntaxClarificationId],
667 667
 			$syntaxClarificationId
668 668
 		);
669 669
 
670
-		foreach ( $languageCodes as $languageCode ) {
671
-			if ( array_key_exists( $languageCode, $syntaxClarifications ) ) {
670
+		foreach ($languageCodes as $languageCode) {
671
+			if (array_key_exists($languageCode, $syntaxClarifications)) {
672 672
 				return $syntaxClarifications[$languageCode];
673 673
 			}
674 674
 		}
@@ -684,20 +684,20 @@  discard block
 block discarded – undo
684 684
 	 * @throws ConstraintParameterException if the parameter is invalid
685 685
 	 * @return string[]|null Context::TYPE_* constants
686 686
 	 */
687
-	public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) {
688
-		$constraintScopeId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' );
689
-		$mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' );
690
-		$qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' );
691
-		$referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' );
687
+	public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) {
688
+		$constraintScopeId = $this->config->get('WBQualityConstraintsConstraintScopeId');
689
+		$mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId');
690
+		$qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId');
691
+		$referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId');
692 692
 
693
-		if ( !array_key_exists( $constraintScopeId, $constraintParameters ) ) {
693
+		if (!array_key_exists($constraintScopeId, $constraintParameters)) {
694 694
 			return null;
695 695
 		}
696 696
 
697 697
 		$contextTypes = [];
698
-		foreach ( $constraintParameters[$constraintScopeId] as $snakSerialization ) {
699
-			$scopeEntityId = $this->parseEntityIdParameter( $snakSerialization, $constraintScopeId );
700
-			switch ( $scopeEntityId->getSerialization() ) {
698
+		foreach ($constraintParameters[$constraintScopeId] as $snakSerialization) {
699
+			$scopeEntityId = $this->parseEntityIdParameter($snakSerialization, $constraintScopeId);
700
+			switch ($scopeEntityId->getSerialization()) {
701 701
 				case $mainSnakId:
702 702
 					$contextTypes[] = Context::TYPE_STATEMENT;
703 703
 					break;
@@ -709,14 +709,14 @@  discard block
 block discarded – undo
709 709
 					break;
710 710
 				default:
711 711
 					throw new ConstraintParameterException(
712
-						wfMessage( 'wbqc-violation-message-parameter-oneof' )
712
+						wfMessage('wbqc-violation-message-parameter-oneof')
713 713
 							->rawParams(
714 714
 								$this->constraintParameterRenderer->formatPropertyId(
715 715
 									$constraintScopeId,
716 716
 									Role::CONSTRAINT_PARAMETER_PROPERTY
717 717
 								)
718 718
 							)
719
-							->numParams( 3 )
719
+							->numParams(3)
720 720
 							->rawParams(
721 721
 								$this->constraintParameterRenderer->formatItemIdList(
722 722
 									[
@@ -732,12 +732,12 @@  discard block
 block discarded – undo
732 732
 			}
733 733
 		}
734 734
 
735
-		if ( $validScopes !== null ) {
736
-			$invalidScopes = array_diff( $contextTypes, $validScopes );
737
-			if ( $invalidScopes !== [] ) {
738
-				$invalidScope = array_pop( $invalidScopes );
735
+		if ($validScopes !== null) {
736
+			$invalidScopes = array_diff($contextTypes, $validScopes);
737
+			if ($invalidScopes !== []) {
738
+				$invalidScope = array_pop($invalidScopes);
739 739
 				throw new ConstraintParameterException(
740
-					wfMessage( 'wbqc-violation-message-invalid-scope' )
740
+					wfMessage('wbqc-violation-message-invalid-scope')
741 741
 						->rawParams(
742 742
 							$this->constraintParameterRenderer->formatConstraintScope(
743 743
 								$invalidScope,
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
 								Role::CONSTRAINT_TYPE_ITEM
749 749
 							)
750 750
 						)
751
-						->numParams( count( $validScopes ) )
751
+						->numParams(count($validScopes))
752 752
 						->rawParams(
753 753
 							$this->constraintParameterRenderer->formatConstraintScopeList(
754 754
 								$validScopes,
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/TypeCheckerHelper.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -87,23 +87,23 @@  discard block
 block discarded – undo
87 87
 	 * @return bool
88 88
 	 * @throws OverflowException if $entitiesChecked exceeds the configured limit
89 89
 	 */
90
-	private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) {
91
-		$maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' );
90
+	private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) {
91
+		$maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities');
92 92
 		if ( ++$entitiesChecked > $maxEntities ) {
93
-			throw new OverflowException( 'Too many entities to check' );
93
+			throw new OverflowException('Too many entities to check');
94 94
 		}
95 95
 
96
-		$item = $this->entityLookup->getEntity( $comparativeClass );
97
-		if ( !( $item instanceof StatementListProvider ) ) {
96
+		$item = $this->entityLookup->getEntity($comparativeClass);
97
+		if (!($item instanceof StatementListProvider)) {
98 98
 			return false; // lookup failed, probably because item doesn't exist
99 99
 		}
100 100
 
101
-		$subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
101
+		$subclassId = $this->config->get('WBQualityConstraintsSubclassOfId');
102 102
 		/** @var Statement $statement */
103
-		foreach ( $item->getStatements()->getByPropertyId( new PropertyId( $subclassId ) ) as $statement ) {
103
+		foreach ($item->getStatements()->getByPropertyId(new PropertyId($subclassId)) as $statement) {
104 104
 			$mainSnak = $statement->getMainSnak();
105 105
 
106
-			if ( !( $this->hasCorrectType( $mainSnak ) ) ) {
106
+			if (!($this->hasCorrectType($mainSnak))) {
107 107
 				continue;
108 108
 			}
109 109
 			/** @var PropertyValueSnak $mainSnak */
@@ -112,11 +112,11 @@  discard block
 block discarded – undo
112 112
 			$dataValue = $mainSnak->getDataValue();
113 113
 			$comparativeClass = $dataValue->getEntityId();
114 114
 
115
-			if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) {
115
+			if (in_array($comparativeClass->getSerialization(), $classesToCheck)) {
116 116
 				return true;
117 117
 			}
118 118
 
119
-			if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) {
119
+			if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) {
120 120
 				return true;
121 121
 			}
122 122
 		}
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
 	 * @return CachedBool
138 138
 	 * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs
139 139
 	 */
140
-	public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) {
140
+	public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) {
141 141
 		try {
142 142
 			return new CachedBool(
143
-				$this->isSubclassOf( $comparativeClass, $classesToCheck ),
143
+				$this->isSubclassOf($comparativeClass, $classesToCheck),
144 144
 				Metadata::blank()
145 145
 			);
146
-		} catch ( OverflowException $e ) {
147
-			if ( $this->sparqlHelper !== null ) {
146
+		} catch (OverflowException $e) {
147
+			if ($this->sparqlHelper !== null) {
148 148
 				$this->dataFactory->increment(
149 149
 					'wikibase.quality.constraints.sparql.typeFallback'
150 150
 				);
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 					/* withInstance = */ false
155 155
 				);
156 156
 			} else {
157
-				return new CachedBool( false, Metadata::blank() );
157
+				return new CachedBool(false, Metadata::blank());
158 158
 			}
159 159
 		}
160 160
 	}
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
 	 * @return CachedBool
173 173
 	 * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs
174 174
 	 */
175
-	public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) {
175
+	public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) {
176 176
 		$metadatas = [];
177 177
 
178 178
 		/** @var Statement $statement */
179
-		foreach ( $this->getStatementsByPropertyIds( $statements, $relationIds ) as $statement ) {
179
+		foreach ($this->getStatementsByPropertyIds($statements, $relationIds) as $statement) {
180 180
 			$mainSnak = $statement->getMainSnak();
181 181
 
182
-			if ( !$this->hasCorrectType( $mainSnak ) ) {
182
+			if (!$this->hasCorrectType($mainSnak)) {
183 183
 				continue;
184 184
 			}
185 185
 			/** @var PropertyValueSnak $mainSnak */
@@ -188,28 +188,28 @@  discard block
 block discarded – undo
188 188
 			$dataValue = $mainSnak->getDataValue();
189 189
 			$comparativeClass = $dataValue->getEntityId();
190 190
 
191
-			if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) {
191
+			if (in_array($comparativeClass->getSerialization(), $classesToCheck)) {
192 192
 				// discard $metadatas, we know this is fresh
193
-				return new CachedBool( true, Metadata::blank() );
193
+				return new CachedBool(true, Metadata::blank());
194 194
 			}
195 195
 
196
-			$result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck );
196
+			$result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck);
197 197
 			$metadatas[] = $result->getMetadata();
198
-			if ( $result->getBool() ) {
198
+			if ($result->getBool()) {
199 199
 				return new CachedBool(
200 200
 					true,
201
-					Metadata::merge( $metadatas )
201
+					Metadata::merge($metadatas)
202 202
 				);
203 203
 			}
204 204
 		}
205 205
 
206 206
 		return new CachedBool(
207 207
 			false,
208
-			Metadata::merge( $metadatas )
208
+			Metadata::merge($metadatas)
209 209
 		);
210 210
 	}
211 211
 
212
-	private function hasCorrectType( Snak $mainSnak ) {
212
+	private function hasCorrectType(Snak $mainSnak) {
213 213
 		return $mainSnak instanceof PropertyValueSnak
214 214
 			&& $mainSnak->getDataValue()->getType() === 'wikibase-entityid';
215 215
 	}
@@ -224,12 +224,12 @@  discard block
 block discarded – undo
224 224
 		array $propertyIdSerializations
225 225
 	) {
226 226
 		$statementArrays = [];
227
-		foreach ( $propertyIdSerializations as $propertyIdSerialization ) {
228
-			$propertyId = new PropertyId( $propertyIdSerialization );
229
-			$statementArrays[] = $statements->getByPropertyId( $propertyId )->toArray();
227
+		foreach ($propertyIdSerializations as $propertyIdSerialization) {
228
+			$propertyId = new PropertyId($propertyIdSerialization);
229
+			$statementArrays[] = $statements->getByPropertyId($propertyId)->toArray();
230 230
 		}
231 231
 		return new StatementList(
232
-			call_user_func_array( 'array_merge', $statementArrays )
232
+			call_user_func_array('array_merge', $statementArrays)
233 233
 		);
234 234
 	}
235 235
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	 *
243 243
 	 * @return string Localized HTML message
244 244
 	 */
245
-	public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) {
245
+	public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) {
246 246
 		// Possible messages:
247 247
 		// wbqc-violation-message-type-instance
248 248
 		// wbqc-violation-message-type-subclass
@@ -250,14 +250,14 @@  discard block
 block discarded – undo
250 250
 		// wbqc-violation-message-valueType-instance
251 251
 		// wbqc-violation-message-valueType-subclass
252 252
 		// wbqc-violation-message-valueType-instanceOrSubclass
253
-		$message = wfMessage( 'wbqc-violation-message-' . $checker . '-' . $relation );
253
+		$message = wfMessage('wbqc-violation-message-'.$checker.'-'.$relation);
254 254
 
255 255
 		$message->rawParams(
256
-			$this->constraintParameterRenderer->formatEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ),
257
-			$this->constraintParameterRenderer->formatEntityId( $entityId, Role::SUBJECT )
256
+			$this->constraintParameterRenderer->formatEntityId($propertyId, Role::CONSTRAINT_PROPERTY),
257
+			$this->constraintParameterRenderer->formatEntityId($entityId, Role::SUBJECT)
258 258
 		);
259
-		$message->numParams( count( $classes ) );
260
-		$message->rawParams( $this->constraintParameterRenderer->formatItemIdList( $classes, Role::OBJECT ) );
259
+		$message->numParams(count($classes));
260
+		$message->rawParams($this->constraintParameterRenderer->formatItemIdList($classes, Role::OBJECT));
261 261
 
262 262
 		return $message->escaped();
263 263
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/SparqlHelper.php 1 patch
Spacing   +130 added lines, -132 removed lines patch added patch discarded remove patch
@@ -91,18 +91,18 @@  discard block
 block discarded – undo
91 91
 		$this->cache = $cache;
92 92
 		$this->dataFactory = $dataFactory;
93 93
 
94
-		$this->entityPrefix = $rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY );
94
+		$this->entityPrefix = $rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY);
95 95
 		$this->prefixes = <<<EOT
96
-PREFIX wd: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY )}>
97
-PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}>
98
-PREFIX wdt: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_DIRECT_CLAIM )}>
99
-PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>
100
-PREFIX p: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM )}>
101
-PREFIX ps: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM_STATEMENT )}>
102
-PREFIX pq: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER )}>
103
-PREFIX pqv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER_VALUE )}>
104
-PREFIX pr: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE )}>
105
-PREFIX prv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE_VALUE )}>
96
+PREFIX wd: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY)}>
97
+PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}>
98
+PREFIX wdt: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_DIRECT_CLAIM)}>
99
+PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>
100
+PREFIX p: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM)}>
101
+PREFIX ps: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM_STATEMENT)}>
102
+PREFIX pq: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER)}>
103
+PREFIX pqv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER_VALUE)}>
104
+PREFIX pr: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE)}>
105
+PREFIX prv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE_VALUE)}>
106 106
 PREFIX wikibase: <http://wikiba.se/ontology#>
107 107
 PREFIX wikibase-beta: <http://wikiba.se/ontology-beta#>
108 108
 EOT;
@@ -117,21 +117,21 @@  discard block
 block discarded – undo
117 117
 	 * @return CachedBool
118 118
 	 * @throws SparqlHelperException if the query times out or some other error occurs
119 119
 	 */
120
-	public function hasType( $id, array $classes, $withInstance ) {
121
-		$instanceOfId = $this->config->get( 'WBQualityConstraintsInstanceOfId' );
122
-		$subclassOfId = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
120
+	public function hasType($id, array $classes, $withInstance) {
121
+		$instanceOfId = $this->config->get('WBQualityConstraintsInstanceOfId');
122
+		$subclassOfId = $this->config->get('WBQualityConstraintsSubclassOfId');
123 123
 
124
-		$path = ( $withInstance ? "wdt:$instanceOfId/" : "" ) . "wdt:$subclassOfId*";
124
+		$path = ($withInstance ? "wdt:$instanceOfId/" : "")."wdt:$subclassOfId*";
125 125
 
126 126
 		$metadatas = [];
127 127
 
128
-		foreach ( array_chunk( $classes, 20 ) as $classesChunk ) {
129
-			$classesValues = implode( ' ', array_map(
130
-				function( $class ) {
131
-					return 'wd:' . $class;
128
+		foreach (array_chunk($classes, 20) as $classesChunk) {
129
+			$classesValues = implode(' ', array_map(
130
+				function($class) {
131
+					return 'wd:'.$class;
132 132
 				},
133 133
 				$classesChunk
134
-			) );
134
+			));
135 135
 
136 136
 			$query = <<<EOF
137 137
 ASK {
@@ -142,19 +142,19 @@  discard block
 block discarded – undo
142 142
 EOF;
143 143
 			// TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually
144 144
 
145
-			$result = $this->runQuery( $query );
145
+			$result = $this->runQuery($query);
146 146
 			$metadatas[] = $result->getMetadata();
147
-			if ( $result->getArray()['boolean'] ) {
147
+			if ($result->getArray()['boolean']) {
148 148
 				return new CachedBool(
149 149
 					true,
150
-					Metadata::merge( $metadatas )
150
+					Metadata::merge($metadatas)
151 151
 				);
152 152
 			}
153 153
 		}
154 154
 
155 155
 		return new CachedBool(
156 156
 			false,
157
-			Metadata::merge( $metadatas )
157
+			Metadata::merge($metadatas)
158 158
 		);
159 159
 	}
160 160
 
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
 		$ignoreDeprecatedStatements
171 171
 	) {
172 172
 		$pid = $statement->getPropertyId()->serialize();
173
-		$guid = str_replace( '$', '-', $statement->getGuid() );
173
+		$guid = str_replace('$', '-', $statement->getGuid());
174 174
 
175 175
 		$deprecatedFilter = '';
176
-		if ( $ignoreDeprecatedStatements ) {
176
+		if ($ignoreDeprecatedStatements) {
177 177
 			$deprecatedFilter .= 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }';
178 178
 			$deprecatedFilter .= 'MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }';
179 179
 		}
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
 LIMIT 10
194 194
 EOF;
195 195
 
196
-		$result = $this->runQuery( $query );
196
+		$result = $this->runQuery($query);
197 197
 
198
-		return $this->getOtherEntities( $result );
198
+		return $this->getOtherEntities($result);
199 199
 	}
200 200
 
201 201
 	/**
@@ -220,16 +220,15 @@  discard block
 block discarded – undo
220 220
 		$dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty(
221 221
 			$snak->getPropertyId()
222 222
 		);
223
-		list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue );
224
-		if ( $isFullValue ) {
223
+		list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue);
224
+		if ($isFullValue) {
225 225
 			$prefix .= 'v';
226 226
 		}
227 227
 		$path = $type === Context::TYPE_QUALIFIER ?
228
-			"$prefix:$pid" :
229
-			"prov:wasDerivedFrom/$prefix:$pid";
228
+			"$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid";
230 229
 
231 230
 		$deprecatedFilter = '';
232
-		if ( $ignoreDeprecatedStatements ) {
231
+		if ($ignoreDeprecatedStatements) {
233 232
 			$deprecatedFilter = <<< EOF
234 233
   MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }
235 234
   MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }
@@ -250,9 +249,9 @@  discard block
 block discarded – undo
250 249
 LIMIT 10
251 250
 EOF;
252 251
 
253
-		$result = $this->runQuery( $query );
252
+		$result = $this->runQuery($query);
254 253
 
255
-		return $this->getOtherEntities( $result );
254
+		return $this->getOtherEntities($result);
256 255
 	}
257 256
 
258 257
 	/**
@@ -262,8 +261,8 @@  discard block
 block discarded – undo
262 261
 	 *
263 262
 	 * @return string
264 263
 	 */
265
-	private function stringLiteral( $text ) {
266
-		return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"';
264
+	private function stringLiteral($text) {
265
+		return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"';
267 266
 	}
268 267
 
269 268
 	/**
@@ -273,17 +272,17 @@  discard block
 block discarded – undo
273 272
 	 *
274 273
 	 * @return CachedEntityIds
275 274
 	 */
276
-	private function getOtherEntities( CachedQueryResults $results ) {
277
-		return new CachedEntityIds( array_map(
278
-			function ( $resultBindings ) {
275
+	private function getOtherEntities(CachedQueryResults $results) {
276
+		return new CachedEntityIds(array_map(
277
+			function($resultBindings) {
279 278
 				$entityIRI = $resultBindings['otherEntity']['value'];
280
-				$entityPrefixLength = strlen( $this->entityPrefix );
281
-				if ( substr( $entityIRI, 0, $entityPrefixLength ) === $this->entityPrefix ) {
279
+				$entityPrefixLength = strlen($this->entityPrefix);
280
+				if (substr($entityIRI, 0, $entityPrefixLength) === $this->entityPrefix) {
282 281
 					try {
283 282
 						return $this->entityIdParser->parse(
284
-							substr( $entityIRI, $entityPrefixLength )
283
+							substr($entityIRI, $entityPrefixLength)
285 284
 						);
286
-					} catch ( EntityIdParsingException $e ) {
285
+					} catch (EntityIdParsingException $e) {
287 286
 						// fall through
288 287
 					}
289 288
 				}
@@ -291,7 +290,7 @@  discard block
 block discarded – undo
291 290
 				return null;
292 291
 			},
293 292
 			$results->getArray()['results']['bindings']
294
-		), $results->getMetadata() );
293
+		), $results->getMetadata());
295 294
 	}
296 295
 
297 296
 	// @codingStandardsIgnoreStart cyclomatic complexity of this function is too high
@@ -304,47 +303,47 @@  discard block
 block discarded – undo
304 303
 	 * @return array the literal or IRI as a string in SPARQL syntax,
305 304
 	 * and a boolean indicating whether it refers to a full value node or not
306 305
 	 */
307
-	private function getRdfLiteral( $dataType, DataValue $dataValue ) {
308
-		switch ( $dataType ) {
306
+	private function getRdfLiteral($dataType, DataValue $dataValue) {
307
+		switch ($dataType) {
309 308
 			case 'string':
310 309
 			case 'external-id':
311
-				return [ $this->stringLiteral( $dataValue->getValue() ), false ];
310
+				return [$this->stringLiteral($dataValue->getValue()), false];
312 311
 			case 'commonsMedia':
313
-				$url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() );
314
-				return [ '<' . $url . '>', false ];
312
+				$url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue());
313
+				return ['<'.$url.'>', false];
315 314
 			case 'geo-shape':
316
-				$url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() );
317
-				return [ '<' . $url . '>', false ];
315
+				$url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue());
316
+				return ['<'.$url.'>', false];
318 317
 			case 'tabular-data':
319
-				$url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() );
320
-				return [ '<' . $url . '>', false ];
318
+				$url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue());
319
+				return ['<'.$url.'>', false];
321 320
 			case 'url':
322 321
 				$url = $dataValue->getValue();
323
-				if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) {
322
+				if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) {
324 323
 					// not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF)
325 324
 					// such an URL should never reach us, so just throw
326
-					throw new InvalidArgumentException( 'invalid URL: ' . $url );
325
+					throw new InvalidArgumentException('invalid URL: '.$url);
327 326
 				}
328
-				return [ '<' . $url . '>', false ];
327
+				return ['<'.$url.'>', false];
329 328
 			case 'wikibase-item':
330 329
 			case 'wikibase-property':
331 330
 				/** @var EntityIdValue $dataValue */
332
-				return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ];
331
+				return ['wd:'.$dataValue->getEntityId()->getSerialization(), false];
333 332
 			case 'monolingualtext':
334 333
 				/** @var MonolingualTextValue $dataValue */
335 334
 				$lang = $dataValue->getLanguageCode();
336
-				if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) {
335
+				if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) {
337 336
 					// not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG)
338 337
 					// such a language tag should never reach us, so just throw
339
-					throw new InvalidArgumentException( 'invalid language tag: ' . $lang );
338
+					throw new InvalidArgumentException('invalid language tag: '.$lang);
340 339
 				}
341
-				return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ];
340
+				return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false];
342 341
 			case 'globe-coordinate':
343 342
 			case 'quantity':
344 343
 			case 'time':
345
-				return [ 'wdv:' . $dataValue->getHash(), true ];
344
+				return ['wdv:'.$dataValue->getHash(), true];
346 345
 			default:
347
-				throw new InvalidArgumentException( 'unknown data type: ' . $dataType );
346
+				throw new InvalidArgumentException('unknown data type: '.$dataType);
348 347
 		}
349 348
 	}
350 349
 	// @codingStandardsIgnoreEnd
@@ -357,47 +356,47 @@  discard block
 block discarded – undo
357 356
 	 * @throws SparqlHelperException if the query times out or some other error occurs
358 357
 	 * @throws ConstraintParameterException if the $regex is invalid
359 358
 	 */
360
-	public function matchesRegularExpression( $text, $regex ) {
359
+	public function matchesRegularExpression($text, $regex) {
361 360
 		// caching wrapper around matchesRegularExpressionWithSparql
362 361
 
363
-		$textHash = hash( 'sha256', $text );
362
+		$textHash = hash('sha256', $text);
364 363
 		$cacheKey = $this->cache->makeKey(
365 364
 			'WikibaseQualityConstraints', // extension
366 365
 			'regex', // action
367 366
 			'WDQS-Java', // regex flavor
368
-			hash( 'sha256', $regex )
367
+			hash('sha256', $regex)
369 368
 		);
370
-		$cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' );
369
+		$cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize');
371 370
 
372 371
 		$cacheMapArray = $this->cache->getWithSetCallback(
373 372
 			$cacheKey,
374 373
 			WANObjectCache::TTL_DAY,
375
-			function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) {
374
+			function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) {
376 375
 				// Initialize the cache map if not set
377
-				if ( $cacheMapArray === false ) {
376
+				if ($cacheMapArray === false) {
378 377
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.init';
379
-					$this->dataFactory->increment( $key );
378
+					$this->dataFactory->increment($key);
380 379
 					return [];
381 380
 				}
382 381
 
383 382
 				$key = 'wikibase.quality.constraints.regex.cache.refresh';
384
-				$this->dataFactory->increment( $key );
385
-				$cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize );
386
-				if ( $cacheMap->has( $textHash ) ) {
383
+				$this->dataFactory->increment($key);
384
+				$cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize);
385
+				if ($cacheMap->has($textHash)) {
387 386
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.hit';
388
-					$this->dataFactory->increment( $key );
389
-					$cacheMap->get( $textHash ); // ping cache
387
+					$this->dataFactory->increment($key);
388
+					$cacheMap->get($textHash); // ping cache
390 389
 				} else {
391 390
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.miss';
392
-					$this->dataFactory->increment( $key );
391
+					$this->dataFactory->increment($key);
393 392
 					try {
394
-						$matches = $this->matchesRegularExpressionWithSparql( $text, $regex );
395
-					} catch ( ConstraintParameterException $e ) {
393
+						$matches = $this->matchesRegularExpressionWithSparql($text, $regex);
394
+					} catch (ConstraintParameterException $e) {
396 395
 						$matches = [
397 396
 							'type' => ConstraintParameterException::class,
398 397
 							'message' => $e->getMessage(),
399 398
 						];
400
-					} catch ( SparqlHelperException $e ) {
399
+					} catch (SparqlHelperException $e) {
401 400
 						// don’t cache this
402 401
 						return $cacheMap->toArray();
403 402
 					}
@@ -421,27 +420,27 @@  discard block
 block discarded – undo
421 420
 			]
422 421
 		);
423 422
 
424
-		if ( isset( $cacheMapArray[$textHash] ) ) {
423
+		if (isset($cacheMapArray[$textHash])) {
425 424
 			$key = 'wikibase.quality.constraints.regex.cache.hit';
426
-			$this->dataFactory->increment( $key );
425
+			$this->dataFactory->increment($key);
427 426
 			$matches = $cacheMapArray[$textHash];
428
-			if ( is_bool( $matches ) ) {
427
+			if (is_bool($matches)) {
429 428
 				return $matches;
430
-			} elseif ( is_array( $matches ) &&
431
-				$matches['type'] == ConstraintParameterException::class ) {
432
-				throw new ConstraintParameterException( $matches['message'] );
429
+			} elseif (is_array($matches) &&
430
+				$matches['type'] == ConstraintParameterException::class) {
431
+				throw new ConstraintParameterException($matches['message']);
433 432
 			} else {
434 433
 				throw new MWException(
435
-					'Value of unknown type in object cache (' .
436
-					'cache key: ' . $cacheKey . ', ' .
437
-					'cache map key: ' . $textHash . ', ' .
438
-					'value type: ' . gettype( $matches ) . ')'
434
+					'Value of unknown type in object cache ('.
435
+					'cache key: '.$cacheKey.', '.
436
+					'cache map key: '.$textHash.', '.
437
+					'value type: '.gettype($matches).')'
439 438
 				);
440 439
 			}
441 440
 		} else {
442 441
 			$key = 'wikibase.quality.constraints.regex.cache.miss';
443
-			$this->dataFactory->increment( $key );
444
-			return $this->matchesRegularExpressionWithSparql( $text, $regex );
442
+			$this->dataFactory->increment($key);
443
+			return $this->matchesRegularExpressionWithSparql($text, $regex);
445 444
 		}
446 445
 	}
447 446
 
@@ -456,26 +455,26 @@  discard block
 block discarded – undo
456 455
 	 * @throws SparqlHelperException if the query times out or some other error occurs
457 456
 	 * @throws ConstraintParameterException if the $regex is invalid
458 457
 	 */
459
-	public function matchesRegularExpressionWithSparql( $text, $regex ) {
460
-		$textStringLiteral = $this->stringLiteral( $text );
461
-		$regexStringLiteral = $this->stringLiteral( '^' . $regex . '$' );
458
+	public function matchesRegularExpressionWithSparql($text, $regex) {
459
+		$textStringLiteral = $this->stringLiteral($text);
460
+		$regexStringLiteral = $this->stringLiteral('^'.$regex.'$');
462 461
 
463 462
 		$query = <<<EOF
464 463
 SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {}
465 464
 EOF;
466 465
 
467
-		$result = $this->runQuery( $query );
466
+		$result = $this->runQuery($query);
468 467
 
469 468
 		$vars = $result->getArray()['results']['bindings'][0];
470
-		if ( array_key_exists( 'matches', $vars ) ) {
469
+		if (array_key_exists('matches', $vars)) {
471 470
 			// true or false ⇒ regex okay, text matches or not
472 471
 			return $vars['matches']['value'] === 'true';
473 472
 		} else {
474 473
 			// empty result: regex broken
475 474
 			throw new ConstraintParameterException(
476
-				wfMessage( 'wbqc-violation-message-parameter-regex' )
477
-					->rawParams( ConstraintParameterRenderer::formatByRole( Role::CONSTRAINT_PARAMETER_VALUE,
478
-						'<code><nowiki>' . htmlspecialchars( $regex ) . '</nowiki></code>' ) )
475
+				wfMessage('wbqc-violation-message-parameter-regex')
476
+					->rawParams(ConstraintParameterRenderer::formatByRole(Role::CONSTRAINT_PARAMETER_VALUE,
477
+						'<code><nowiki>'.htmlspecialchars($regex).'</nowiki></code>'))
479 478
 					->escaped()
480 479
 			);
481 480
 		}
@@ -488,14 +487,14 @@  discard block
 block discarded – undo
488 487
 	 *
489 488
 	 * @return boolean
490 489
 	 */
491
-	public function isTimeout( $responseContent ) {
492
-		$timeoutRegex = implode( '|', array_map(
493
-			function ( $fqn ) {
494
-				return preg_quote( $fqn, '/' );
490
+	public function isTimeout($responseContent) {
491
+		$timeoutRegex = implode('|', array_map(
492
+			function($fqn) {
493
+				return preg_quote($fqn, '/');
495 494
 			},
496
-			$this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' )
497
-		) );
498
-		return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent );
495
+			$this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses')
496
+		));
497
+		return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent);
499 498
 	}
500 499
 
501 500
 	/**
@@ -507,17 +506,17 @@  discard block
 block discarded – undo
507 506
 	 * @return integer|boolean the max-age (in seconds)
508 507
 	 * or a plain boolean if no max-age can be determined
509 508
 	 */
510
-	public function getCacheMaxAge( $responseHeaders ) {
509
+	public function getCacheMaxAge($responseHeaders) {
511 510
 		if (
512
-			array_key_exists( 'x-cache-status', $responseHeaders ) &&
513
-			preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] )
511
+			array_key_exists('x-cache-status', $responseHeaders) &&
512
+			preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0])
514 513
 		) {
515 514
 			$maxage = [];
516 515
 			if (
517
-				array_key_exists( 'cache-control', $responseHeaders ) &&
518
-				preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage )
516
+				array_key_exists('cache-control', $responseHeaders) &&
517
+				preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage)
519 518
 			) {
520
-				return intval( $maxage[1] );
519
+				return intval($maxage[1]);
521 520
 			} else {
522 521
 				return true;
523 522
 			}
@@ -535,59 +534,58 @@  discard block
 block discarded – undo
535 534
 	 *
536 535
 	 * @throws SparqlHelperException if the query times out or some other error occurs
537 536
 	 */
538
-	public function runQuery( $query ) {
537
+	public function runQuery($query) {
539 538
 
540
-		$endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' );
541
-		$maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' );
542
-		$url = $endpoint . '?' . http_build_query(
539
+		$endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint');
540
+		$maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis');
541
+		$url = $endpoint.'?'.http_build_query(
543 542
 			[
544
-				'query' => "#wbqc\n" . $this->prefixes . $query,
543
+				'query' => "#wbqc\n".$this->prefixes.$query,
545 544
 				'format' => 'json',
546 545
 				'maxQueryTimeMillis' => $maxQueryTimeMillis,
547 546
 			],
548
-			null, ini_get( 'arg_separator.output' ),
547
+			null, ini_get('arg_separator.output'),
549 548
 			// encode spaces with %20, not +
550 549
 			PHP_QUERY_RFC3986
551 550
 		);
552 551
 
553 552
 		$options = [
554 553
 			'method' => 'GET',
555
-			'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ),
554
+			'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000),
556 555
 			'connectTimeout' => 'default',
557 556
 		];
558
-		$request = MWHttpRequest::factory( $url, $options );
559
-		$startTime = microtime( true );
557
+		$request = MWHttpRequest::factory($url, $options);
558
+		$startTime = microtime(true);
560 559
 		$status = $request->execute();
561
-		$endTime = microtime( true );
560
+		$endTime = microtime(true);
562 561
 		$this->dataFactory->timing(
563 562
 			'wikibase.quality.constraints.sparql.timing',
564
-			( $endTime - $startTime ) * 1000
563
+			($endTime - $startTime) * 1000
565 564
 		);
566 565
 
567
-		$maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() );
568
-		if ( $maxAge ) {
569
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' );
566
+		$maxAge = $this->getCacheMaxAge($request->getResponseHeaders());
567
+		if ($maxAge) {
568
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.cached');
570 569
 		}
571 570
 
572
-		if ( $status->isOK() ) {
571
+		if ($status->isOK()) {
573 572
 			$json = $request->getContent();
574
-			$arr = json_decode( $json, true );
573
+			$arr = json_decode($json, true);
575 574
 			return new CachedQueryResults(
576 575
 				$arr,
577 576
 				Metadata::ofCachingMetadata(
578 577
 					$maxAge ?
579
-						CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) :
580
-						CachingMetadata::fresh()
578
+						CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh()
581 579
 				)
582 580
 			);
583 581
 		} else {
584
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' );
582
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.error');
585 583
 
586 584
 			$this->dataFactory->increment(
587 585
 				"wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}"
588 586
 			);
589 587
 
590
-			if ( $this->isTimeout( $request->getContent() ) ) {
588
+			if ($this->isTimeout($request->getContent())) {
591 589
 				$this->dataFactory->increment(
592 590
 					'wikibase.quality.constraints.sparql.error.timeout'
593 591
 				);
Please login to merge, or discard this patch.