@@ -88,15 +88,15 @@ discard block |
||
88 | 88 | * @param array $parameters |
89 | 89 | * @throws ConstraintParameterException |
90 | 90 | */ |
91 | - public function checkError( array $parameters ) { |
|
92 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
91 | + public function checkError(array $parameters) { |
|
92 | + if (array_key_exists('@error', $parameters)) { |
|
93 | 93 | $error = $parameters['@error']; |
94 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
94 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
95 | 95 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
96 | 96 | } else { |
97 | 97 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
98 | 98 | } |
99 | - throw new ConstraintParameterException( new ViolationMessage( $msg ) ); |
|
99 | + throw new ConstraintParameterException(new ViolationMessage($msg)); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | * @param string $parameterId |
107 | 107 | * @throws ConstraintParameterException |
108 | 108 | */ |
109 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
110 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
109 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
110 | + if (count($parameters[$parameterId]) !== 1) { |
|
111 | 111 | throw new ConstraintParameterException( |
112 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) ) |
|
113 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
112 | + (new ViolationMessage('wbqc-violation-message-parameter-single')) |
|
113 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
114 | 114 | ); |
115 | 115 | } |
116 | 116 | } |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | * @return void |
123 | 123 | * @throws ConstraintParameterException |
124 | 124 | */ |
125 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
126 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
125 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
126 | + if (!($snak instanceof PropertyValueSnak)) { |
|
127 | 127 | throw new ConstraintParameterException( |
128 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
129 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
128 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
129 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
130 | 130 | ); |
131 | 131 | } |
132 | 132 | } |
@@ -138,17 +138,17 @@ discard block |
||
138 | 138 | * @throws ConstraintParameterException |
139 | 139 | * @return EntityId |
140 | 140 | */ |
141 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
142 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
143 | - $this->requireValueParameter( $snak, $parameterId ); |
|
141 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
142 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
143 | + $this->requireValueParameter($snak, $parameterId); |
|
144 | 144 | $value = $snak->getDataValue(); |
145 | - if ( $value instanceof EntityIdValue ) { |
|
145 | + if ($value instanceof EntityIdValue) { |
|
146 | 146 | return $value->getEntityId(); |
147 | 147 | } else { |
148 | 148 | throw new ConstraintParameterException( |
149 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) ) |
|
150 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
151 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
149 | + (new ViolationMessage('wbqc-violation-message-parameter-entity')) |
|
150 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
151 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
152 | 152 | ); |
153 | 153 | } |
154 | 154 | } |
@@ -159,20 +159,20 @@ discard block |
||
159 | 159 | * @throws ConstraintParameterException if the parameter is invalid or missing |
160 | 160 | * @return string[] class entity ID serializations |
161 | 161 | */ |
162 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
163 | - $this->checkError( $constraintParameters ); |
|
164 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
165 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
162 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
163 | + $this->checkError($constraintParameters); |
|
164 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
165 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
166 | 166 | throw new ConstraintParameterException( |
167 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
168 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
169 | - ->withEntityId( new PropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
167 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
168 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
169 | + ->withEntityId(new PropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
170 | 170 | ); |
171 | 171 | } |
172 | 172 | |
173 | 173 | $classes = []; |
174 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
175 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
174 | + foreach ($constraintParameters[$classId] as $class) { |
|
175 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
176 | 176 | } |
177 | 177 | return $classes; |
178 | 178 | } |
@@ -183,23 +183,23 @@ discard block |
||
183 | 183 | * @throws ConstraintParameterException if the parameter is invalid or missing |
184 | 184 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
185 | 185 | */ |
186 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
187 | - $this->checkError( $constraintParameters ); |
|
188 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
189 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
186 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
187 | + $this->checkError($constraintParameters); |
|
188 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
189 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
190 | 190 | throw new ConstraintParameterException( |
191 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
192 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
193 | - ->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
191 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
192 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
193 | + ->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
194 | 194 | ); |
195 | 195 | } |
196 | 196 | |
197 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
198 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
199 | - $instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ); |
|
200 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ); |
|
201 | - $instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ); |
|
202 | - switch ( $relationEntityId ) { |
|
197 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
198 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
199 | + $instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId'); |
|
200 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId'); |
|
201 | + $instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId'); |
|
202 | + switch ($relationEntityId) { |
|
203 | 203 | case $instanceId: |
204 | 204 | return 'instance'; |
205 | 205 | case $subclassId: |
@@ -208,13 +208,13 @@ discard block |
||
208 | 208 | return 'instanceOrSubclass'; |
209 | 209 | default: |
210 | 210 | throw new ConstraintParameterException( |
211 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
212 | - ->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
211 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
212 | + ->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
213 | 213 | ->withEntityIdList( |
214 | 214 | [ |
215 | - new ItemId( $instanceId ), |
|
216 | - new ItemId( $subclassId ), |
|
217 | - new ItemId( $instanceOrSubclassId ), |
|
215 | + new ItemId($instanceId), |
|
216 | + new ItemId($subclassId), |
|
217 | + new ItemId($instanceOrSubclassId), |
|
218 | 218 | ], |
219 | 219 | Role::CONSTRAINT_PARAMETER_VALUE |
220 | 220 | ) |
@@ -229,20 +229,20 @@ discard block |
||
229 | 229 | * @throws ConstraintParameterException |
230 | 230 | * @return PropertyId |
231 | 231 | */ |
232 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
233 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
234 | - $this->requireValueParameter( $snak, $parameterId ); |
|
232 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
233 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
234 | + $this->requireValueParameter($snak, $parameterId); |
|
235 | 235 | $value = $snak->getDataValue(); |
236 | - if ( $value instanceof EntityIdValue ) { |
|
236 | + if ($value instanceof EntityIdValue) { |
|
237 | 237 | $id = $value->getEntityId(); |
238 | - if ( $id instanceof PropertyId ) { |
|
238 | + if ($id instanceof PropertyId) { |
|
239 | 239 | return $id; |
240 | 240 | } |
241 | 241 | } |
242 | 242 | throw new ConstraintParameterException( |
243 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) ) |
|
244 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
245 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
243 | + (new ViolationMessage('wbqc-violation-message-parameter-property')) |
|
244 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
245 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
246 | 246 | ); |
247 | 247 | } |
248 | 248 | |
@@ -253,32 +253,32 @@ discard block |
||
253 | 253 | * @throws ConstraintParameterException if the parameter is invalid or missing |
254 | 254 | * @return PropertyId |
255 | 255 | */ |
256 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
257 | - $this->checkError( $constraintParameters ); |
|
258 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
259 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
256 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
257 | + $this->checkError($constraintParameters); |
|
258 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
259 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
260 | 260 | throw new ConstraintParameterException( |
261 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
262 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
263 | - ->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
261 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
262 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
263 | + ->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
264 | 264 | ); |
265 | 265 | } |
266 | 266 | |
267 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
268 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
267 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
268 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
269 | 269 | } |
270 | 270 | |
271 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
271 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
272 | 272 | $dataValue = $snak->getDataValue(); |
273 | - if ( $dataValue instanceof EntityIdValue && |
|
273 | + if ($dataValue instanceof EntityIdValue && |
|
274 | 274 | $dataValue->getEntityId() instanceof ItemId |
275 | 275 | ) { |
276 | - return ItemIdSnakValue::fromItemId( $dataValue->getEntityId() ); |
|
276 | + return ItemIdSnakValue::fromItemId($dataValue->getEntityId()); |
|
277 | 277 | } else { |
278 | 278 | throw new ConstraintParameterException( |
279 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
280 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
281 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
279 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
280 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
281 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
282 | 282 | ); |
283 | 283 | } |
284 | 284 | } |
@@ -290,15 +290,15 @@ discard block |
||
290 | 290 | * @throws ConstraintParameterException if the parameter is invalid or missing |
291 | 291 | * @return ItemIdSnakValue[] array of values |
292 | 292 | */ |
293 | - public function parseItemsParameter( array $constraintParameters, $constraintTypeItemId, $required ) { |
|
294 | - $this->checkError( $constraintParameters ); |
|
295 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
296 | - if ( !array_key_exists( $qualifierId, $constraintParameters ) ) { |
|
297 | - if ( $required ) { |
|
293 | + public function parseItemsParameter(array $constraintParameters, $constraintTypeItemId, $required) { |
|
294 | + $this->checkError($constraintParameters); |
|
295 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
296 | + if (!array_key_exists($qualifierId, $constraintParameters)) { |
|
297 | + if ($required) { |
|
298 | 298 | throw new ConstraintParameterException( |
299 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
300 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
301 | - ->withEntityId( new PropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
299 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
300 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
301 | + ->withEntityId(new PropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
302 | 302 | ); |
303 | 303 | } else { |
304 | 304 | return []; |
@@ -306,11 +306,11 @@ discard block |
||
306 | 306 | } |
307 | 307 | |
308 | 308 | $values = []; |
309 | - foreach ( $constraintParameters[$qualifierId] as $parameter ) { |
|
310 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
311 | - switch ( true ) { |
|
309 | + foreach ($constraintParameters[$qualifierId] as $parameter) { |
|
310 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
311 | + switch (true) { |
|
312 | 312 | case $snak instanceof PropertyValueSnak: |
313 | - $values[] = $this->parseItemIdParameter( $snak, $qualifierId ); |
|
313 | + $values[] = $this->parseItemIdParameter($snak, $qualifierId); |
|
314 | 314 | break; |
315 | 315 | case $snak instanceof PropertySomeValueSnak: |
316 | 316 | $values[] = ItemIdSnakValue::someValue(); |
@@ -329,27 +329,27 @@ discard block |
||
329 | 329 | * @throws ConstraintParameterException if the parameter is invalid or missing |
330 | 330 | * @return PropertyId[] |
331 | 331 | */ |
332 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
333 | - $this->checkError( $constraintParameters ); |
|
334 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
335 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
332 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
333 | + $this->checkError($constraintParameters); |
|
334 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
335 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
336 | 336 | throw new ConstraintParameterException( |
337 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
338 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
339 | - ->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
337 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
338 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
339 | + ->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
340 | 340 | ); |
341 | 341 | } |
342 | 342 | |
343 | 343 | $parameters = $constraintParameters[$propertyId]; |
344 | - if ( count( $parameters ) === 1 && |
|
345 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
344 | + if (count($parameters) === 1 && |
|
345 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
346 | 346 | ) { |
347 | 347 | return []; |
348 | 348 | } |
349 | 349 | |
350 | 350 | $properties = []; |
351 | - foreach ( $parameters as $parameter ) { |
|
352 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
351 | + foreach ($parameters as $parameter) { |
|
352 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
353 | 353 | } |
354 | 354 | return $properties; |
355 | 355 | } |
@@ -360,16 +360,16 @@ discard block |
||
360 | 360 | * @throws ConstraintParameterException |
361 | 361 | * @return DataValue|null |
362 | 362 | */ |
363 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
364 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
365 | - if ( $snak instanceof PropertyValueSnak ) { |
|
363 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
364 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
365 | + if ($snak instanceof PropertyValueSnak) { |
|
366 | 366 | return $snak->getDataValue(); |
367 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
367 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
368 | 368 | return null; |
369 | 369 | } else { |
370 | 370 | throw new ConstraintParameterException( |
371 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
372 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
371 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
372 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
373 | 373 | ); |
374 | 374 | } |
375 | 375 | } |
@@ -379,10 +379,10 @@ discard block |
||
379 | 379 | * @param string $parameterId |
380 | 380 | * @return DataValue|null |
381 | 381 | */ |
382 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
382 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
383 | 383 | try { |
384 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
385 | - } catch ( ConstraintParameterException $e ) { |
|
384 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
385 | + } catch (ConstraintParameterException $e) { |
|
386 | 386 | // unknown value means “now” |
387 | 387 | return new NowValue(); |
388 | 388 | } |
@@ -395,14 +395,14 @@ discard block |
||
395 | 395 | * @param string $unit |
396 | 396 | * @return bool |
397 | 397 | */ |
398 | - private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) { |
|
399 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
400 | - !( $max instanceof UnboundedQuantityValue ) |
|
398 | + private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) { |
|
399 | + if (!($min instanceof UnboundedQuantityValue) || |
|
400 | + !($max instanceof UnboundedQuantityValue) |
|
401 | 401 | ) { |
402 | 402 | return false; |
403 | 403 | } |
404 | 404 | |
405 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
405 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | /** |
@@ -415,42 +415,42 @@ discard block |
||
415 | 415 | * @throws ConstraintParameterException if the parameter is invalid or missing |
416 | 416 | * @return DataValue[] if the parameter is invalid or missing |
417 | 417 | */ |
418 | - private function parseRangeParameter( array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type ) { |
|
419 | - $this->checkError( $constraintParameters ); |
|
420 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
421 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
418 | + private function parseRangeParameter(array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type) { |
|
419 | + $this->checkError($constraintParameters); |
|
420 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
421 | + !array_key_exists($maximumId, $constraintParameters) |
|
422 | 422 | ) { |
423 | 423 | throw new ConstraintParameterException( |
424 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) ) |
|
425 | - ->withDataValueType( $type ) |
|
426 | - ->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
427 | - ->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
428 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
424 | + (new ViolationMessage('wbqc-violation-message-range-parameters-needed')) |
|
425 | + ->withDataValueType($type) |
|
426 | + ->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
427 | + ->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
428 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
429 | 429 | ); |
430 | 430 | } |
431 | 431 | |
432 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
433 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
432 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
433 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
434 | 434 | $parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
435 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
436 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
435 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
436 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
437 | 437 | |
438 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
439 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
438 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
439 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
440 | 440 | throw new ConstraintParameterException( |
441 | - new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
441 | + new ViolationMessage('wbqc-violation-message-range-parameters-one-year') |
|
442 | 442 | ); |
443 | 443 | } |
444 | - if ( $min === null && $max === null || |
|
445 | - $min !== null && $max !== null && $min->equals( $max ) ) { |
|
444 | + if ($min === null && $max === null || |
|
445 | + $min !== null && $max !== null && $min->equals($max)) { |
|
446 | 446 | throw new ConstraintParameterException( |
447 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) ) |
|
448 | - ->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
449 | - ->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
447 | + (new ViolationMessage('wbqc-violation-message-range-parameters-same')) |
|
448 | + ->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
449 | + ->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
450 | 450 | ); |
451 | 451 | } |
452 | 452 | |
453 | - return [ $min, $max ]; |
|
453 | + return [$min, $max]; |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -460,11 +460,11 @@ discard block |
||
460 | 460 | * @throws ConstraintParameterException if the parameter is invalid or missing |
461 | 461 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
462 | 462 | */ |
463 | - public function parseQuantityRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
463 | + public function parseQuantityRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
464 | 464 | return $this->parseRangeParameter( |
465 | 465 | $constraintParameters, |
466 | - $this->config->get( 'WBQualityConstraintsMinimumQuantityId' ), |
|
467 | - $this->config->get( 'WBQualityConstraintsMaximumQuantityId' ), |
|
466 | + $this->config->get('WBQualityConstraintsMinimumQuantityId'), |
|
467 | + $this->config->get('WBQualityConstraintsMaximumQuantityId'), |
|
468 | 468 | $constraintTypeItemId, |
469 | 469 | 'quantity' |
470 | 470 | ); |
@@ -477,11 +477,11 @@ discard block |
||
477 | 477 | * @throws ConstraintParameterException if the parameter is invalid or missing |
478 | 478 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
479 | 479 | */ |
480 | - public function parseTimeRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
480 | + public function parseTimeRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
481 | 481 | return $this->parseRangeParameter( |
482 | 482 | $constraintParameters, |
483 | - $this->config->get( 'WBQualityConstraintsMinimumDateId' ), |
|
484 | - $this->config->get( 'WBQualityConstraintsMaximumDateId' ), |
|
483 | + $this->config->get('WBQualityConstraintsMinimumDateId'), |
|
484 | + $this->config->get('WBQualityConstraintsMaximumDateId'), |
|
485 | 485 | $constraintTypeItemId, |
486 | 486 | 'time' |
487 | 487 | ); |
@@ -494,17 +494,17 @@ discard block |
||
494 | 494 | * @throws ConstraintParameterException |
495 | 495 | * @return string |
496 | 496 | */ |
497 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
498 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
499 | - $this->requireValueParameter( $snak, $parameterId ); |
|
497 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
498 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
499 | + $this->requireValueParameter($snak, $parameterId); |
|
500 | 500 | $value = $snak->getDataValue(); |
501 | - if ( $value instanceof StringValue ) { |
|
501 | + if ($value instanceof StringValue) { |
|
502 | 502 | return $value->getValue(); |
503 | 503 | } else { |
504 | 504 | throw new ConstraintParameterException( |
505 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) ) |
|
506 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
507 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
505 | + (new ViolationMessage('wbqc-violation-message-parameter-string')) |
|
506 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
507 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
508 | 508 | ); |
509 | 509 | } |
510 | 510 | } |
@@ -515,15 +515,15 @@ discard block |
||
515 | 515 | * @throws ConstraintParameterException if the parameter is invalid or missing |
516 | 516 | * @return string |
517 | 517 | */ |
518 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
519 | - $this->checkError( $constraintParameters ); |
|
520 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
521 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
518 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
519 | + $this->checkError($constraintParameters); |
|
520 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
521 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
522 | 522 | return ''; |
523 | 523 | } |
524 | 524 | |
525 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
526 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
525 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
526 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -532,19 +532,19 @@ discard block |
||
532 | 532 | * @throws ConstraintParameterException if the parameter is invalid or missing |
533 | 533 | * @return string |
534 | 534 | */ |
535 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
536 | - $this->checkError( $constraintParameters ); |
|
537 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
538 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
535 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
536 | + $this->checkError($constraintParameters); |
|
537 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
538 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
539 | 539 | throw new ConstraintParameterException( |
540 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
541 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
542 | - ->withEntityId( new PropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
540 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
541 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
542 | + ->withEntityId(new PropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
543 | 543 | ); |
544 | 544 | } |
545 | 545 | |
546 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
547 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
546 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
547 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | /** |
@@ -552,16 +552,16 @@ discard block |
||
552 | 552 | * @throws ConstraintParameterException if the parameter is invalid |
553 | 553 | * @return EntityId[] |
554 | 554 | */ |
555 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
556 | - $this->checkError( $constraintParameters ); |
|
557 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
558 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
555 | + public function parseExceptionParameter(array $constraintParameters) { |
|
556 | + $this->checkError($constraintParameters); |
|
557 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
558 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
559 | 559 | return []; |
560 | 560 | } |
561 | 561 | |
562 | 562 | return array_map( |
563 | - function( $snakSerialization ) use ( $exceptionId ) { |
|
564 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
563 | + function($snakSerialization) use ($exceptionId) { |
|
564 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
565 | 565 | }, |
566 | 566 | $constraintParameters[$exceptionId] |
567 | 567 | ); |
@@ -572,26 +572,26 @@ discard block |
||
572 | 572 | * @throws ConstraintParameterException if the parameter is invalid |
573 | 573 | * @return string|null 'mandatory' or null |
574 | 574 | */ |
575 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
576 | - $this->checkError( $constraintParameters ); |
|
577 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
578 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
575 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
576 | + $this->checkError($constraintParameters); |
|
577 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
578 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
579 | 579 | return null; |
580 | 580 | } |
581 | 581 | |
582 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
583 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
584 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
585 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
582 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
583 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
584 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
585 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
586 | 586 | $statusId = $snak->getDataValue()->getEntityId()->getSerialization(); |
587 | 587 | |
588 | - if ( $statusId === $mandatoryId ) { |
|
588 | + if ($statusId === $mandatoryId) { |
|
589 | 589 | return 'mandatory'; |
590 | 590 | } else { |
591 | 591 | throw new ConstraintParameterException( |
592 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
593 | - ->withEntityId( new PropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
594 | - ->withEntityIdList( [ new ItemId( $mandatoryId ) ], Role::CONSTRAINT_PARAMETER_VALUE ) |
|
592 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
593 | + ->withEntityId(new PropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
594 | + ->withEntityIdList([new ItemId($mandatoryId)], Role::CONSTRAINT_PARAMETER_VALUE) |
|
595 | 595 | ); |
596 | 596 | } |
597 | 597 | } |
@@ -603,12 +603,12 @@ discard block |
||
603 | 603 | * @return void |
604 | 604 | * @throws ConstraintParameterException |
605 | 605 | */ |
606 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
607 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
606 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
607 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
608 | 608 | throw new ConstraintParameterException( |
609 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) ) |
|
610 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
611 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
609 | + (new ViolationMessage('wbqc-violation-message-parameter-monolingualtext')) |
|
610 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
611 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
612 | 612 | ); |
613 | 613 | } |
614 | 614 | } |
@@ -621,30 +621,30 @@ discard block |
||
621 | 621 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
622 | 622 | * @return MultilingualTextValue |
623 | 623 | */ |
624 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
624 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
625 | 625 | $result = []; |
626 | 626 | |
627 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
628 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
629 | - $this->requireValueParameter( $snak, $parameterId ); |
|
627 | + foreach ($snakSerializations as $snakSerialization) { |
|
628 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
629 | + $this->requireValueParameter($snak, $parameterId); |
|
630 | 630 | |
631 | 631 | $value = $snak->getDataValue(); |
632 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
632 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
633 | 633 | /** @var MonolingualTextValue $value */ |
634 | 634 | |
635 | 635 | $code = $value->getLanguageCode(); |
636 | - if ( array_key_exists( $code, $result ) ) { |
|
636 | + if (array_key_exists($code, $result)) { |
|
637 | 637 | throw new ConstraintParameterException( |
638 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) ) |
|
639 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
640 | - ->withLanguage( $code ) |
|
638 | + (new ViolationMessage('wbqc-violation-message-parameter-single-per-language')) |
|
639 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
640 | + ->withLanguage($code) |
|
641 | 641 | ); |
642 | 642 | } |
643 | 643 | |
644 | 644 | $result[$code] = $value; |
645 | 645 | } |
646 | 646 | |
647 | - return new MultilingualTextValue( $result ); |
|
647 | + return new MultilingualTextValue($result); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | /** |
@@ -652,11 +652,11 @@ discard block |
||
652 | 652 | * @throws ConstraintParameterException if the parameter is invalid |
653 | 653 | * @return MultilingualTextValue |
654 | 654 | */ |
655 | - public function parseSyntaxClarificationParameter( array $constraintParameters ) { |
|
656 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
655 | + public function parseSyntaxClarificationParameter(array $constraintParameters) { |
|
656 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
657 | 657 | |
658 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
659 | - return new MultilingualTextValue( [] ); |
|
658 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
659 | + return new MultilingualTextValue([]); |
|
660 | 660 | } |
661 | 661 | |
662 | 662 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -675,20 +675,20 @@ discard block |
||
675 | 675 | * @throws ConstraintParameterException if the parameter is invalid |
676 | 676 | * @return string[]|null Context::TYPE_* constants |
677 | 677 | */ |
678 | - public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) { |
|
679 | - $constraintScopeId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
680 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ); |
|
681 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ); |
|
682 | - $referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ); |
|
678 | + public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) { |
|
679 | + $constraintScopeId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
680 | + $mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId'); |
|
681 | + $qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId'); |
|
682 | + $referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId'); |
|
683 | 683 | |
684 | - if ( !array_key_exists( $constraintScopeId, $constraintParameters ) ) { |
|
684 | + if (!array_key_exists($constraintScopeId, $constraintParameters)) { |
|
685 | 685 | return null; |
686 | 686 | } |
687 | 687 | |
688 | 688 | $contextTypes = []; |
689 | - foreach ( $constraintParameters[$constraintScopeId] as $snakSerialization ) { |
|
690 | - $scopeEntityId = $this->parseEntityIdParameter( $snakSerialization, $constraintScopeId ); |
|
691 | - switch ( $scopeEntityId->getSerialization() ) { |
|
689 | + foreach ($constraintParameters[$constraintScopeId] as $snakSerialization) { |
|
690 | + $scopeEntityId = $this->parseEntityIdParameter($snakSerialization, $constraintScopeId); |
|
691 | + switch ($scopeEntityId->getSerialization()) { |
|
692 | 692 | case $mainSnakId: |
693 | 693 | $contextTypes[] = Context::TYPE_STATEMENT; |
694 | 694 | break; |
@@ -700,13 +700,13 @@ discard block |
||
700 | 700 | break; |
701 | 701 | default: |
702 | 702 | throw new ConstraintParameterException( |
703 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
704 | - ->withEntityId( new PropertyId( $constraintScopeId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
703 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
704 | + ->withEntityId(new PropertyId($constraintScopeId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
705 | 705 | ->withEntityIdList( |
706 | 706 | [ |
707 | - new ItemId( $mainSnakId ), |
|
708 | - new ItemId( $qualifiersId ), |
|
709 | - new ItemId( $referencesId ), |
|
707 | + new ItemId($mainSnakId), |
|
708 | + new ItemId($qualifiersId), |
|
709 | + new ItemId($referencesId), |
|
710 | 710 | ], |
711 | 711 | Role::CONSTRAINT_PARAMETER_VALUE |
712 | 712 | ) |
@@ -714,15 +714,15 @@ discard block |
||
714 | 714 | } |
715 | 715 | } |
716 | 716 | |
717 | - if ( $validScopes !== null ) { |
|
718 | - $invalidScopes = array_diff( $contextTypes, $validScopes ); |
|
719 | - if ( $invalidScopes !== [] ) { |
|
720 | - $invalidScope = array_pop( $invalidScopes ); |
|
717 | + if ($validScopes !== null) { |
|
718 | + $invalidScopes = array_diff($contextTypes, $validScopes); |
|
719 | + if ($invalidScopes !== []) { |
|
720 | + $invalidScope = array_pop($invalidScopes); |
|
721 | 721 | throw new ConstraintParameterException( |
722 | - ( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) ) |
|
723 | - ->withConstraintScope( $invalidScope, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
724 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
725 | - ->withConstraintScopeList( $validScopes, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
722 | + (new ViolationMessage('wbqc-violation-message-invalid-scope')) |
|
723 | + ->withConstraintScope($invalidScope, Role::CONSTRAINT_PARAMETER_VALUE) |
|
724 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
725 | + ->withConstraintScopeList($validScopes, Role::CONSTRAINT_PARAMETER_VALUE) |
|
726 | 726 | ); |
727 | 727 | } |
728 | 728 | } |
@@ -736,15 +736,15 @@ discard block |
||
736 | 736 | * @param ItemId $unitId |
737 | 737 | * @return string unit |
738 | 738 | */ |
739 | - private function parseUnitParameter( ItemId $unitId ) { |
|
739 | + private function parseUnitParameter(ItemId $unitId) { |
|
740 | 740 | $unitRepositoryName = $unitId->getRepositoryName(); |
741 | - if ( !array_key_exists( $unitRepositoryName, $this->conceptBaseUris ) ) { |
|
741 | + if (!array_key_exists($unitRepositoryName, $this->conceptBaseUris)) { |
|
742 | 742 | throw new LogicException( |
743 | - 'No base URI for concept URI for repository: ' . $unitRepositoryName |
|
743 | + 'No base URI for concept URI for repository: '.$unitRepositoryName |
|
744 | 744 | ); |
745 | 745 | } |
746 | 746 | $baseUri = $this->conceptBaseUris[$unitRepositoryName]; |
747 | - return $baseUri . $unitId->getSerialization(); |
|
747 | + return $baseUri.$unitId->getSerialization(); |
|
748 | 748 | } |
749 | 749 | |
750 | 750 | /** |
@@ -754,23 +754,23 @@ discard block |
||
754 | 754 | * @return UnitsParameter |
755 | 755 | * @throws ConstraintParameterException |
756 | 756 | */ |
757 | - private function parseUnitItem( ItemIdSnakValue $item ) { |
|
758 | - switch ( true ) { |
|
757 | + private function parseUnitItem(ItemIdSnakValue $item) { |
|
758 | + switch (true) { |
|
759 | 759 | case $item->isValue(): |
760 | - $unit = $this->parseUnitParameter( $item->getItemId() ); |
|
760 | + $unit = $this->parseUnitParameter($item->getItemId()); |
|
761 | 761 | return new UnitsParameter( |
762 | - [ $item->getItemId() ], |
|
763 | - [ UnboundedQuantityValue::newFromNumber( 1, $unit ) ], |
|
762 | + [$item->getItemId()], |
|
763 | + [UnboundedQuantityValue::newFromNumber(1, $unit)], |
|
764 | 764 | false |
765 | 765 | ); |
766 | 766 | case $item->isSomeValue(): |
767 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
767 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
768 | 768 | throw new ConstraintParameterException( |
769 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
770 | - ->withEntityId( new PropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
769 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
770 | + ->withEntityId(new PropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
771 | 771 | ); |
772 | 772 | case $item->isNoValue(): |
773 | - return new UnitsParameter( [], [], true ); |
|
773 | + return new UnitsParameter([], [], true); |
|
774 | 774 | } |
775 | 775 | } |
776 | 776 | |
@@ -780,26 +780,26 @@ discard block |
||
780 | 780 | * @throws ConstraintParameterException if the parameter is invalid or missing |
781 | 781 | * @return UnitsParameter |
782 | 782 | */ |
783 | - public function parseUnitsParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
784 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
783 | + public function parseUnitsParameter(array $constraintParameters, $constraintTypeItemId) { |
|
784 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
785 | 785 | $unitItems = []; |
786 | 786 | $unitQuantities = []; |
787 | 787 | $unitlessAllowed = false; |
788 | 788 | |
789 | - foreach ( $items as $item ) { |
|
790 | - $unit = $this->parseUnitItem( $item ); |
|
791 | - $unitItems = array_merge( $unitItems, $unit->getUnitItemIds() ); |
|
792 | - $unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() ); |
|
789 | + foreach ($items as $item) { |
|
790 | + $unit = $this->parseUnitItem($item); |
|
791 | + $unitItems = array_merge($unitItems, $unit->getUnitItemIds()); |
|
792 | + $unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities()); |
|
793 | 793 | $unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed(); |
794 | 794 | } |
795 | 795 | |
796 | - if ( $unitQuantities === [] && !$unitlessAllowed ) { |
|
796 | + if ($unitQuantities === [] && !$unitlessAllowed) { |
|
797 | 797 | throw new LogicException( |
798 | 798 | 'The "units" parameter is required, and yet we seem to be missing any allowed unit' |
799 | 799 | ); |
800 | 800 | } |
801 | 801 | |
802 | - return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed ); |
|
802 | + return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed); |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | /** |
@@ -809,41 +809,41 @@ discard block |
||
809 | 809 | * @return EntityTypesParameter |
810 | 810 | * @throws ConstraintParameterException |
811 | 811 | */ |
812 | - private function parseEntityTypeItem( ItemIdSnakValue $item ) { |
|
813 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
812 | + private function parseEntityTypeItem(ItemIdSnakValue $item) { |
|
813 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
814 | 814 | |
815 | - if ( !$item->isValue() ) { |
|
815 | + if (!$item->isValue()) { |
|
816 | 816 | throw new ConstraintParameterException( |
817 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
818 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
817 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
818 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
819 | 819 | ); |
820 | 820 | } |
821 | 821 | |
822 | 822 | $itemId = $item->getItemId(); |
823 | - switch ( $itemId->getSerialization() ) { |
|
824 | - case $this->config->get( 'WBQualityConstraintsWikibaseItemId' ): |
|
823 | + switch ($itemId->getSerialization()) { |
|
824 | + case $this->config->get('WBQualityConstraintsWikibaseItemId'): |
|
825 | 825 | $entityType = 'item'; |
826 | 826 | break; |
827 | - case $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ): |
|
827 | + case $this->config->get('WBQualityConstraintsWikibasePropertyId'): |
|
828 | 828 | $entityType = 'property'; |
829 | 829 | break; |
830 | - case $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ): |
|
830 | + case $this->config->get('WBQualityConstraintsWikibaseLexemeId'): |
|
831 | 831 | $entityType = 'lexeme'; |
832 | 832 | break; |
833 | 833 | default: |
834 | 834 | $allowed = [ |
835 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseItemId' ) ), |
|
836 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) ), |
|
837 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) ), |
|
835 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseItemId')), |
|
836 | + new ItemId($this->config->get('WBQualityConstraintsWikibasePropertyId')), |
|
837 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseLexemeId')), |
|
838 | 838 | ]; |
839 | 839 | throw new ConstraintParameterException( |
840 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
841 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
842 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
840 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
841 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
842 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
843 | 843 | ); |
844 | 844 | } |
845 | 845 | |
846 | - return new EntityTypesParameter( [ $entityType ], [ $itemId ] ); |
|
846 | + return new EntityTypesParameter([$entityType], [$itemId]); |
|
847 | 847 | } |
848 | 848 | |
849 | 849 | /** |
@@ -852,27 +852,27 @@ discard block |
||
852 | 852 | * @throws ConstraintParameterException if the parameter is invalid or missing |
853 | 853 | * @return EntityTypesParameter |
854 | 854 | */ |
855 | - public function parseEntityTypesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
855 | + public function parseEntityTypesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
856 | 856 | $entityTypes = []; |
857 | 857 | $entityTypeItemIds = []; |
858 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
858 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
859 | 859 | |
860 | - foreach ( $items as $item ) { |
|
861 | - $entityType = $this->parseEntityTypeItem( $item ); |
|
862 | - $entityTypes = array_merge( $entityTypes, $entityType->getEntityTypes() ); |
|
863 | - $entityTypeItemIds = array_merge( $entityTypeItemIds, $entityType->getEntityTypeItemIds() ); |
|
860 | + foreach ($items as $item) { |
|
861 | + $entityType = $this->parseEntityTypeItem($item); |
|
862 | + $entityTypes = array_merge($entityTypes, $entityType->getEntityTypes()); |
|
863 | + $entityTypeItemIds = array_merge($entityTypeItemIds, $entityType->getEntityTypeItemIds()); |
|
864 | 864 | } |
865 | 865 | |
866 | - if ( empty( $entityTypes ) ) { |
|
866 | + if (empty($entityTypes)) { |
|
867 | 867 | // @codeCoverageIgnoreStart |
868 | 868 | throw new LogicException( |
869 | - 'The "entity types" parameter is required, ' . |
|
869 | + 'The "entity types" parameter is required, '. |
|
870 | 870 | 'and yet we seem to be missing any allowed entity type' |
871 | 871 | ); |
872 | 872 | // @codeCoverageIgnoreEnd |
873 | 873 | } |
874 | 874 | |
875 | - return new EntityTypesParameter( $entityTypes, $entityTypeItemIds ); |
|
875 | + return new EntityTypesParameter($entityTypes, $entityTypeItemIds); |
|
876 | 876 | } |
877 | 877 | |
878 | 878 | /** |
@@ -880,18 +880,18 @@ discard block |
||
880 | 880 | * @throws ConstraintParameterException if the parameter is invalid |
881 | 881 | * @return PropertyId[] |
882 | 882 | */ |
883 | - public function parseSeparatorsParameter( array $constraintParameters ) { |
|
884 | - $separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' ); |
|
883 | + public function parseSeparatorsParameter(array $constraintParameters) { |
|
884 | + $separatorId = $this->config->get('WBQualityConstraintsSeparatorId'); |
|
885 | 885 | |
886 | - if ( !array_key_exists( $separatorId, $constraintParameters ) ) { |
|
886 | + if (!array_key_exists($separatorId, $constraintParameters)) { |
|
887 | 887 | return []; |
888 | 888 | } |
889 | 889 | |
890 | 890 | $parameters = $constraintParameters[$separatorId]; |
891 | 891 | $separators = []; |
892 | 892 | |
893 | - foreach ( $parameters as $parameter ) { |
|
894 | - $separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId ); |
|
893 | + foreach ($parameters as $parameter) { |
|
894 | + $separators[] = $this->parsePropertyIdParameter($parameter, $separatorId); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | return $separators; |