Completed
Push — master ( 363a80...f26110 )
by
unknown
09:03 queued 06:34
created
src/ConstraintCheck/Checker/ItemChecker.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -86,18 +86,18 @@  discard block
 block discarded – undo
86 86
 	 * @throws ConstraintParameterException
87 87
 	 * @return CheckResult
88 88
 	 */
89
-	public function checkConstraint( Context $context, Constraint $constraint ) {
90
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
91
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
89
+	public function checkConstraint(Context $context, Constraint $constraint) {
90
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
91
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
92 92
 		}
93 93
 
94 94
 		$parameters = [];
95 95
 		$constraintParameters = $constraint->getConstraintParameters();
96 96
 
97
-		$propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
98
-		$parameters['property'] = [ $propertyId ];
97
+		$propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId());
98
+		$parameters['property'] = [$propertyId];
99 99
 
100
-		$items = $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false );
100
+		$items = $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false);
101 101
 		$parameters['items'] = $items;
102 102
 
103 103
 		/*
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		 *   a) a property only
106 106
 		 *   b) a property and a number of items (each combination of property and item forming an individual claim)
107 107
 		 */
108
-		if ( $items === [] ) {
108
+		if ($items === []) {
109 109
 			$requiredStatement = $this->connectionCheckerHelper->findStatementWithProperty(
110 110
 				$context->getEntity()->getStatements(),
111 111
 				$propertyId
@@ -118,31 +118,31 @@  discard block
 block discarded – undo
118 118
 			);
119 119
 		}
120 120
 
121
-		if ( $requiredStatement !== null ) {
121
+		if ($requiredStatement !== null) {
122 122
 			$status = CheckResult::STATUS_COMPLIANCE;
123 123
 			$message = null;
124 124
 		} else {
125 125
 			$status = CheckResult::STATUS_VIOLATION;
126
-			$message = ( new ViolationMessage( 'wbqc-violation-message-item' ) )
127
-				->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY )
128
-				->withEntityId( $propertyId, Role::PREDICATE )
129
-				->withItemIdSnakValueList( $items, Role::OBJECT );
126
+			$message = (new ViolationMessage('wbqc-violation-message-item'))
127
+				->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY)
128
+				->withEntityId($propertyId, Role::PREDICATE)
129
+				->withItemIdSnakValueList($items, Role::OBJECT);
130 130
 		}
131 131
 
132
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
132
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
133 133
 	}
134 134
 
135
-	public function checkConstraintParameters( Constraint $constraint ) {
135
+	public function checkConstraintParameters(Constraint $constraint) {
136 136
 		$constraintParameters = $constraint->getConstraintParameters();
137 137
 		$exceptions = [];
138 138
 		try {
139
-			$this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
140
-		} catch ( ConstraintParameterException $e ) {
139
+			$this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId());
140
+		} catch (ConstraintParameterException $e) {
141 141
 			$exceptions[] = $e;
142 142
 		}
143 143
 		try {
144
-			$this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false );
145
-		} catch ( ConstraintParameterException $e ) {
144
+			$this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false);
145
+		} catch (ConstraintParameterException $e) {
146 146
 			$exceptions[] = $e;
147 147
 		}
148 148
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/ConstraintParameterParser.php 1 patch
Spacing   +210 added lines, -210 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 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,47 +429,47 @@  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
-							$this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ),
435
-							wfMessage( 'datatypes-type-quantity' )->escaped(),
436
-							wfMessage( 'datatypes-type-time' )->escaped()
434
+							$this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM),
435
+							wfMessage('datatypes-type-quantity')->escaped(),
436
+							wfMessage('datatypes-type-time')->escaped()
437 437
 						)
438 438
 						->escaped()
439 439
 				);
440 440
 		}
441
-		$minimumId = $this->config->get( 'WBQualityConstraintsMinimum' . $configKey . 'Id' );
442
-		$maximumId = $this->config->get( 'WBQualityConstraintsMaximum' . $configKey . 'Id' );
443
-		if ( !array_key_exists( $minimumId, $constraintParameters ) ||
444
-			!array_key_exists( $maximumId, $constraintParameters )
441
+		$minimumId = $this->config->get('WBQualityConstraintsMinimum'.$configKey.'Id');
442
+		$maximumId = $this->config->get('WBQualityConstraintsMaximum'.$configKey.'Id');
443
+		if (!array_key_exists($minimumId, $constraintParameters) ||
444
+			!array_key_exists($maximumId, $constraintParameters)
445 445
 		) {
446 446
 			throw new ConstraintParameterException(
447
-				wfMessage( 'wbqc-violation-message-range-parameters-needed' )
447
+				wfMessage('wbqc-violation-message-range-parameters-needed')
448 448
 					->rawParams(
449
-						wfMessage( 'datatypes-type-' . $type )->escaped(),
450
-						$this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
451
-						$this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY )
449
+						wfMessage('datatypes-type-'.$type)->escaped(),
450
+						$this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY),
451
+						$this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY)
452 452
 					)
453
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
453
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
454 454
 					->escaped()
455 455
 			);
456 456
 		}
457 457
 
458
-		$this->requireSingleParameter( $constraintParameters, $minimumId );
459
-		$this->requireSingleParameter( $constraintParameters, $maximumId );
458
+		$this->requireSingleParameter($constraintParameters, $minimumId);
459
+		$this->requireSingleParameter($constraintParameters, $maximumId);
460 460
 		$parseFunction = $configKey === 'Date' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter';
461
-		$min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId );
462
-		$max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId );
461
+		$min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId);
462
+		$max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId);
463 463
 
464
-		$yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' );
465
-		if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) {
464
+		$yearUnit = $this->config->get('WBQualityConstraintsYearUnit');
465
+		if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) {
466 466
 			throw new ConstraintParameterException(
467
-				wfMessage( 'wbqc-violation-message-range-parameters-one-year' )
467
+				wfMessage('wbqc-violation-message-range-parameters-one-year')
468 468
 					->escaped()
469 469
 			);
470 470
 		}
471 471
 
472
-		return [ $min, $max ];
472
+		return [$min, $max];
473 473
 	}
474 474
 
475 475
 	/**
@@ -479,18 +479,18 @@  discard block
 block discarded – undo
479 479
 	 * @throws ConstraintParameterException
480 480
 	 * @return string
481 481
 	 */
482
-	private function parseStringParameter( array $snakSerialization, $parameterId ) {
483
-		$snak = $this->snakDeserializer->deserialize( $snakSerialization );
484
-		$this->requireValueParameter( $snak, $parameterId );
482
+	private function parseStringParameter(array $snakSerialization, $parameterId) {
483
+		$snak = $this->snakDeserializer->deserialize($snakSerialization);
484
+		$this->requireValueParameter($snak, $parameterId);
485 485
 		$value = $snak->getDataValue();
486
-		if ( $value instanceof StringValue ) {
486
+		if ($value instanceof StringValue) {
487 487
 			return $value->getValue();
488 488
 		} else {
489 489
 			throw new ConstraintParameterException(
490
-				wfMessage( 'wbqc-violation-message-parameter-string' )
490
+				wfMessage('wbqc-violation-message-parameter-string')
491 491
 					->rawParams(
492
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
493
-						$this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE )
492
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
493
+						$this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE)
494 494
 					)
495 495
 					->escaped()
496 496
 			);
@@ -503,15 +503,15 @@  discard block
 block discarded – undo
503 503
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
504 504
 	 * @return string
505 505
 	 */
506
-	public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) {
507
-		$this->checkError( $constraintParameters );
508
-		$namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' );
509
-		if ( !array_key_exists( $namespaceId, $constraintParameters ) ) {
506
+	public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) {
507
+		$this->checkError($constraintParameters);
508
+		$namespaceId = $this->config->get('WBQualityConstraintsNamespaceId');
509
+		if (!array_key_exists($namespaceId, $constraintParameters)) {
510 510
 			return '';
511 511
 		}
512 512
 
513
-		$this->requireSingleParameter( $constraintParameters, $namespaceId );
514
-		return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId );
513
+		$this->requireSingleParameter($constraintParameters, $namespaceId);
514
+		return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId);
515 515
 	}
516 516
 
517 517
 	/**
@@ -520,20 +520,20 @@  discard block
 block discarded – undo
520 520
 	 * @throws ConstraintParameterException if the parameter is invalid or missing
521 521
 	 * @return string
522 522
 	 */
523
-	public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) {
524
-		$this->checkError( $constraintParameters );
525
-		$formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' );
526
-		if ( !array_key_exists( $formatId, $constraintParameters ) ) {
523
+	public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) {
524
+		$this->checkError($constraintParameters);
525
+		$formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId');
526
+		if (!array_key_exists($formatId, $constraintParameters)) {
527 527
 			throw new ConstraintParameterException(
528
-				wfMessage( 'wbqc-violation-message-parameter-needed' )
529
-					->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) )
530
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $formatId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
528
+				wfMessage('wbqc-violation-message-parameter-needed')
529
+					->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM))
530
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($formatId, Role::CONSTRAINT_PARAMETER_PROPERTY))
531 531
 					->escaped()
532 532
 			);
533 533
 		}
534 534
 
535
-		$this->requireSingleParameter( $constraintParameters, $formatId );
536
-		return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId );
535
+		$this->requireSingleParameter($constraintParameters, $formatId);
536
+		return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId);
537 537
 	}
538 538
 
539 539
 	/**
@@ -541,16 +541,16 @@  discard block
 block discarded – undo
541 541
 	 * @throws ConstraintParameterException if the parameter is invalid
542 542
 	 * @return EntityId[]
543 543
 	 */
544
-	public function parseExceptionParameter( array $constraintParameters ) {
545
-		$this->checkError( $constraintParameters );
546
-		$exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' );
547
-		if ( !array_key_exists( $exceptionId, $constraintParameters ) ) {
544
+	public function parseExceptionParameter(array $constraintParameters) {
545
+		$this->checkError($constraintParameters);
546
+		$exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId');
547
+		if (!array_key_exists($exceptionId, $constraintParameters)) {
548 548
 			return [];
549 549
 		}
550 550
 
551 551
 		return array_map(
552
-			function( $snakSerialization ) use ( $exceptionId ) {
553
-				return $this->parseEntityIdParameter( $snakSerialization, $exceptionId );
552
+			function($snakSerialization) use ($exceptionId) {
553
+				return $this->parseEntityIdParameter($snakSerialization, $exceptionId);
554 554
 			},
555 555
 			$constraintParameters[$exceptionId]
556 556
 		);
@@ -561,27 +561,27 @@  discard block
 block discarded – undo
561 561
 	 * @throws ConstraintParameterException if the parameter is invalid
562 562
 	 * @return string|null 'mandatory' or null
563 563
 	 */
564
-	public function parseConstraintStatusParameter( array $constraintParameters ) {
565
-		$this->checkError( $constraintParameters );
566
-		$constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' );
567
-		if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) {
564
+	public function parseConstraintStatusParameter(array $constraintParameters) {
565
+		$this->checkError($constraintParameters);
566
+		$constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId');
567
+		if (!array_key_exists($constraintStatusId, $constraintParameters)) {
568 568
 			return null;
569 569
 		}
570 570
 
571
-		$mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' );
572
-		$this->requireSingleParameter( $constraintParameters, $constraintStatusId );
573
-		$snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] );
574
-		$this->requireValueParameter( $snak, $constraintStatusId );
571
+		$mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId');
572
+		$this->requireSingleParameter($constraintParameters, $constraintStatusId);
573
+		$snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]);
574
+		$this->requireValueParameter($snak, $constraintStatusId);
575 575
 		$statusId = $snak->getDataValue()->getEntityId()->getSerialization();
576 576
 
577
-		if ( $statusId === $mandatoryId ) {
577
+		if ($statusId === $mandatoryId) {
578 578
 			return 'mandatory';
579 579
 		} else {
580 580
 			throw new ConstraintParameterException(
581
-				wfMessage( 'wbqc-violation-message-parameter-oneof' )
582
-					->rawParams( $this->constraintParameterRenderer->formatPropertyId( $constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY ) )
583
-					->numParams( 1 )
584
-					->rawParams( $this->constraintParameterRenderer->formatItemIdList( [ $mandatoryId ], Role::CONSTRAINT_PARAMETER_VALUE ) )
581
+				wfMessage('wbqc-violation-message-parameter-oneof')
582
+					->rawParams($this->constraintParameterRenderer->formatPropertyId($constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY))
583
+					->numParams(1)
584
+					->rawParams($this->constraintParameterRenderer->formatItemIdList([$mandatoryId], Role::CONSTRAINT_PARAMETER_VALUE))
585 585
 					->escaped()
586 586
 			);
587 587
 		}
@@ -594,13 +594,13 @@  discard block
 block discarded – undo
594 594
 	 * @return void
595 595
 	 * @throws ConstraintParameterException
596 596
 	 */
597
-	private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) {
598
-		if ( !( $dataValue instanceof MonolingualTextValue ) ) {
597
+	private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) {
598
+		if (!($dataValue instanceof MonolingualTextValue)) {
599 599
 			throw new ConstraintParameterException(
600
-				wfMessage( 'wbqc-violation-message-parameter-monolingualtext' )
600
+				wfMessage('wbqc-violation-message-parameter-monolingualtext')
601 601
 					->rawParams(
602
-						$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ),
603
-						$this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE )
602
+						$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY),
603
+						$this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE)
604 604
 					)
605 605
 					->escaped()
606 606
 			);
@@ -615,26 +615,26 @@  discard block
 block discarded – undo
615 615
 	 * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts
616 616
 	 * @return string[]
617 617
 	 */
618
-	private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) {
618
+	private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) {
619 619
 		$result = [];
620 620
 
621
-		foreach ( $snakSerializations as $snakSerialization ) {
622
-			$snak = $this->snakDeserializer->deserialize( $snakSerialization );
623
-			$this->requireValueParameter( $snak, $parameterId );
621
+		foreach ($snakSerializations as $snakSerialization) {
622
+			$snak = $this->snakDeserializer->deserialize($snakSerialization);
623
+			$this->requireValueParameter($snak, $parameterId);
624 624
 
625 625
 			$value = $snak->getDataValue();
626
-			$this->requireMonolingualTextParameter( $value, $parameterId );
626
+			$this->requireMonolingualTextParameter($value, $parameterId);
627 627
 			/** @var MonolingualTextValue $value */
628 628
 
629 629
 			$code = $value->getLanguageCode();
630
-			if ( array_key_exists( $code, $result ) ) {
630
+			if (array_key_exists($code, $result)) {
631 631
 				throw new ConstraintParameterException(
632
-					wfMessage( 'wbqc-violation-message-parameter-single-per-language' )
632
+					wfMessage('wbqc-violation-message-parameter-single-per-language')
633 633
 						->rawParams(
634
-							$this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY )
634
+							$this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)
635 635
 						)
636 636
 						->plaintextParams(
637
-							Language::fetchLanguageName( $code ),
637
+							Language::fetchLanguageName($code),
638 638
 							$code
639 639
 						)
640 640
 						->escaped()
@@ -653,23 +653,23 @@  discard block
 block discarded – undo
653 653
 	 * @throws ConstraintParameterException if the parameter is invalid
654 654
 	 * @return string|null
655 655
 	 */
656
-	public function parseSyntaxClarificationParameter( array $constraintParameters, Language $language ) {
657
-		$syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' );
656
+	public function parseSyntaxClarificationParameter(array $constraintParameters, Language $language) {
657
+		$syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId');
658 658
 
659
-		if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) {
659
+		if (!array_key_exists($syntaxClarificationId, $constraintParameters)) {
660 660
 			return null;
661 661
 		}
662 662
 
663 663
 		$languageCodes = $language->getFallbackLanguages();
664
-		array_unshift( $languageCodes, $language->getCode() );
664
+		array_unshift($languageCodes, $language->getCode());
665 665
 
666 666
 		$syntaxClarifications = $this->parseMultilingualTextParameter(
667 667
 			$constraintParameters[$syntaxClarificationId],
668 668
 			$syntaxClarificationId
669 669
 		);
670 670
 
671
-		foreach ( $languageCodes as $languageCode ) {
672
-			if ( array_key_exists( $languageCode, $syntaxClarifications ) ) {
671
+		foreach ($languageCodes as $languageCode) {
672
+			if (array_key_exists($languageCode, $syntaxClarifications)) {
673 673
 				return $syntaxClarifications[$languageCode];
674 674
 			}
675 675
 		}
@@ -685,20 +685,20 @@  discard block
 block discarded – undo
685 685
 	 * @throws ConstraintParameterException if the parameter is invalid
686 686
 	 * @return string[]|null Context::TYPE_* constants
687 687
 	 */
688
-	public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) {
689
-		$constraintScopeId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' );
690
-		$mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' );
691
-		$qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' );
692
-		$referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' );
688
+	public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) {
689
+		$constraintScopeId = $this->config->get('WBQualityConstraintsConstraintScopeId');
690
+		$mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId');
691
+		$qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId');
692
+		$referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId');
693 693
 
694
-		if ( !array_key_exists( $constraintScopeId, $constraintParameters ) ) {
694
+		if (!array_key_exists($constraintScopeId, $constraintParameters)) {
695 695
 			return null;
696 696
 		}
697 697
 
698 698
 		$contextTypes = [];
699
-		foreach ( $constraintParameters[$constraintScopeId] as $snakSerialization ) {
700
-			$scopeEntityId = $this->parseEntityIdParameter( $snakSerialization, $constraintScopeId );
701
-			switch ( $scopeEntityId->getSerialization() ) {
699
+		foreach ($constraintParameters[$constraintScopeId] as $snakSerialization) {
700
+			$scopeEntityId = $this->parseEntityIdParameter($snakSerialization, $constraintScopeId);
701
+			switch ($scopeEntityId->getSerialization()) {
702 702
 				case $mainSnakId:
703 703
 					$contextTypes[] = Context::TYPE_STATEMENT;
704 704
 					break;
@@ -710,14 +710,14 @@  discard block
 block discarded – undo
710 710
 					break;
711 711
 				default:
712 712
 					throw new ConstraintParameterException(
713
-						wfMessage( 'wbqc-violation-message-parameter-oneof' )
713
+						wfMessage('wbqc-violation-message-parameter-oneof')
714 714
 							->rawParams(
715 715
 								$this->constraintParameterRenderer->formatPropertyId(
716 716
 									$constraintScopeId,
717 717
 									Role::CONSTRAINT_PARAMETER_PROPERTY
718 718
 								)
719 719
 							)
720
-							->numParams( 3 )
720
+							->numParams(3)
721 721
 							->rawParams(
722 722
 								$this->constraintParameterRenderer->formatItemIdList(
723 723
 									[
@@ -733,12 +733,12 @@  discard block
 block discarded – undo
733 733
 			}
734 734
 		}
735 735
 
736
-		if ( $validScopes !== null ) {
737
-			$invalidScopes = array_diff( $contextTypes, $validScopes );
738
-			if ( $invalidScopes !== [] ) {
739
-				$invalidScope = array_pop( $invalidScopes );
736
+		if ($validScopes !== null) {
737
+			$invalidScopes = array_diff($contextTypes, $validScopes);
738
+			if ($invalidScopes !== []) {
739
+				$invalidScope = array_pop($invalidScopes);
740 740
 				throw new ConstraintParameterException(
741
-					wfMessage( 'wbqc-violation-message-invalid-scope' )
741
+					wfMessage('wbqc-violation-message-invalid-scope')
742 742
 						->rawParams(
743 743
 							$this->constraintParameterRenderer->formatConstraintScope(
744 744
 								$invalidScope,
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 								Role::CONSTRAINT_TYPE_ITEM
750 750
 							)
751 751
 						)
752
-						->numParams( count( $validScopes ) )
752
+						->numParams(count($validScopes))
753 753
 						->rawParams(
754 754
 							$this->constraintParameterRenderer->formatConstraintScopeList(
755 755
 								$validScopes,
Please login to merge, or discard this patch.
src/Api/CheckingResultsBuilder.php 1 patch
Spacing   +30 added lines, -31 removed lines patch added patch discarded remove patch
@@ -83,55 +83,54 @@  discard block
 block discarded – undo
83 83
 	) {
84 84
 		$response = [];
85 85
 		$metadatas = [];
86
-		$statusesFlipped = array_flip( $statuses );
87
-		foreach ( $entityIds as $entityId ) {
86
+		$statusesFlipped = array_flip($statuses);
87
+		foreach ($entityIds as $entityId) {
88 88
 			$results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnEntityId(
89 89
 				$entityId,
90 90
 				$constraintIds,
91
-				[ $this, 'defaultResults' ]
91
+				[$this, 'defaultResults']
92 92
 			);
93 93
 			/** @var CheckResult[] $results */
94
-			$results = array_filter( $results, $this->statusSelected( $statusesFlipped ) );
95
-			foreach ( $results as $result ) {
94
+			$results = array_filter($results, $this->statusSelected($statusesFlipped));
95
+			foreach ($results as $result) {
96 96
 				$metadatas[] = $result->getMetadata();
97
-				$resultArray = $this->checkResultToArray( $result );
98
-				$result->getContext()->storeCheckResultInArray( $resultArray, $response );
97
+				$resultArray = $this->checkResultToArray($result);
98
+				$result->getContext()->storeCheckResultInArray($resultArray, $response);
99 99
 			}
100 100
 		}
101
-		foreach ( $claimIds as $claimId ) {
101
+		foreach ($claimIds as $claimId) {
102 102
 			$results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnClaimId(
103 103
 				$claimId,
104 104
 				$constraintIds,
105
-				[ $this, 'defaultResults' ]
105
+				[$this, 'defaultResults']
106 106
 			);
107
-			$results = array_filter( $results, $this->statusSelected( $statusesFlipped ) );
108
-			foreach ( $results as $result ) {
107
+			$results = array_filter($results, $this->statusSelected($statusesFlipped));
108
+			foreach ($results as $result) {
109 109
 				$metadatas[] = $result->getMetadata();
110
-				$resultArray = $this->checkResultToArray( $result );
111
-				$result->getContext()->storeCheckResultInArray( $resultArray, $response );
110
+				$resultArray = $this->checkResultToArray($result);
111
+				$result->getContext()->storeCheckResultInArray($resultArray, $response);
112 112
 			}
113 113
 		}
114 114
 		return new CachedCheckConstraintsResponse(
115 115
 			$response,
116
-			Metadata::merge( $metadatas )
116
+			Metadata::merge($metadatas)
117 117
 		);
118 118
 	}
119 119
 
120
-	public function defaultResults( Context $context ) {
120
+	public function defaultResults(Context $context) {
121 121
 		return $context->getType() === Context::TYPE_STATEMENT ?
122
-			[ new NullResult( $context ) ] :
123
-			[];
122
+			[new NullResult($context)] : [];
124 123
 	}
125 124
 
126
-	public function statusSelected( array $statusesFlipped ) {
127
-		return function( CheckResult $result ) use ( $statusesFlipped ) {
128
-			return array_key_exists( $result->getStatus(), $statusesFlipped ) ||
125
+	public function statusSelected(array $statusesFlipped) {
126
+		return function(CheckResult $result) use ($statusesFlipped) {
127
+			return array_key_exists($result->getStatus(), $statusesFlipped) ||
129 128
 				$result instanceof NullResult;
130 129
 		};
131 130
 	}
132 131
 
133
-	public function checkResultToArray( CheckResult $checkResult ) {
134
-		if ( $checkResult instanceof NullResult ) {
132
+	public function checkResultToArray(CheckResult $checkResult) {
133
+		if ($checkResult instanceof NullResult) {
135 134
 			return null;
136 135
 		}
137 136
 
@@ -139,10 +138,10 @@  discard block
 block discarded – undo
139 138
 		$typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId();
140 139
 		$constraintPropertyId = $checkResult->getContext()->getSnak()->getPropertyId();
141 140
 
142
-		$title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId );
143
-		$typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) );
141
+		$title = $this->entityTitleLookup->getTitleForId($constraintPropertyId);
142
+		$typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId));
144 143
 		// TODO link to the statement when possible (T169224)
145
-		$link = $title->getFullURL() . '#' . $this->config->get( 'WBQualityConstraintsPropertyConstraintId' );
144
+		$link = $title->getFullURL().'#'.$this->config->get('WBQualityConstraintsPropertyConstraintId');
146 145
 
147 146
 		$constraint = [
148 147
 			'id' => $constraintId,
@@ -151,11 +150,11 @@  discard block
 block discarded – undo
151 150
 			'link' => $link,
152 151
 			'discussLink' => $title->getTalkPage()->getFullURL(),
153 152
 		];
154
-		if ( $this->config->get( 'WBQualityConstraintsIncludeDetailInApi' ) ) {
153
+		if ($this->config->get('WBQualityConstraintsIncludeDetailInApi')) {
155 154
 			$parameters = $checkResult->getParameters();
156 155
 			$constraint += [
157 156
 				'detail' => $parameters,
158
-				'detailHTML' => $this->constraintParameterRenderer->formatParameters( $parameters ),
157
+				'detailHTML' => $this->constraintParameterRenderer->formatParameters($parameters),
159 158
 			];
160 159
 		}
161 160
 
@@ -165,14 +164,14 @@  discard block
 block discarded – undo
165 164
 			'constraint' => $constraint
166 165
 		];
167 166
 		$message = $checkResult->getMessage();
168
-		if ( $message ) {
169
-			$result['message-html'] = $this->violationMessageRenderer->render( $message );
167
+		if ($message) {
168
+			$result['message-html'] = $this->violationMessageRenderer->render($message);
170 169
 		}
171
-		if ( $checkResult->getContext()->getType() === Context::TYPE_STATEMENT ) {
170
+		if ($checkResult->getContext()->getType() === Context::TYPE_STATEMENT) {
172 171
 			$result['claim'] = $checkResult->getContext()->getSnakStatement()->getGuid();
173 172
 		}
174 173
 		$cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray();
175
-		if ( $cachingMetadataArray !== null ) {
174
+		if ($cachingMetadataArray !== null) {
176 175
 			$result['cached'] = $cachingMetadataArray;
177 176
 		}
178 177
 
Please login to merge, or discard this patch.
src/Api/CheckConstraints.php 1 patch
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -77,21 +77,21 @@  discard block
 block discarded – undo
77 77
 	 *
78 78
 	 * @return self
79 79
 	 */
80
-	public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) {
80
+	public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') {
81 81
 		$repo = WikibaseRepo::getDefaultInstance();
82 82
 
83 83
 		$language = $repo->getUserLanguage();
84 84
 		$formatterOptions = new FormatterOptions();
85
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
85
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
86 86
 		$valueFormatterFactory = $repo->getValueFormatterFactory();
87
-		$valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
87
+		$valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
88 88
 
89 89
 		$languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory();
90
-		$labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language );
90
+		$labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language);
91 91
 		$entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory();
92
-		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup );
92
+		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup);
93 93
 		$entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory();
94
-		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup );
94
+		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup);
95 95
 		$config = MediaWikiServices::getInstance()->getMainConfig();
96 96
 		$titleParser = MediaWikiServices::getInstance()->getTitleParser();
97 97
 		$unitConverter = $repo->getUnitConverter();
@@ -124,10 +124,10 @@  discard block
 block discarded – undo
124 124
 			$repo->getEntityTitleLookup(),
125 125
 			$entityIdLabelFormatter,
126 126
 			$constraintParameterRenderer,
127
-			new ViolationMessageRenderer( $entityIdHtmlLinkFormatter, $valueFormatter ),
127
+			new ViolationMessageRenderer($entityIdHtmlLinkFormatter, $valueFormatter),
128 128
 			$config
129 129
 		);
130
-		if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) {
130
+		if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) {
131 131
 			$wikiPageEntityMetaDataAccessor = new WikiPageEntityMetaDataLookup(
132 132
 				$repo->getEntityNamespaceLookup()
133 133
 			);
@@ -138,12 +138,12 @@  discard block
 block discarded – undo
138 138
 				ResultsCache::getDefaultInstance(),
139 139
 				$wikiPageEntityMetaDataAccessor,
140 140
 				$entityIdParser,
141
-				$config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ),
141
+				$config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'),
142 142
 				[
143
-					$config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ),
144
-					$config->get( 'WBQualityConstraintsTypeConstraintId' ),
145
-					$config->get( 'WBQualityConstraintsValueTypeConstraintId' ),
146
-					$config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ),
143
+					$config->get('WBQualityConstraintsCommonsLinkConstraintId'),
144
+					$config->get('WBQualityConstraintsTypeConstraintId'),
145
+					$config->get('WBQualityConstraintsValueTypeConstraintId'),
146
+					$config->get('WBQualityConstraintsDistinctValuesConstraintId'),
147 147
 				],
148 148
 				$dataFactory
149 149
 			);
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 			$prefix,
156 156
 			$repo->getEntityIdParser(),
157 157
 			$repo->getStatementGuidValidator(),
158
-			$repo->getApiHelperFactory( RequestContext::getMain() ),
158
+			$repo->getApiHelperFactory(RequestContext::getMain()),
159 159
 			$resultsBuilder,
160 160
 			$dataFactory
161 161
 		);
@@ -181,11 +181,11 @@  discard block
 block discarded – undo
181 181
 		ResultsBuilder $resultsBuilder,
182 182
 		IBufferingStatsdDataFactory $dataFactory
183 183
 	) {
184
-		parent::__construct( $main, $name, $prefix );
184
+		parent::__construct($main, $name, $prefix);
185 185
 		$this->entityIdParser = $entityIdParser;
186 186
 		$this->statementGuidValidator = $statementGuidValidator;
187
-		$this->resultBuilder = $apiHelperFactory->getResultBuilder( $this );
188
-		$this->errorReporter = $apiHelperFactory->getErrorReporter( $this );
187
+		$this->resultBuilder = $apiHelperFactory->getResultBuilder($this);
188
+		$this->errorReporter = $apiHelperFactory->getErrorReporter($this);
189 189
 		$this->resultsBuilder = $resultsBuilder;
190 190
 		$this->dataFactory = $dataFactory;
191 191
 	}
@@ -200,9 +200,9 @@  discard block
 block discarded – undo
200 200
 
201 201
 		$params = $this->extractRequestParams();
202 202
 
203
-		$this->validateParameters( $params );
204
-		$entityIds = $this->parseEntityIds( $params );
205
-		$claimIds = $this->parseClaimIds( $params );
203
+		$this->validateParameters($params);
204
+		$entityIds = $this->parseEntityIds($params);
205
+		$claimIds = $this->parseClaimIds($params);
206 206
 		$constraintIDs = $params[self::PARAM_CONSTRAINT_ID];
207 207
 		$statuses = $params[self::PARAM_STATUS];
208 208
 
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 			)->getArray()
218 218
 		);
219 219
 		// ensure that result contains the given entity IDs even if they have no statements
220
-		foreach ( $entityIds as $entityId ) {
220
+		foreach ($entityIds as $entityId) {
221 221
 			$this->getResult()->addArrayType(
222
-				[ $this->getModuleName(), $entityId->getSerialization() ],
222
+				[$this->getModuleName(), $entityId->getSerialization()],
223 223
 				'assoc'
224 224
 			);
225 225
 		}
226
-		$this->resultBuilder->markSuccess( 1 );
226
+		$this->resultBuilder->markSuccess(1);
227 227
 	}
228 228
 
229 229
 	/**
@@ -231,24 +231,24 @@  discard block
 block discarded – undo
231 231
 	 *
232 232
 	 * @return EntityId[]
233 233
 	 */
234
-	private function parseEntityIds( array $params ) {
234
+	private function parseEntityIds(array $params) {
235 235
 		$ids = $params[self::PARAM_ID];
236 236
 
237
-		if ( $ids === null ) {
237
+		if ($ids === null) {
238 238
 			return [];
239
-		} elseif ( $ids === [] ) {
239
+		} elseif ($ids === []) {
240 240
 			$this->errorReporter->dieError(
241
-				'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' );
241
+				'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' );
242 242
 		}
243 243
 
244
-		return array_map( function ( $id ) {
244
+		return array_map(function($id) {
245 245
 			try {
246
-				return $this->entityIdParser->parse( $id );
247
-			} catch ( EntityIdParsingException $e ) {
246
+				return $this->entityIdParser->parse($id);
247
+			} catch (EntityIdParsingException $e) {
248 248
 				$this->errorReporter->dieError(
249
-					"Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] );
249
+					"Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] );
250 250
 			}
251
-		}, $ids );
251
+		}, $ids);
252 252
 	}
253 253
 
254 254
 	/**
@@ -256,35 +256,35 @@  discard block
 block discarded – undo
256 256
 	 *
257 257
 	 * @return string[]
258 258
 	 */
259
-	private function parseClaimIds( array $params ) {
259
+	private function parseClaimIds(array $params) {
260 260
 		$ids = $params[self::PARAM_CLAIM_ID];
261 261
 
262
-		if ( $ids === null ) {
262
+		if ($ids === null) {
263 263
 			return [];
264
-		} elseif ( $ids === [] ) {
264
+		} elseif ($ids === []) {
265 265
 			$this->errorReporter->dieError(
266
-				'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' );
266
+				'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' );
267 267
 		}
268 268
 
269
-		foreach ( $ids as $id ) {
270
-			if ( !$this->statementGuidValidator->validate( $id ) ) {
269
+		foreach ($ids as $id) {
270
+			if (!$this->statementGuidValidator->validate($id)) {
271 271
 				$this->errorReporter->dieError(
272
-					"Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] );
272
+					"Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] );
273 273
 			}
274 274
 		}
275 275
 
276 276
 		return $ids;
277 277
 	}
278 278
 
279
-	private function validateParameters( array $params ) {
280
-		if ( $params[self::PARAM_CONSTRAINT_ID] !== null
281
-			 && empty( $params[self::PARAM_CONSTRAINT_ID] )
279
+	private function validateParameters(array $params) {
280
+		if ($params[self::PARAM_CONSTRAINT_ID] !== null
281
+			 && empty($params[self::PARAM_CONSTRAINT_ID])
282 282
 		) {
283 283
 			$paramConstraintId = self::PARAM_CONSTRAINT_ID;
284 284
 			$this->errorReporter->dieError(
285 285
 				"If $paramConstraintId is specified, it must be nonempty.", 'no-data' );
286 286
 		}
287
-		if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) {
287
+		if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) {
288 288
 			$paramId = self::PARAM_ID;
289 289
 			$paramClaimId = self::PARAM_CLAIM_ID;
290 290
 			$this->errorReporter->dieError(
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/ViolationMessageRenderer.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -54,93 +54,93 @@  discard block
 block discarded – undo
54 54
 	 * (temporarily, pre-rendered strings are allowed and returned without changes)
55 55
 	 * @return string
56 56
 	 */
57
-	public function render( $violationMessage ) {
58
-		if ( is_string( $violationMessage ) ) {
57
+	public function render($violationMessage) {
58
+		if (is_string($violationMessage)) {
59 59
 			// TODO remove this once all checkers produce ViolationMessage objects
60 60
 			return $violationMessage;
61 61
 		}
62
-		$message = new Message( $violationMessage->getMessageKey() );
63
-		foreach ( $violationMessage->getArguments() as $argument ) {
64
-			$this->renderArgument( $argument, $message );
62
+		$message = new Message($violationMessage->getMessageKey());
63
+		foreach ($violationMessage->getArguments() as $argument) {
64
+			$this->renderArgument($argument, $message);
65 65
 		}
66 66
 		return $message->escaped();
67 67
 	}
68 68
 
69
-	private function addRole( $value, $role ) {
70
-		if ( $role === null ) {
69
+	private function addRole($value, $role) {
70
+		if ($role === null) {
71 71
 			return $value;
72 72
 		}
73 73
 
74
-		return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' .
75
-			$value .
74
+		return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'.
75
+			$value.
76 76
 			'</span>';
77 77
 	}
78 78
 
79
-	private function renderArgument( array $argument, Message $message ) {
79
+	private function renderArgument(array $argument, Message $message) {
80 80
 		$type = $argument['type'];
81 81
 		$value = $argument['value'];
82 82
 		$role = $argument['role'];
83
-		switch ( $type ) {
83
+		switch ($type) {
84 84
 			case ViolationMessage::TYPE_ENTITY_ID:
85
-				$params = $this->renderEntityId( $value, $role );
85
+				$params = $this->renderEntityId($value, $role);
86 86
 				break;
87 87
 			case ViolationMessage::TYPE_ENTITY_ID_LIST:
88
-				$params = $this->renderEntityIdList( $value, $role );
88
+				$params = $this->renderEntityIdList($value, $role);
89 89
 				break;
90 90
 			case ViolationMessage::TYPE_ITEM_ID_SNAK_VALUE:
91
-				$params = $this->renderItemIdSnakValue( $value, $role );
91
+				$params = $this->renderItemIdSnakValue($value, $role);
92 92
 				break;
93 93
 			case ViolationMessage::TYPE_ITEM_ID_SNAK_VALUE_LIST:
94
-				$params = $this->renderItemIdSnakValueList( $value, $role );
94
+				$params = $this->renderItemIdSnakValueList($value, $role);
95 95
 				break;
96 96
 			case ViolationMessage::TYPE_DATA_VALUE:
97
-				$params = $this->renderDataValue( $value, $role );
97
+				$params = $this->renderDataValue($value, $role);
98 98
 				break;
99 99
 			case ViolationMessage::TYPE_DATA_VALUE_TYPE:
100
-				$params = $this->renderDataValueType( $value, $role );
100
+				$params = $this->renderDataValueType($value, $role);
101 101
 				break;
102 102
 			default:
103 103
 				throw new InvalidArgumentException(
104
-					'Unknown ViolationMessage argument type ' . $type . '!'
104
+					'Unknown ViolationMessage argument type '.$type.'!'
105 105
 				);
106 106
 		}
107
-		$message->params( $params );
107
+		$message->params($params);
108 108
 	}
109 109
 
110
-	private function renderList( array $list, $role, callable $render ) {
111
-		if ( $list === [] ) {
110
+	private function renderList(array $list, $role, callable $render) {
111
+		if ($list === []) {
112 112
 			return [
113
-				Message::numParam( 0 ),
114
-				Message::rawParam( '<ul></ul>' ),
113
+				Message::numParam(0),
114
+				Message::rawParam('<ul></ul>'),
115 115
 			];
116 116
 		}
117 117
 
118
-		if ( count( $list ) > $this->maxListLength ) {
119
-			$list = array_slice( $list, 0, $this->maxListLength );
118
+		if (count($list) > $this->maxListLength) {
119
+			$list = array_slice($list, 0, $this->maxListLength);
120 120
 			$truncated = true;
121 121
 		}
122 122
 
123 123
 		$renderedParams = array_map(
124 124
 			$render,
125 125
 			$list,
126
-			array_fill( 0, count( $list ), $role )
126
+			array_fill(0, count($list), $role)
127 127
 		);
128 128
 		$renderedElements = array_map(
129
-			function ( $param ) {
129
+			function($param) {
130 130
 				return $param['raw'];
131 131
 			},
132 132
 			$renderedParams
133 133
 		);
134
-		if ( isset( $truncated ) ) {
135
-			$renderedElements[] = wfMessage( 'ellipsis' )->escaped();
134
+		if (isset($truncated)) {
135
+			$renderedElements[] = wfMessage('ellipsis')->escaped();
136 136
 		}
137 137
 
138 138
 		return array_merge(
139 139
 			[
140
-				Message::numParam( count( $list ) ),
140
+				Message::numParam(count($list)),
141 141
 				Message::rawParam(
142
-					'<ul><li>' .
143
-					implode( '</li><li>', $renderedElements ) .
142
+					'<ul><li>'.
143
+					implode('</li><li>', $renderedElements).
144 144
 					'</li></ul>'
145 145
 				),
146 146
 			],
@@ -148,35 +148,35 @@  discard block
 block discarded – undo
148 148
 		);
149 149
 	}
150 150
 
151
-	private function renderEntityId( EntityId $entityId, $role ) {
152
-		return Message::rawParam( $this->addRole(
153
-			$this->entityIdFormatter->formatEntityId( $entityId ),
151
+	private function renderEntityId(EntityId $entityId, $role) {
152
+		return Message::rawParam($this->addRole(
153
+			$this->entityIdFormatter->formatEntityId($entityId),
154 154
 			$role
155
-		) );
155
+		));
156 156
 	}
157 157
 
158
-	private function renderEntityIdList( array $entityIdList, $role ) {
159
-		return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] );
158
+	private function renderEntityIdList(array $entityIdList, $role) {
159
+		return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']);
160 160
 	}
161 161
 
162
-	private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) {
163
-		switch ( true ) {
162
+	private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) {
163
+		switch (true) {
164 164
 			case $value->isValue():
165
-				return $this->renderEntityId( $value->getItemId(), $role );
165
+				return $this->renderEntityId($value->getItemId(), $role);
166 166
 			case $value->isSomeValue():
167
-				return Message::rawParam( $this->addRole(
168
-					'<span class="wikibase-snakview-variation-somevaluesnak">' .
169
-						wfMessage( 'wikibase-snakview-snaktypeselector-somevalue' )->escaped() .
167
+				return Message::rawParam($this->addRole(
168
+					'<span class="wikibase-snakview-variation-somevaluesnak">'.
169
+						wfMessage('wikibase-snakview-snaktypeselector-somevalue')->escaped().
170 170
 						'</span>',
171 171
 					$role
172
-				) );
172
+				));
173 173
 			case $value->isNoValue():
174
-				return Message::rawParam( $this->addRole(
175
-					'<span class="wikibase-snakview-variation-novaluesnak">' .
176
-						wfMessage( 'wikibase-snakview-snaktypeselector-novalue' )->escaped() .
174
+				return Message::rawParam($this->addRole(
175
+					'<span class="wikibase-snakview-variation-novaluesnak">'.
176
+						wfMessage('wikibase-snakview-snaktypeselector-novalue')->escaped().
177 177
 						'</span>',
178 178
 					$role
179
-				) );
179
+				));
180 180
 			default:
181 181
 				// @codeCoverageIgnoreStart
182 182
 				throw new LogicException(
@@ -186,33 +186,33 @@  discard block
 block discarded – undo
186 186
 		}
187 187
 	}
188 188
 
189
-	private function renderItemIdSnakValueList( array $valueList, $role ) {
190
-		return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] );
189
+	private function renderItemIdSnakValueList(array $valueList, $role) {
190
+		return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']);
191 191
 	}
192 192
 
193
-	private function renderDataValue( DataValue $dataValue, $role ) {
194
-		return Message::rawParam( $this->addRole(
195
-			$this->dataValueFormatter->format( $dataValue ),
193
+	private function renderDataValue(DataValue $dataValue, $role) {
194
+		return Message::rawParam($this->addRole(
195
+			$this->dataValueFormatter->format($dataValue),
196 196
 			$role
197
-		) );
197
+		));
198 198
 	}
199 199
 
200
-	private function renderDataValueType( $dataValueType, $role ) {
200
+	private function renderDataValueType($dataValueType, $role) {
201 201
 		$messageKeys = [
202 202
 			'string' => 'datatypes-type-string',
203 203
 			'monolingualtext' => 'datatypes-monolingualtext',
204 204
 			'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid',
205 205
 		];
206 206
 
207
-		if ( array_key_exists( $dataValueType, $messageKeys ) ) {
208
-			return Message::rawParam( $this->addRole(
209
-				wfMessage( $messageKeys[$dataValueType] )->escaped(),
207
+		if (array_key_exists($dataValueType, $messageKeys)) {
208
+			return Message::rawParam($this->addRole(
209
+				wfMessage($messageKeys[$dataValueType])->escaped(),
210 210
 				$role
211
-			) );
211
+			));
212 212
 		} else {
213 213
 			// @codeCoverageIgnoreStart
214 214
 			throw new LogicException(
215
-				'Unknown data value type ' . $dataValueType
215
+				'Unknown data value type '.$dataValueType
216 216
 			);
217 217
 			// @codeCoverageIgnoreEnd
218 218
 		}
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/ViolationMessage.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -79,17 +79,17 @@  discard block
 block discarded – undo
79 79
 	public function __construct(
80 80
 		$messageKey
81 81
 	) {
82
-		if ( strpos( $messageKey, self::MESSAGE_KEY_PREFIX ) !== 0 ) {
82
+		if (strpos($messageKey, self::MESSAGE_KEY_PREFIX) !== 0) {
83 83
 			throw new InvalidArgumentException(
84
-				'ViolationMessage key ⧼' .
85
-				$messageKey .
86
-				'⧽ should start with "' .
87
-				self::MESSAGE_KEY_PREFIX .
84
+				'ViolationMessage key ⧼'.
85
+				$messageKey.
86
+				'⧽ should start with "'.
87
+				self::MESSAGE_KEY_PREFIX.
88 88
 				'".'
89 89
 			);
90 90
 		}
91 91
 
92
-		$this->messageKeySuffix = substr( $messageKey, strlen( self::MESSAGE_KEY_PREFIX ) );
92
+		$this->messageKeySuffix = substr($messageKey, strlen(self::MESSAGE_KEY_PREFIX));
93 93
 		$this->arguments = [];
94 94
 	}
95 95
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 * @return string
99 99
 	 */
100 100
 	public function getMessageKey() {
101
-		return self::MESSAGE_KEY_PREFIX . $this->messageKeySuffix;
101
+		return self::MESSAGE_KEY_PREFIX.$this->messageKeySuffix;
102 102
 	}
103 103
 
104 104
 	/**
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 	 * @param mixed $value the value, which should match the $type
117 117
 	 * @return ViolationMessage
118 118
 	 */
119
-	private function withArgument( $type, $role, $value ) {
119
+	private function withArgument($type, $role, $value) {
120 120
 		$ret = clone $this;
121
-		$ret->arguments[] = [ 'type' => $type, 'role' => $role, 'value' => $value ];
121
+		$ret->arguments[] = ['type' => $type, 'role' => $role, 'value' => $value];
122 122
 		return $ret;
123 123
 	}
124 124
 
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
 	 * @param string|null $role one of the Role::* constants
131 131
 	 * @return ViolationMessage
132 132
 	 */
133
-	public function withEntityId( EntityId $entityId, $role = null ) {
134
-		return $this->withArgument( self::TYPE_ENTITY_ID, $role, $entityId );
133
+	public function withEntityId(EntityId $entityId, $role = null) {
134
+		return $this->withArgument(self::TYPE_ENTITY_ID, $role, $entityId);
135 135
 	}
136 136
 
137 137
 	/**
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
 	 * @param string|null $role one of the Role::* constants
149 149
 	 * @return ViolationMessage
150 150
 	 */
151
-	public function withEntityIdList( array $entityIdList, $role = null ) {
152
-		return $this->withArgument( self::TYPE_ENTITY_ID_LIST, $role, $entityIdList );
151
+	public function withEntityIdList(array $entityIdList, $role = null) {
152
+		return $this->withArgument(self::TYPE_ENTITY_ID_LIST, $role, $entityIdList);
153 153
 	}
154 154
 
155 155
 	/**
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
 	 * @param string|null $role one of the Role::* constants
161 161
 	 * @return ViolationMessage
162 162
 	 */
163
-	public function withItemIdSnakValue( ItemIdSnakValue $value, $role = null ) {
164
-		return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value );
163
+	public function withItemIdSnakValue(ItemIdSnakValue $value, $role = null) {
164
+		return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value);
165 165
 	}
166 166
 
167 167
 	/**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
 	 * @param string|null $role one of the Role::* constants
179 179
 	 * @return ViolationMessage
180 180
 	 */
181
-	public function withItemIdSnakValueList( array $valueList, $role = null ) {
182
-		return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList );
181
+	public function withItemIdSnakValueList(array $valueList, $role = null) {
182
+		return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList);
183 183
 	}
184 184
 
185 185
 	/**
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 	 * @param string|null $role one of the Role::* constants
191 191
 	 * @return ViolationMessage
192 192
 	 */
193
-	public function withDataValue( DataValue $dataValue, $role = null ) {
194
-		return $this->withArgument( self::TYPE_DATA_VALUE, $role, $dataValue );
193
+	public function withDataValue(DataValue $dataValue, $role = null) {
194
+		return $this->withArgument(self::TYPE_DATA_VALUE, $role, $dataValue);
195 195
 	}
196 196
 
197 197
 	/**
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
 	 * @param string|null $role one of the Role::* constants
207 207
 	 * @return ViolationMessage
208 208
 	 */
209
-	public function withDataValueType( $dataValueType, $role = null ) {
210
-		return $this->withArgument( self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType );
209
+	public function withDataValueType($dataValueType, $role = null) {
210
+		return $this->withArgument(self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType);
211 211
 	}
212 212
 
213 213
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/FormatChecker.php 1 patch
Spacing   +30 added lines, -31 removed lines patch added patch discarded remove patch
@@ -95,26 +95,26 @@  discard block
 block discarded – undo
95 95
 	 * @throws ConstraintParameterException
96 96
 	 * @return CheckResult
97 97
 	 */
98
-	public function checkConstraint( Context $context, Constraint $constraint ) {
98
+	public function checkConstraint(Context $context, Constraint $constraint) {
99 99
 		$parameters = [];
100 100
 		$constraintParameters = $constraint->getConstraintParameters();
101 101
 
102
-		$format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
103
-		$parameters['pattern'] = [ $format ];
102
+		$format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId());
103
+		$parameters['pattern'] = [$format];
104 104
 
105 105
 		$syntaxClarification = $this->constraintParameterParser->parseSyntaxClarificationParameter(
106 106
 			$constraintParameters,
107 107
 			WikibaseRepo::getDefaultInstance()->getUserLanguage() // TODO make this part of the Context?
108 108
 		);
109
-		if ( $syntaxClarification !== null ) {
110
-			$parameters['clarification'] = [ $syntaxClarification ];
109
+		if ($syntaxClarification !== null) {
110
+			$parameters['clarification'] = [$syntaxClarification];
111 111
 		}
112 112
 
113 113
 		$snak = $context->getSnak();
114 114
 
115
-		if ( !$snak instanceof PropertyValueSnak ) {
115
+		if (!$snak instanceof PropertyValueSnak) {
116 116
 			// nothing to check
117
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
117
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
118 118
 		}
119 119
 
120 120
 		$dataValue = $snak->getDataValue();
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 		 * error handling:
124 124
 		 *   type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext'
125 125
 		 */
126
-		switch ( $dataValue->getType() ) {
126
+		switch ($dataValue->getType()) {
127 127
 			case 'string':
128 128
 				$text = $dataValue->getValue();
129 129
 				break;
@@ -132,56 +132,55 @@  discard block
 block discarded – undo
132 132
 				$text = $dataValue->getText();
133 133
 				break;
134 134
 			default:
135
-				$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) )
136
-					->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM )
137
-					->withDataValueType( 'string' )
138
-					->withDataValueType( 'monolingualtext' );
139
-				return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
135
+				$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2'))
136
+					->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM)
137
+					->withDataValueType('string')
138
+					->withDataValueType('monolingualtext');
139
+				return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
140 140
 		}
141 141
 
142
-		if ( $this->sparqlHelper !== null && $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) {
143
-			if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) {
142
+		if ($this->sparqlHelper !== null && $this->config->get('WBQualityConstraintsCheckFormatConstraint')) {
143
+			if ($this->sparqlHelper->matchesRegularExpression($text, $format)) {
144 144
 				$message = null;
145 145
 				$status = CheckResult::STATUS_COMPLIANCE;
146 146
 			} else {
147 147
 				$message = wfMessage(
148 148
 					$syntaxClarification !== null ?
149
-						'wbqc-violation-message-format-clarification' :
150
-						'wbqc-violation-message-format'
149
+						'wbqc-violation-message-format-clarification' : 'wbqc-violation-message-format'
151 150
 				)->rawParams(
152
-					$this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ),
153
-					$this->constraintParameterRenderer->formatDataValue( new StringValue( $text ), Role::OBJECT ),
154
-					$this->constraintParameterRenderer->formatByRole( Role::CONSTRAINT_PARAMETER_VALUE,
155
-						'<code><nowiki>' . htmlspecialchars( $format ) . '</nowiki></code>' )
151
+					$this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY),
152
+					$this->constraintParameterRenderer->formatDataValue(new StringValue($text), Role::OBJECT),
153
+					$this->constraintParameterRenderer->formatByRole(Role::CONSTRAINT_PARAMETER_VALUE,
154
+						'<code><nowiki>'.htmlspecialchars($format).'</nowiki></code>')
156 155
 				);
157
-				if ( $syntaxClarification !== null ) {
158
-					$message->params( $syntaxClarification );
156
+				if ($syntaxClarification !== null) {
157
+					$message->params($syntaxClarification);
159 158
 				}
160 159
 				$message = $message->escaped();
161 160
 				$status = CheckResult::STATUS_VIOLATION;
162 161
 			}
163 162
 		} else {
164
-			$message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) )
165
-				->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM );
163
+			$message = (new ViolationMessage('wbqc-violation-message-security-reason'))
164
+				->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM);
166 165
 			$status = CheckResult::STATUS_TODO;
167 166
 		}
168
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
167
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
169 168
 	}
170 169
 
171
-	public function checkConstraintParameters( Constraint $constraint ) {
170
+	public function checkConstraintParameters(Constraint $constraint) {
172 171
 		$constraintParameters = $constraint->getConstraintParameters();
173 172
 		$exceptions = [];
174 173
 		try {
175
-			$this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
176
-		} catch ( ConstraintParameterException $e ) {
174
+			$this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId());
175
+		} catch (ConstraintParameterException $e) {
177 176
 			$exceptions[] = $e;
178 177
 		}
179 178
 		try {
180 179
 			$this->constraintParameterParser->parseSyntaxClarificationParameter(
181 180
 				$constraintParameters,
182
-				Language::factory( 'en' ) // errors are reported independent of language requested
181
+				Language::factory('en') // errors are reported independent of language requested
183 182
 			);
184
-		} catch ( ConstraintParameterException $e ) {
183
+		} catch (ConstraintParameterException $e) {
185 184
 			$exceptions[] = $e;
186 185
 		}
187 186
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/SymmetricChecker.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -81,9 +81,9 @@  discard block
 block discarded – undo
81 81
 	 *
82 82
 	 * @return CheckResult
83 83
 	 */
84
-	public function checkConstraint( Context $context, Constraint $constraint ) {
85
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
86
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
84
+	public function checkConstraint(Context $context, Constraint $constraint) {
85
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
86
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
87 87
 		}
88 88
 
89 89
 		$parameters = [];
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
 		$snak = $context->getSnak();
92 92
 		$propertyId = $context->getSnak()->getPropertyId();
93 93
 
94
-		if ( !$snak instanceof PropertyValueSnak ) {
94
+		if (!$snak instanceof PropertyValueSnak) {
95 95
 			// nothing to check
96
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
96
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
97 97
 		}
98 98
 
99 99
 		$dataValue = $snak->getDataValue();
@@ -102,19 +102,19 @@  discard block
 block discarded – undo
102 102
 		 * error handling:
103 103
 		 *   type of $dataValue for properties with 'Symmetric' constraint has to be 'wikibase-entityid'
104 104
 		 */
105
-		if ( $dataValue->getType() !== 'wikibase-entityid' ) {
106
-			$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) )
107
-				->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM )
108
-				->withDataValueType( 'wikibase-entityid' );
109
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
105
+		if ($dataValue->getType() !== 'wikibase-entityid') {
106
+			$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type'))
107
+				->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM)
108
+				->withDataValueType('wikibase-entityid');
109
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
110 110
 		}
111 111
 		/** @var EntityIdValue $dataValue */
112 112
 
113 113
 		$targetEntityId = $dataValue->getEntityId();
114
-		$targetEntity = $this->entityLookup->getEntity( $targetEntityId );
115
-		if ( $targetEntity === null ) {
116
-			$message = new ViolationMessage( 'wbqc-violation-message-target-entity-must-exist' );
117
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
114
+		$targetEntity = $this->entityLookup->getEntity($targetEntityId);
115
+		if ($targetEntity === null) {
116
+			$message = new ViolationMessage('wbqc-violation-message-target-entity-must-exist');
117
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
118 118
 		}
119 119
 
120 120
 		$symmetricStatement = $this->connectionCheckerHelper->findStatementWithPropertyAndEntityIdValue(
@@ -122,23 +122,23 @@  discard block
 block discarded – undo
122 122
 			$propertyId,
123 123
 			$context->getEntity()->getId()
124 124
 		);
125
-		if ( $symmetricStatement !== null ) {
125
+		if ($symmetricStatement !== null) {
126 126
 			$message = null;
127 127
 			$status = CheckResult::STATUS_COMPLIANCE;
128 128
 		} else {
129
-			$message = ( new ViolationMessage( 'wbqc-violation-message-symmetric' ) )
130
-				->withEntityId( $targetEntityId, Role::SUBJECT )
131
-				->withEntityId( $propertyId, Role::PREDICATE )
132
-				->withEntityId( $context->getEntity()->getId(), Role::OBJECT );
129
+			$message = (new ViolationMessage('wbqc-violation-message-symmetric'))
130
+				->withEntityId($targetEntityId, Role::SUBJECT)
131
+				->withEntityId($propertyId, Role::PREDICATE)
132
+				->withEntityId($context->getEntity()->getId(), Role::OBJECT);
133 133
 			$status = CheckResult::STATUS_VIOLATION;
134 134
 		}
135 135
 
136
-		return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) )
137
-			->withMetadata( Metadata::ofDependencyMetadata(
138
-				DependencyMetadata::ofEntityId( $targetEntityId ) ) );
136
+		return (new CheckResult($context, $constraint, $parameters, $status, $message))
137
+			->withMetadata(Metadata::ofDependencyMetadata(
138
+				DependencyMetadata::ofEntityId($targetEntityId) ));
139 139
 	}
140 140
 
141
-	public function checkConstraintParameters( Constraint $constraint ) {
141
+	public function checkConstraintParameters(Constraint $constraint) {
142 142
 		// no parameters
143 143
 		return [];
144 144
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/DiffWithinRangeChecker.php 1 patch
Spacing   +43 added lines, -44 removed lines patch added patch discarded remove patch
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 	 * @throws ConstraintParameterException
85 85
 	 * @return array [ DataValue|null $min, DataValue|null $max, PropertyId $property, array $parameters ]
86 86
 	 */
87
-	private function parseConstraintParameters( Constraint $constraint ) {
88
-		list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter(
87
+	private function parseConstraintParameters(Constraint $constraint) {
88
+		list($min, $max) = $this->constraintParameterParser->parseRangeParameter(
89 89
 			$constraint->getConstraintParameters(),
90 90
 			$constraint->getConstraintTypeItemId(),
91 91
 			'quantity'
@@ -95,15 +95,15 @@  discard block
 block discarded – undo
95 95
 			$constraint->getConstraintTypeItemId()
96 96
 		);
97 97
 
98
-		if ( $min !== null ) {
99
-			$parameters['minimum_quantity'] = [ $min ];
98
+		if ($min !== null) {
99
+			$parameters['minimum_quantity'] = [$min];
100 100
 		}
101
-		if ( $max !== null ) {
102
-			$parameters['maximum_quantity'] = [ $max ];
101
+		if ($max !== null) {
102
+			$parameters['maximum_quantity'] = [$max];
103 103
 		}
104
-		$parameters['property'] = [ $property ];
104
+		$parameters['property'] = [$property];
105 105
 
106
-		return [ $min, $max, $property, $parameters ];
106
+		return [$min, $max, $property, $parameters];
107 107
 	}
108 108
 
109 109
 	/**
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
 	 *
114 114
 	 * @return bool
115 115
 	 */
116
-	private function rangeInYears( $min, $max ) {
117
-		$yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' );
116
+	private function rangeInYears($min, $max) {
117
+		$yearUnit = $this->config->get('WBQualityConstraintsYearUnit');
118 118
 
119
-		if ( $min !== null && $min->getUnit() === $yearUnit ) {
119
+		if ($min !== null && $min->getUnit() === $yearUnit) {
120 120
 			return true;
121 121
 		}
122
-		if ( $max !== null && $max->getUnit() === $yearUnit ) {
122
+		if ($max !== null && $max->getUnit() === $yearUnit) {
123 123
 			return true;
124 124
 		}
125 125
 
@@ -135,59 +135,58 @@  discard block
 block discarded – undo
135 135
 	 * @throws ConstraintParameterException
136 136
 	 * @return CheckResult
137 137
 	 */
138
-	public function checkConstraint( Context $context, Constraint $constraint ) {
139
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
140
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
138
+	public function checkConstraint(Context $context, Constraint $constraint) {
139
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
140
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
141 141
 		}
142 142
 
143 143
 		$parameters = [];
144 144
 
145 145
 		$snak = $context->getSnak();
146 146
 
147
-		if ( !$snak instanceof PropertyValueSnak ) {
147
+		if (!$snak instanceof PropertyValueSnak) {
148 148
 			// nothing to check
149
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
149
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
150 150
 		}
151 151
 
152 152
 		$minuend = $snak->getDataValue();
153 153
 
154 154
 		/** @var PropertyId $property */
155
-		list( $min, $max, $property, $parameters ) = $this->parseConstraintParameters( $constraint );
155
+		list($min, $max, $property, $parameters) = $this->parseConstraintParameters($constraint);
156 156
 
157 157
 		// checks only the first occurrence of the referenced property (this constraint implies a single value constraint on that property)
158
-		foreach ( $context->getSnakGroup() as $otherSnak ) {
158
+		foreach ($context->getSnakGroup() as $otherSnak) {
159 159
 			if (
160
-				!$property->equals( $otherSnak->getPropertyId() ) ||
160
+				!$property->equals($otherSnak->getPropertyId()) ||
161 161
 				!$otherSnak instanceof PropertyValueSnak
162 162
 			) {
163 163
 				continue;
164 164
 			}
165 165
 
166 166
 			$subtrahend = $otherSnak->getDataValue();
167
-			if ( $subtrahend->getType() === $minuend->getType() ) {
168
-				$diff = $this->rangeInYears( $min, $max ) ?
169
-					$this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) :
170
-					$this->rangeCheckerHelper->getDifference( $minuend, $subtrahend );
167
+			if ($subtrahend->getType() === $minuend->getType()) {
168
+				$diff = $this->rangeInYears($min, $max) ?
169
+					$this->rangeCheckerHelper->getDifferenceInYears($minuend, $subtrahend) : $this->rangeCheckerHelper->getDifference($minuend, $subtrahend);
171 170
 
172
-				if ( $this->rangeCheckerHelper->getComparison( $min, $diff ) > 0 ||
173
-					$this->rangeCheckerHelper->getComparison( $diff, $max ) > 0
171
+				if ($this->rangeCheckerHelper->getComparison($min, $diff) > 0 ||
172
+					$this->rangeCheckerHelper->getComparison($diff, $max) > 0
174 173
 				) {
175 174
 					// at least one of $min, $max is set at this point, otherwise there could be no violation
176
-					$openness = $min !== null ? ( $max !== null ? '' : '-rightopen' ) : '-leftopen';
175
+					$openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen';
177 176
 					// possible message keys:
178 177
 					// wbqc-violation-message-diff-within-range
179 178
 					// wbqc-violation-message-diff-within-range-leftopen
180 179
 					// wbqc-violation-message-diff-within-range-rightopen
181
-					$message = ( new ViolationMessage( "wbqc-violation-message-diff-within-range$openness" ) )
182
-						->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE )
183
-						->withDataValue( $minuend, Role::OBJECT )
184
-						->withEntityId( $otherSnak->getPropertyId(), Role::PREDICATE )
185
-						->withDataValue( $subtrahend, Role::OBJECT );
186
-					if ( $min !== null ) {
187
-						$message = $message->withDataValue( $min, Role::OBJECT );
180
+					$message = (new ViolationMessage("wbqc-violation-message-diff-within-range$openness"))
181
+						->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE)
182
+						->withDataValue($minuend, Role::OBJECT)
183
+						->withEntityId($otherSnak->getPropertyId(), Role::PREDICATE)
184
+						->withDataValue($subtrahend, Role::OBJECT);
185
+					if ($min !== null) {
186
+						$message = $message->withDataValue($min, Role::OBJECT);
188 187
 					}
189
-					if ( $max !== null ) {
190
-						$message = $message->withDataValue( $max, Role::OBJECT );
188
+					if ($max !== null) {
189
+						$message = $message->withDataValue($max, Role::OBJECT);
191 190
 					}
192 191
 					$status = CheckResult::STATUS_VIOLATION;
193 192
 				} else {
@@ -195,19 +194,19 @@  discard block
 block discarded – undo
195 194
 					$status = CheckResult::STATUS_COMPLIANCE;
196 195
 				}
197 196
 			} else {
198
-				$message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-must-have-equal-types' );
197
+				$message = new ViolationMessage('wbqc-violation-message-diff-within-range-must-have-equal-types');
199 198
 				$status = CheckResult::STATUS_VIOLATION;
200 199
 			}
201 200
 
202
-			return new CheckResult( $context, $constraint, $parameters, $status, $message );
201
+			return new CheckResult($context, $constraint, $parameters, $status, $message);
203 202
 		}
204 203
 
205
-		$message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-property-must-exist' );
204
+		$message = new ViolationMessage('wbqc-violation-message-diff-within-range-property-must-exist');
206 205
 		$status = CheckResult::STATUS_VIOLATION;
207
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
206
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
208 207
 	}
209 208
 
210
-	public function checkConstraintParameters( Constraint $constraint ) {
209
+	public function checkConstraintParameters(Constraint $constraint) {
211 210
 		$constraintParameters = $constraint->getConstraintParameters();
212 211
 		$exceptions = [];
213 212
 		try {
@@ -216,12 +215,12 @@  discard block
 block discarded – undo
216 215
 				$constraint->getConstraintTypeItemId(),
217 216
 				'quantity'
218 217
 			);
219
-		} catch ( ConstraintParameterException $e ) {
218
+		} catch (ConstraintParameterException $e) {
220 219
 			$exceptions[] = $e;
221 220
 		}
222 221
 		try {
223
-			$this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
224
-		} catch ( ConstraintParameterException $e ) {
222
+			$this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId());
223
+		} catch (ConstraintParameterException $e) {
225 224
 			$exceptions[] = $e;
226 225
 		}
227 226
 		return $exceptions;
Please login to merge, or discard this patch.