@@ -77,15 +77,15 @@ discard block |
||
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( new ViolationMessage( $msg ) ); |
|
88 | + throw new ConstraintParameterException(new ViolationMessage($msg)); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -95,11 +95,11 @@ discard block |
||
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 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) ) |
|
102 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
101 | + (new ViolationMessage('wbqc-violation-message-parameter-single')) |
|
102 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
103 | 103 | ); |
104 | 104 | } |
105 | 105 | } |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | * @return void |
112 | 112 | * @throws ConstraintParameterException |
113 | 113 | */ |
114 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
115 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
114 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
115 | + if (!($snak instanceof PropertyValueSnak)) { |
|
116 | 116 | throw new ConstraintParameterException( |
117 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
118 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
117 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
118 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
119 | 119 | ); |
120 | 120 | } |
121 | 121 | } |
@@ -127,17 +127,17 @@ discard block |
||
127 | 127 | * @throws ConstraintParameterException |
128 | 128 | * @return EntityId |
129 | 129 | */ |
130 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
131 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
132 | - $this->requireValueParameter( $snak, $parameterId ); |
|
130 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
131 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
132 | + $this->requireValueParameter($snak, $parameterId); |
|
133 | 133 | $value = $snak->getDataValue(); |
134 | - if ( $value instanceof EntityIdValue ) { |
|
134 | + if ($value instanceof EntityIdValue) { |
|
135 | 135 | return $value->getEntityId(); |
136 | 136 | } else { |
137 | 137 | throw new ConstraintParameterException( |
138 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) ) |
|
139 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
140 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
138 | + (new ViolationMessage('wbqc-violation-message-parameter-entity')) |
|
139 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
140 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
141 | 141 | ); |
142 | 142 | } |
143 | 143 | } |
@@ -148,20 +148,20 @@ discard block |
||
148 | 148 | * @throws ConstraintParameterException if the parameter is invalid or missing |
149 | 149 | * @return string[] class entity ID serializations |
150 | 150 | */ |
151 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
152 | - $this->checkError( $constraintParameters ); |
|
153 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
154 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
151 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
152 | + $this->checkError($constraintParameters); |
|
153 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
154 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
155 | 155 | throw new ConstraintParameterException( |
156 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
157 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
158 | - ->withEntityId( new PropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
156 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
157 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
158 | + ->withEntityId(new PropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
159 | 159 | ); |
160 | 160 | } |
161 | 161 | |
162 | 162 | $classes = []; |
163 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
164 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
163 | + foreach ($constraintParameters[$classId] as $class) { |
|
164 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
165 | 165 | } |
166 | 166 | return $classes; |
167 | 167 | } |
@@ -172,23 +172,23 @@ discard block |
||
172 | 172 | * @throws ConstraintParameterException if the parameter is invalid or missing |
173 | 173 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
174 | 174 | */ |
175 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
176 | - $this->checkError( $constraintParameters ); |
|
177 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
178 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
175 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
176 | + $this->checkError($constraintParameters); |
|
177 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
178 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
179 | 179 | throw new ConstraintParameterException( |
180 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
181 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
182 | - ->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
180 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
181 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
182 | + ->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
183 | 183 | ); |
184 | 184 | } |
185 | 185 | |
186 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
187 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
188 | - $instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ); |
|
189 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ); |
|
190 | - $instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ); |
|
191 | - switch ( $relationEntityId->getSerialization() ) { |
|
186 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
187 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
188 | + $instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId'); |
|
189 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId'); |
|
190 | + $instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId'); |
|
191 | + switch ($relationEntityId->getSerialization()) { |
|
192 | 192 | case $instanceId: |
193 | 193 | return 'instance'; |
194 | 194 | case $subclassId: |
@@ -197,13 +197,13 @@ discard block |
||
197 | 197 | return 'instanceOrSubclass'; |
198 | 198 | default: |
199 | 199 | throw new ConstraintParameterException( |
200 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
201 | - ->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
200 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
201 | + ->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
202 | 202 | ->withEntityIdList( |
203 | 203 | [ |
204 | - new ItemId( $instanceId ), |
|
205 | - new ItemId( $subclassId ), |
|
206 | - new ItemId( $instanceOrSubclassId ), |
|
204 | + new ItemId($instanceId), |
|
205 | + new ItemId($subclassId), |
|
206 | + new ItemId($instanceOrSubclassId), |
|
207 | 207 | ], |
208 | 208 | Role::CONSTRAINT_PARAMETER_VALUE |
209 | 209 | ) |
@@ -218,20 +218,20 @@ discard block |
||
218 | 218 | * @throws ConstraintParameterException |
219 | 219 | * @return PropertyId |
220 | 220 | */ |
221 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
222 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
223 | - $this->requireValueParameter( $snak, $parameterId ); |
|
221 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
222 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
223 | + $this->requireValueParameter($snak, $parameterId); |
|
224 | 224 | $value = $snak->getDataValue(); |
225 | - if ( $value instanceof EntityIdValue ) { |
|
225 | + if ($value instanceof EntityIdValue) { |
|
226 | 226 | $id = $value->getEntityId(); |
227 | - if ( $id instanceof PropertyId ) { |
|
227 | + if ($id instanceof PropertyId) { |
|
228 | 228 | return $id; |
229 | 229 | } |
230 | 230 | } |
231 | 231 | throw new ConstraintParameterException( |
232 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) ) |
|
233 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
234 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
232 | + (new ViolationMessage('wbqc-violation-message-parameter-property')) |
|
233 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
234 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
235 | 235 | ); |
236 | 236 | } |
237 | 237 | |
@@ -242,33 +242,33 @@ discard block |
||
242 | 242 | * @throws ConstraintParameterException if the parameter is invalid or missing |
243 | 243 | * @return PropertyId |
244 | 244 | */ |
245 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
246 | - $this->checkError( $constraintParameters ); |
|
247 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
248 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
245 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
246 | + $this->checkError($constraintParameters); |
|
247 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
248 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
249 | 249 | throw new ConstraintParameterException( |
250 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
251 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
252 | - ->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
250 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
251 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
252 | + ->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
253 | 253 | ); |
254 | 254 | } |
255 | 255 | |
256 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
257 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
256 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
257 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
258 | 258 | } |
259 | 259 | |
260 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
260 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
261 | 261 | $dataValue = $snak->getDataValue(); |
262 | - if ( $dataValue instanceof EntityIdValue ) { |
|
262 | + if ($dataValue instanceof EntityIdValue) { |
|
263 | 263 | $entityId = $dataValue->getEntityId(); |
264 | - if ( $entityId instanceof ItemId ) { |
|
265 | - return ItemIdSnakValue::fromItemId( $entityId ); |
|
264 | + if ($entityId instanceof ItemId) { |
|
265 | + return ItemIdSnakValue::fromItemId($entityId); |
|
266 | 266 | } |
267 | 267 | } |
268 | 268 | throw new ConstraintParameterException( |
269 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
270 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
271 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
269 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
270 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
271 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
272 | 272 | ); |
273 | 273 | } |
274 | 274 | |
@@ -286,16 +286,16 @@ discard block |
||
286 | 286 | $required, |
287 | 287 | $parameterId = null |
288 | 288 | ) { |
289 | - $this->checkError( $constraintParameters ); |
|
290 | - if ( $parameterId === null ) { |
|
291 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
289 | + $this->checkError($constraintParameters); |
|
290 | + if ($parameterId === null) { |
|
291 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
292 | 292 | } |
293 | - if ( !array_key_exists( $parameterId, $constraintParameters ) ) { |
|
294 | - if ( $required ) { |
|
293 | + if (!array_key_exists($parameterId, $constraintParameters)) { |
|
294 | + if ($required) { |
|
295 | 295 | throw new ConstraintParameterException( |
296 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
297 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
298 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
296 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
297 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
298 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
299 | 299 | ); |
300 | 300 | } else { |
301 | 301 | return []; |
@@ -303,11 +303,11 @@ discard block |
||
303 | 303 | } |
304 | 304 | |
305 | 305 | $values = []; |
306 | - foreach ( $constraintParameters[$parameterId] as $parameter ) { |
|
307 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
308 | - switch ( true ) { |
|
306 | + foreach ($constraintParameters[$parameterId] as $parameter) { |
|
307 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
308 | + switch (true) { |
|
309 | 309 | case $snak instanceof PropertyValueSnak: |
310 | - $values[] = $this->parseItemIdParameter( $snak, $parameterId ); |
|
310 | + $values[] = $this->parseItemIdParameter($snak, $parameterId); |
|
311 | 311 | break; |
312 | 312 | case $snak instanceof PropertySomeValueSnak: |
313 | 313 | $values[] = ItemIdSnakValue::someValue(); |
@@ -335,13 +335,13 @@ discard block |
||
335 | 335 | bool $required, |
336 | 336 | string $parameterId |
337 | 337 | ): array { |
338 | - return array_map( static function ( ItemIdSnakValue $value ) use ( $parameterId ): ItemId { |
|
339 | - if ( $value->isValue() ) { |
|
338 | + return array_map(static function(ItemIdSnakValue $value) use ($parameterId): ItemId { |
|
339 | + if ($value->isValue()) { |
|
340 | 340 | return $value->getItemId(); |
341 | 341 | } else { |
342 | 342 | throw new ConstraintParameterException( |
343 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
344 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
343 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
344 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
345 | 345 | ); |
346 | 346 | } |
347 | 347 | }, $this->parseItemsParameter( |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | $constraintTypeItemId, |
350 | 350 | $required, |
351 | 351 | $parameterId |
352 | - ) ); |
|
352 | + )); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | /** |
@@ -358,27 +358,27 @@ discard block |
||
358 | 358 | * @throws ConstraintParameterException if the parameter is invalid or missing |
359 | 359 | * @return PropertyId[] |
360 | 360 | */ |
361 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
362 | - $this->checkError( $constraintParameters ); |
|
363 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
364 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
361 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
362 | + $this->checkError($constraintParameters); |
|
363 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
364 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
365 | 365 | throw new ConstraintParameterException( |
366 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
367 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
368 | - ->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
366 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
367 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
368 | + ->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
369 | 369 | ); |
370 | 370 | } |
371 | 371 | |
372 | 372 | $parameters = $constraintParameters[$propertyId]; |
373 | - if ( count( $parameters ) === 1 && |
|
374 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
373 | + if (count($parameters) === 1 && |
|
374 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
375 | 375 | ) { |
376 | 376 | return []; |
377 | 377 | } |
378 | 378 | |
379 | 379 | $properties = []; |
380 | - foreach ( $parameters as $parameter ) { |
|
381 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
380 | + foreach ($parameters as $parameter) { |
|
381 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
382 | 382 | } |
383 | 383 | return $properties; |
384 | 384 | } |
@@ -389,16 +389,16 @@ discard block |
||
389 | 389 | * @throws ConstraintParameterException |
390 | 390 | * @return DataValue|null |
391 | 391 | */ |
392 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
393 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
394 | - if ( $snak instanceof PropertyValueSnak ) { |
|
392 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
393 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
394 | + if ($snak instanceof PropertyValueSnak) { |
|
395 | 395 | return $snak->getDataValue(); |
396 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
396 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
397 | 397 | return null; |
398 | 398 | } else { |
399 | 399 | throw new ConstraintParameterException( |
400 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
401 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
400 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
401 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
402 | 402 | ); |
403 | 403 | } |
404 | 404 | } |
@@ -408,10 +408,10 @@ discard block |
||
408 | 408 | * @param string $parameterId |
409 | 409 | * @return DataValue|null |
410 | 410 | */ |
411 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
411 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
412 | 412 | try { |
413 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
414 | - } catch ( ConstraintParameterException $e ) { |
|
413 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
414 | + } catch (ConstraintParameterException $e) { |
|
415 | 415 | // unknown value means “now” |
416 | 416 | return new NowValue(); |
417 | 417 | } |
@@ -424,14 +424,14 @@ discard block |
||
424 | 424 | * @param string $unit |
425 | 425 | * @return bool |
426 | 426 | */ |
427 | - private function exactlyOneQuantityWithUnit( ?DataValue $min, ?DataValue $max, $unit ) { |
|
428 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
429 | - !( $max instanceof UnboundedQuantityValue ) |
|
427 | + private function exactlyOneQuantityWithUnit(?DataValue $min, ?DataValue $max, $unit) { |
|
428 | + if (!($min instanceof UnboundedQuantityValue) || |
|
429 | + !($max instanceof UnboundedQuantityValue) |
|
430 | 430 | ) { |
431 | 431 | return false; |
432 | 432 | } |
433 | 433 | |
434 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
434 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | /** |
@@ -444,42 +444,42 @@ discard block |
||
444 | 444 | * @throws ConstraintParameterException if the parameter is invalid or missing |
445 | 445 | * @return DataValue[] if the parameter is invalid or missing |
446 | 446 | */ |
447 | - private function parseRangeParameter( array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type ) { |
|
448 | - $this->checkError( $constraintParameters ); |
|
449 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
450 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
447 | + private function parseRangeParameter(array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type) { |
|
448 | + $this->checkError($constraintParameters); |
|
449 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
450 | + !array_key_exists($maximumId, $constraintParameters) |
|
451 | 451 | ) { |
452 | 452 | throw new ConstraintParameterException( |
453 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) ) |
|
454 | - ->withDataValueType( $type ) |
|
455 | - ->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
456 | - ->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
457 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
453 | + (new ViolationMessage('wbqc-violation-message-range-parameters-needed')) |
|
454 | + ->withDataValueType($type) |
|
455 | + ->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
456 | + ->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
457 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
458 | 458 | ); |
459 | 459 | } |
460 | 460 | |
461 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
462 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
461 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
462 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
463 | 463 | $parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
464 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
465 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
464 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
465 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
466 | 466 | |
467 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
468 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
467 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
468 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
469 | 469 | throw new ConstraintParameterException( |
470 | - new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
470 | + new ViolationMessage('wbqc-violation-message-range-parameters-one-year') |
|
471 | 471 | ); |
472 | 472 | } |
473 | - if ( $min === null && $max === null || |
|
474 | - $min !== null && $max !== null && $min->equals( $max ) ) { |
|
473 | + if ($min === null && $max === null || |
|
474 | + $min !== null && $max !== null && $min->equals($max)) { |
|
475 | 475 | throw new ConstraintParameterException( |
476 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) ) |
|
477 | - ->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
478 | - ->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
476 | + (new ViolationMessage('wbqc-violation-message-range-parameters-same')) |
|
477 | + ->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
478 | + ->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
479 | 479 | ); |
480 | 480 | } |
481 | 481 | |
482 | - return [ $min, $max ]; |
|
482 | + return [$min, $max]; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -489,11 +489,11 @@ discard block |
||
489 | 489 | * @throws ConstraintParameterException if the parameter is invalid or missing |
490 | 490 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
491 | 491 | */ |
492 | - public function parseQuantityRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
492 | + public function parseQuantityRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
493 | 493 | return $this->parseRangeParameter( |
494 | 494 | $constraintParameters, |
495 | - $this->config->get( 'WBQualityConstraintsMinimumQuantityId' ), |
|
496 | - $this->config->get( 'WBQualityConstraintsMaximumQuantityId' ), |
|
495 | + $this->config->get('WBQualityConstraintsMinimumQuantityId'), |
|
496 | + $this->config->get('WBQualityConstraintsMaximumQuantityId'), |
|
497 | 497 | $constraintTypeItemId, |
498 | 498 | 'quantity' |
499 | 499 | ); |
@@ -506,11 +506,11 @@ discard block |
||
506 | 506 | * @throws ConstraintParameterException if the parameter is invalid or missing |
507 | 507 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
508 | 508 | */ |
509 | - public function parseTimeRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
509 | + public function parseTimeRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
510 | 510 | return $this->parseRangeParameter( |
511 | 511 | $constraintParameters, |
512 | - $this->config->get( 'WBQualityConstraintsMinimumDateId' ), |
|
513 | - $this->config->get( 'WBQualityConstraintsMaximumDateId' ), |
|
512 | + $this->config->get('WBQualityConstraintsMinimumDateId'), |
|
513 | + $this->config->get('WBQualityConstraintsMaximumDateId'), |
|
514 | 514 | $constraintTypeItemId, |
515 | 515 | 'time' |
516 | 516 | ); |
@@ -523,17 +523,17 @@ discard block |
||
523 | 523 | * @throws ConstraintParameterException |
524 | 524 | * @return string |
525 | 525 | */ |
526 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
527 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
528 | - $this->requireValueParameter( $snak, $parameterId ); |
|
526 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
527 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
528 | + $this->requireValueParameter($snak, $parameterId); |
|
529 | 529 | $value = $snak->getDataValue(); |
530 | - if ( $value instanceof StringValue ) { |
|
530 | + if ($value instanceof StringValue) { |
|
531 | 531 | return $value->getValue(); |
532 | 532 | } else { |
533 | 533 | throw new ConstraintParameterException( |
534 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) ) |
|
535 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
536 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
534 | + (new ViolationMessage('wbqc-violation-message-parameter-string')) |
|
535 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
536 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
537 | 537 | ); |
538 | 538 | } |
539 | 539 | } |
@@ -544,15 +544,15 @@ discard block |
||
544 | 544 | * @throws ConstraintParameterException if the parameter is invalid or missing |
545 | 545 | * @return string |
546 | 546 | */ |
547 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
548 | - $this->checkError( $constraintParameters ); |
|
549 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
550 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
547 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
548 | + $this->checkError($constraintParameters); |
|
549 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
550 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
551 | 551 | return ''; |
552 | 552 | } |
553 | 553 | |
554 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
555 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
554 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
555 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | /** |
@@ -561,19 +561,19 @@ discard block |
||
561 | 561 | * @throws ConstraintParameterException if the parameter is invalid or missing |
562 | 562 | * @return string |
563 | 563 | */ |
564 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
565 | - $this->checkError( $constraintParameters ); |
|
566 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
567 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
564 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
565 | + $this->checkError($constraintParameters); |
|
566 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
567 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
568 | 568 | throw new ConstraintParameterException( |
569 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
570 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
571 | - ->withEntityId( new PropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
569 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
570 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
571 | + ->withEntityId(new PropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
572 | 572 | ); |
573 | 573 | } |
574 | 574 | |
575 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
576 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
575 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
576 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -581,16 +581,16 @@ discard block |
||
581 | 581 | * @throws ConstraintParameterException if the parameter is invalid |
582 | 582 | * @return EntityId[] |
583 | 583 | */ |
584 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
585 | - $this->checkError( $constraintParameters ); |
|
586 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
587 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
584 | + public function parseExceptionParameter(array $constraintParameters) { |
|
585 | + $this->checkError($constraintParameters); |
|
586 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
587 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
588 | 588 | return []; |
589 | 589 | } |
590 | 590 | |
591 | 591 | return array_map( |
592 | - function ( $snakSerialization ) use ( $exceptionId ) { |
|
593 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
592 | + function($snakSerialization) use ($exceptionId) { |
|
593 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
594 | 594 | }, |
595 | 595 | $constraintParameters[$exceptionId] |
596 | 596 | ); |
@@ -601,39 +601,39 @@ discard block |
||
601 | 601 | * @throws ConstraintParameterException if the parameter is invalid |
602 | 602 | * @return string|null 'mandatory', 'suggestion' or null |
603 | 603 | */ |
604 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
605 | - $this->checkError( $constraintParameters ); |
|
606 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
607 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
604 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
605 | + $this->checkError($constraintParameters); |
|
606 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
607 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
608 | 608 | return null; |
609 | 609 | } |
610 | 610 | |
611 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
612 | - $supportedStatuses = [ new ItemId( $mandatoryId ) ]; |
|
613 | - if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) { |
|
614 | - $suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' ); |
|
615 | - $supportedStatuses[] = new ItemId( $suggestionId ); |
|
611 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
612 | + $supportedStatuses = [new ItemId($mandatoryId)]; |
|
613 | + if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) { |
|
614 | + $suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId'); |
|
615 | + $supportedStatuses[] = new ItemId($suggestionId); |
|
616 | 616 | } else { |
617 | 617 | $suggestionId = null; |
618 | 618 | } |
619 | 619 | |
620 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
621 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
622 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
620 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
621 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
622 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
623 | 623 | '@phan-var \Wikibase\DataModel\Snak\PropertyValueSnak $snak'; |
624 | 624 | $dataValue = $snak->getDataValue(); |
625 | 625 | '@phan-var EntityIdValue $dataValue'; |
626 | 626 | $entityId = $dataValue->getEntityId(); |
627 | 627 | $statusId = $entityId->getSerialization(); |
628 | 628 | |
629 | - if ( $statusId === $mandatoryId ) { |
|
629 | + if ($statusId === $mandatoryId) { |
|
630 | 630 | return 'mandatory'; |
631 | - } elseif ( $statusId === $suggestionId ) { |
|
631 | + } elseif ($statusId === $suggestionId) { |
|
632 | 632 | return 'suggestion'; |
633 | 633 | } else { |
634 | 634 | throw new ConstraintParameterException( |
635 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
636 | - ->withEntityId( new PropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
635 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
636 | + ->withEntityId(new PropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
637 | 637 | ->withEntityIdList( |
638 | 638 | $supportedStatuses, |
639 | 639 | Role::CONSTRAINT_PARAMETER_VALUE |
@@ -649,12 +649,12 @@ discard block |
||
649 | 649 | * @return void |
650 | 650 | * @throws ConstraintParameterException |
651 | 651 | */ |
652 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
653 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
652 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
653 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
654 | 654 | throw new ConstraintParameterException( |
655 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) ) |
|
656 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
657 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
655 | + (new ViolationMessage('wbqc-violation-message-parameter-monolingualtext')) |
|
656 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
657 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
658 | 658 | ); |
659 | 659 | } |
660 | 660 | } |
@@ -667,31 +667,31 @@ discard block |
||
667 | 667 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
668 | 668 | * @return MultilingualTextValue |
669 | 669 | */ |
670 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
670 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
671 | 671 | $result = []; |
672 | 672 | |
673 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
674 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
675 | - $this->requireValueParameter( $snak, $parameterId ); |
|
673 | + foreach ($snakSerializations as $snakSerialization) { |
|
674 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
675 | + $this->requireValueParameter($snak, $parameterId); |
|
676 | 676 | |
677 | 677 | $value = $snak->getDataValue(); |
678 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
678 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
679 | 679 | /** @var MonolingualTextValue $value */ |
680 | 680 | '@phan-var MonolingualTextValue $value'; |
681 | 681 | |
682 | 682 | $code = $value->getLanguageCode(); |
683 | - if ( array_key_exists( $code, $result ) ) { |
|
683 | + if (array_key_exists($code, $result)) { |
|
684 | 684 | throw new ConstraintParameterException( |
685 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) ) |
|
686 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
687 | - ->withLanguage( $code ) |
|
685 | + (new ViolationMessage('wbqc-violation-message-parameter-single-per-language')) |
|
686 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
687 | + ->withLanguage($code) |
|
688 | 688 | ); |
689 | 689 | } |
690 | 690 | |
691 | 691 | $result[$code] = $value; |
692 | 692 | } |
693 | 693 | |
694 | - return new MultilingualTextValue( $result ); |
|
694 | + return new MultilingualTextValue($result); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
@@ -699,11 +699,11 @@ discard block |
||
699 | 699 | * @throws ConstraintParameterException if the parameter is invalid |
700 | 700 | * @return MultilingualTextValue |
701 | 701 | */ |
702 | - public function parseSyntaxClarificationParameter( array $constraintParameters ) { |
|
703 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
702 | + public function parseSyntaxClarificationParameter(array $constraintParameters) { |
|
703 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
704 | 704 | |
705 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
706 | - return new MultilingualTextValue( [] ); |
|
705 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
706 | + return new MultilingualTextValue([]); |
|
707 | 707 | } |
708 | 708 | |
709 | 709 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | array $validScopes |
729 | 729 | ) { |
730 | 730 | $contextTypes = []; |
731 | - $parameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
731 | + $parameterId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
732 | 732 | $itemIds = $this->parseItemIdsParameter( |
733 | 733 | $constraintParameters, |
734 | 734 | $constraintTypeItemId, |
@@ -736,22 +736,22 @@ discard block |
||
736 | 736 | $parameterId |
737 | 737 | ); |
738 | 738 | |
739 | - if ( $itemIds === [] ) { |
|
739 | + if ($itemIds === []) { |
|
740 | 740 | return null; |
741 | 741 | } |
742 | 742 | |
743 | - foreach ( $itemIds as $itemId ) { |
|
744 | - $contextTypes[] = $this->parseContextTypeItemId( $itemId, 'constraint scope', $parameterId ); |
|
743 | + foreach ($itemIds as $itemId) { |
|
744 | + $contextTypes[] = $this->parseContextTypeItemId($itemId, 'constraint scope', $parameterId); |
|
745 | 745 | } |
746 | 746 | |
747 | - $invalidScopes = array_diff( $contextTypes, $validScopes ); |
|
748 | - if ( $invalidScopes !== [] ) { |
|
749 | - $invalidScope = array_pop( $invalidScopes ); |
|
747 | + $invalidScopes = array_diff($contextTypes, $validScopes); |
|
748 | + if ($invalidScopes !== []) { |
|
749 | + $invalidScope = array_pop($invalidScopes); |
|
750 | 750 | throw new ConstraintParameterException( |
751 | - ( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) ) |
|
752 | - ->withConstraintScope( $invalidScope, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
753 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
754 | - ->withConstraintScopeList( $validScopes, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
751 | + (new ViolationMessage('wbqc-violation-message-invalid-scope')) |
|
752 | + ->withConstraintScope($invalidScope, Role::CONSTRAINT_PARAMETER_VALUE) |
|
753 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
754 | + ->withConstraintScopeList($validScopes, Role::CONSTRAINT_PARAMETER_VALUE) |
|
755 | 755 | ); |
756 | 756 | } |
757 | 757 | |
@@ -764,8 +764,8 @@ discard block |
||
764 | 764 | * @param ItemId $unitId |
765 | 765 | * @return string unit |
766 | 766 | */ |
767 | - private function parseUnitParameter( ItemId $unitId ) { |
|
768 | - return $this->unitItemConceptBaseUri . $unitId->getSerialization(); |
|
767 | + private function parseUnitParameter(ItemId $unitId) { |
|
768 | + return $this->unitItemConceptBaseUri.$unitId->getSerialization(); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | /** |
@@ -775,23 +775,23 @@ discard block |
||
775 | 775 | * @return UnitsParameter |
776 | 776 | * @throws ConstraintParameterException |
777 | 777 | */ |
778 | - private function parseUnitItem( ItemIdSnakValue $item ) { |
|
779 | - switch ( true ) { |
|
778 | + private function parseUnitItem(ItemIdSnakValue $item) { |
|
779 | + switch (true) { |
|
780 | 780 | case $item->isValue(): |
781 | - $unit = $this->parseUnitParameter( $item->getItemId() ); |
|
781 | + $unit = $this->parseUnitParameter($item->getItemId()); |
|
782 | 782 | return new UnitsParameter( |
783 | - [ $item->getItemId() ], |
|
784 | - [ UnboundedQuantityValue::newFromNumber( 1, $unit ) ], |
|
783 | + [$item->getItemId()], |
|
784 | + [UnboundedQuantityValue::newFromNumber(1, $unit)], |
|
785 | 785 | false |
786 | 786 | ); |
787 | 787 | case $item->isSomeValue(): |
788 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
788 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
789 | 789 | throw new ConstraintParameterException( |
790 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
791 | - ->withEntityId( new PropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
790 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
791 | + ->withEntityId(new PropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
792 | 792 | ); |
793 | 793 | case $item->isNoValue(): |
794 | - return new UnitsParameter( [], [], true ); |
|
794 | + return new UnitsParameter([], [], true); |
|
795 | 795 | } |
796 | 796 | } |
797 | 797 | |
@@ -801,66 +801,66 @@ discard block |
||
801 | 801 | * @throws ConstraintParameterException if the parameter is invalid or missing |
802 | 802 | * @return UnitsParameter |
803 | 803 | */ |
804 | - public function parseUnitsParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
805 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
804 | + public function parseUnitsParameter(array $constraintParameters, $constraintTypeItemId) { |
|
805 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
806 | 806 | $unitItems = []; |
807 | 807 | $unitQuantities = []; |
808 | 808 | $unitlessAllowed = false; |
809 | 809 | |
810 | - foreach ( $items as $item ) { |
|
811 | - $unit = $this->parseUnitItem( $item ); |
|
812 | - $unitItems = array_merge( $unitItems, $unit->getUnitItemIds() ); |
|
813 | - $unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() ); |
|
810 | + foreach ($items as $item) { |
|
811 | + $unit = $this->parseUnitItem($item); |
|
812 | + $unitItems = array_merge($unitItems, $unit->getUnitItemIds()); |
|
813 | + $unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities()); |
|
814 | 814 | $unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed(); |
815 | 815 | } |
816 | 816 | |
817 | - if ( $unitQuantities === [] && !$unitlessAllowed ) { |
|
817 | + if ($unitQuantities === [] && !$unitlessAllowed) { |
|
818 | 818 | throw new LogicException( |
819 | 819 | 'The "units" parameter is required, and yet we seem to be missing any allowed unit' |
820 | 820 | ); |
821 | 821 | } |
822 | 822 | |
823 | - return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed ); |
|
823 | + return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed); |
|
824 | 824 | } |
825 | 825 | |
826 | - private function parseEntityTypeItemId( ItemId $itemId ): EntityTypesParameter { |
|
827 | - switch ( $itemId->getSerialization() ) { |
|
828 | - case $this->config->get( 'WBQualityConstraintsWikibaseItemId' ): |
|
826 | + private function parseEntityTypeItemId(ItemId $itemId): EntityTypesParameter { |
|
827 | + switch ($itemId->getSerialization()) { |
|
828 | + case $this->config->get('WBQualityConstraintsWikibaseItemId'): |
|
829 | 829 | $entityType = 'item'; |
830 | 830 | break; |
831 | - case $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ): |
|
831 | + case $this->config->get('WBQualityConstraintsWikibasePropertyId'): |
|
832 | 832 | $entityType = 'property'; |
833 | 833 | break; |
834 | - case $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ): |
|
834 | + case $this->config->get('WBQualityConstraintsWikibaseLexemeId'): |
|
835 | 835 | $entityType = 'lexeme'; |
836 | 836 | break; |
837 | - case $this->config->get( 'WBQualityConstraintsWikibaseFormId' ): |
|
837 | + case $this->config->get('WBQualityConstraintsWikibaseFormId'): |
|
838 | 838 | $entityType = 'form'; |
839 | 839 | break; |
840 | - case $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ): |
|
840 | + case $this->config->get('WBQualityConstraintsWikibaseSenseId'): |
|
841 | 841 | $entityType = 'sense'; |
842 | 842 | break; |
843 | - case $this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ): |
|
843 | + case $this->config->get('WBQualityConstraintsWikibaseMediaInfoId'): |
|
844 | 844 | $entityType = 'mediainfo'; |
845 | 845 | break; |
846 | 846 | default: |
847 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
847 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
848 | 848 | $allowed = [ |
849 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseItemId' ) ), |
|
850 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) ), |
|
851 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) ), |
|
852 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseFormId' ) ), |
|
853 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) ), |
|
854 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ) ), |
|
849 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseItemId')), |
|
850 | + new ItemId($this->config->get('WBQualityConstraintsWikibasePropertyId')), |
|
851 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseLexemeId')), |
|
852 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseFormId')), |
|
853 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseSenseId')), |
|
854 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseMediaInfoId')), |
|
855 | 855 | ]; |
856 | 856 | throw new ConstraintParameterException( |
857 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
858 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
859 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
857 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
858 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
859 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
860 | 860 | ); |
861 | 861 | } |
862 | 862 | |
863 | - return new EntityTypesParameter( [ $entityType ], [ $itemId ] ); |
|
863 | + return new EntityTypesParameter([$entityType], [$itemId]); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | /** |
@@ -869,32 +869,32 @@ discard block |
||
869 | 869 | * @throws ConstraintParameterException if the parameter is invalid or missing |
870 | 870 | * @return EntityTypesParameter |
871 | 871 | */ |
872 | - public function parseEntityTypesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
872 | + public function parseEntityTypesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
873 | 873 | $entityTypes = []; |
874 | 874 | $entityTypeItemIds = []; |
875 | 875 | $itemIds = $this->parseItemIdsParameter( |
876 | 876 | $constraintParameters, |
877 | 877 | $constraintTypeItemId, |
878 | 878 | true, |
879 | - $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ) |
|
879 | + $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId') |
|
880 | 880 | ); |
881 | 881 | |
882 | - foreach ( $itemIds as $itemId ) { |
|
883 | - $entityType = $this->parseEntityTypeItemId( $itemId ); |
|
884 | - $entityTypes = array_merge( $entityTypes, $entityType->getEntityTypes() ); |
|
885 | - $entityTypeItemIds = array_merge( $entityTypeItemIds, $entityType->getEntityTypeItemIds() ); |
|
882 | + foreach ($itemIds as $itemId) { |
|
883 | + $entityType = $this->parseEntityTypeItemId($itemId); |
|
884 | + $entityTypes = array_merge($entityTypes, $entityType->getEntityTypes()); |
|
885 | + $entityTypeItemIds = array_merge($entityTypeItemIds, $entityType->getEntityTypeItemIds()); |
|
886 | 886 | } |
887 | 887 | |
888 | - if ( empty( $entityTypes ) ) { |
|
888 | + if (empty($entityTypes)) { |
|
889 | 889 | // @codeCoverageIgnoreStart |
890 | 890 | throw new LogicException( |
891 | - 'The "entity types" parameter is required, ' . |
|
891 | + 'The "entity types" parameter is required, '. |
|
892 | 892 | 'and yet we seem to be missing any allowed entity type' |
893 | 893 | ); |
894 | 894 | // @codeCoverageIgnoreEnd |
895 | 895 | } |
896 | 896 | |
897 | - return new EntityTypesParameter( $entityTypes, $entityTypeItemIds ); |
|
897 | + return new EntityTypesParameter($entityTypes, $entityTypeItemIds); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
@@ -902,18 +902,18 @@ discard block |
||
902 | 902 | * @throws ConstraintParameterException if the parameter is invalid |
903 | 903 | * @return PropertyId[] |
904 | 904 | */ |
905 | - public function parseSeparatorsParameter( array $constraintParameters ) { |
|
906 | - $separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' ); |
|
905 | + public function parseSeparatorsParameter(array $constraintParameters) { |
|
906 | + $separatorId = $this->config->get('WBQualityConstraintsSeparatorId'); |
|
907 | 907 | |
908 | - if ( !array_key_exists( $separatorId, $constraintParameters ) ) { |
|
908 | + if (!array_key_exists($separatorId, $constraintParameters)) { |
|
909 | 909 | return []; |
910 | 910 | } |
911 | 911 | |
912 | 912 | $parameters = $constraintParameters[$separatorId]; |
913 | 913 | $separators = []; |
914 | 914 | |
915 | - foreach ( $parameters as $parameter ) { |
|
916 | - $separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId ); |
|
915 | + foreach ($parameters as $parameter) { |
|
916 | + $separators[] = $this->parsePropertyIdParameter($parameter, $separatorId); |
|
917 | 917 | } |
918 | 918 | |
919 | 919 | return $separators; |
@@ -928,18 +928,18 @@ discard block |
||
928 | 928 | * @return string one of the Context::TYPE_* constants |
929 | 929 | * @throws ConstraintParameterException |
930 | 930 | */ |
931 | - private function parseContextTypeItemId( ItemId $itemId, $use, $parameterId ) { |
|
932 | - if ( $use === 'constraint scope' ) { |
|
933 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ); |
|
934 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ); |
|
935 | - $referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ); |
|
931 | + private function parseContextTypeItemId(ItemId $itemId, $use, $parameterId) { |
|
932 | + if ($use === 'constraint scope') { |
|
933 | + $mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId'); |
|
934 | + $qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId'); |
|
935 | + $referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId'); |
|
936 | 936 | } else { |
937 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
938 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
939 | - $referencesId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
937 | + $mainSnakId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
938 | + $qualifiersId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
939 | + $referencesId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
940 | 940 | } |
941 | 941 | |
942 | - switch ( $itemId->getSerialization() ) { |
|
942 | + switch ($itemId->getSerialization()) { |
|
943 | 943 | case $mainSnakId: |
944 | 944 | return Context::TYPE_STATEMENT; |
945 | 945 | case $qualifiersId: |
@@ -948,14 +948,14 @@ discard block |
||
948 | 948 | return Context::TYPE_REFERENCE; |
949 | 949 | default: |
950 | 950 | $allowed = [ |
951 | - new ItemId( $mainSnakId ), |
|
952 | - new ItemId( $qualifiersId ), |
|
953 | - new ItemId( $referencesId ), |
|
951 | + new ItemId($mainSnakId), |
|
952 | + new ItemId($qualifiersId), |
|
953 | + new ItemId($referencesId), |
|
954 | 954 | ]; |
955 | 955 | throw new ConstraintParameterException( |
956 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
957 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
958 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
956 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
957 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
958 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
959 | 959 | ); |
960 | 960 | } |
961 | 961 | } |
@@ -966,9 +966,9 @@ discard block |
||
966 | 966 | * @throws ConstraintParameterException if the parameter is invalid or missing |
967 | 967 | * @return string[] list of Context::TYPE_* constants |
968 | 968 | */ |
969 | - public function parsePropertyScopeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
969 | + public function parsePropertyScopeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
970 | 970 | $contextTypes = []; |
971 | - $parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' ); |
|
971 | + $parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId'); |
|
972 | 972 | $itemIds = $this->parseItemIdsParameter( |
973 | 973 | $constraintParameters, |
974 | 974 | $constraintTypeItemId, |
@@ -976,14 +976,14 @@ discard block |
||
976 | 976 | $parameterId |
977 | 977 | ); |
978 | 978 | |
979 | - foreach ( $itemIds as $itemId ) { |
|
980 | - $contextTypes[] = $this->parseContextTypeItemId( $itemId, 'property scope', $parameterId ); |
|
979 | + foreach ($itemIds as $itemId) { |
|
980 | + $contextTypes[] = $this->parseContextTypeItemId($itemId, 'property scope', $parameterId); |
|
981 | 981 | } |
982 | 982 | |
983 | - if ( empty( $contextTypes ) ) { |
|
983 | + if (empty($contextTypes)) { |
|
984 | 984 | // @codeCoverageIgnoreStart |
985 | 985 | throw new LogicException( |
986 | - 'The "property scope" parameter is required, ' . |
|
986 | + 'The "property scope" parameter is required, '. |
|
987 | 987 | 'and yet we seem to be missing any allowed scope' |
988 | 988 | ); |
989 | 989 | // @codeCoverageIgnoreEnd |