@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | * @param array $parameters |
79 | 79 | * @throws ConstraintParameterException |
80 | 80 | */ |
81 | - public function checkError( array $parameters ) { |
|
82 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
81 | + public function checkError(array $parameters) { |
|
82 | + if (array_key_exists('@error', $parameters)) { |
|
83 | 83 | $error = $parameters['@error']; |
84 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
84 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
85 | 85 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
86 | 86 | } else { |
87 | 87 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
88 | 88 | } |
89 | - throw new ConstraintParameterException( new ViolationMessage( $msg ) ); |
|
89 | + throw new ConstraintParameterException(new ViolationMessage($msg)); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | * @param string $parameterId |
97 | 97 | * @throws ConstraintParameterException |
98 | 98 | */ |
99 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
100 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
99 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
100 | + if (count($parameters[$parameterId]) !== 1) { |
|
101 | 101 | throw new ConstraintParameterException( |
102 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) ) |
|
103 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
102 | + (new ViolationMessage('wbqc-violation-message-parameter-single')) |
|
103 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
104 | 104 | ); |
105 | 105 | } |
106 | 106 | } |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * @return void |
113 | 113 | * @throws ConstraintParameterException |
114 | 114 | */ |
115 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
116 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
115 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
116 | + if (!($snak instanceof PropertyValueSnak)) { |
|
117 | 117 | throw new ConstraintParameterException( |
118 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
119 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
118 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
119 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
120 | 120 | ); |
121 | 121 | } |
122 | 122 | } |
@@ -128,17 +128,17 @@ discard block |
||
128 | 128 | * @throws ConstraintParameterException |
129 | 129 | * @return EntityId |
130 | 130 | */ |
131 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
132 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
133 | - $this->requireValueParameter( $snak, $parameterId ); |
|
131 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
132 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
133 | + $this->requireValueParameter($snak, $parameterId); |
|
134 | 134 | $value = $snak->getDataValue(); |
135 | - if ( $value instanceof EntityIdValue ) { |
|
135 | + if ($value instanceof EntityIdValue) { |
|
136 | 136 | return $value->getEntityId(); |
137 | 137 | } else { |
138 | 138 | throw new ConstraintParameterException( |
139 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) ) |
|
140 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
141 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
139 | + (new ViolationMessage('wbqc-violation-message-parameter-entity')) |
|
140 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
141 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
142 | 142 | ); |
143 | 143 | } |
144 | 144 | } |
@@ -149,20 +149,20 @@ discard block |
||
149 | 149 | * @throws ConstraintParameterException if the parameter is invalid or missing |
150 | 150 | * @return string[] class entity ID serializations |
151 | 151 | */ |
152 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
153 | - $this->checkError( $constraintParameters ); |
|
154 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
155 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
152 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
153 | + $this->checkError($constraintParameters); |
|
154 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
155 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
156 | 156 | throw new ConstraintParameterException( |
157 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
158 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
159 | - ->withEntityId( new NumericPropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
157 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
158 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
159 | + ->withEntityId(new NumericPropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
160 | 160 | ); |
161 | 161 | } |
162 | 162 | |
163 | 163 | $classes = []; |
164 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
165 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
164 | + foreach ($constraintParameters[$classId] as $class) { |
|
165 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
166 | 166 | } |
167 | 167 | return $classes; |
168 | 168 | } |
@@ -173,31 +173,31 @@ discard block |
||
173 | 173 | * @throws ConstraintParameterException if the parameter is invalid or missing |
174 | 174 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
175 | 175 | */ |
176 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
177 | - $this->checkError( $constraintParameters ); |
|
178 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
179 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
176 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
177 | + $this->checkError($constraintParameters); |
|
178 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
179 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
180 | 180 | throw new ConstraintParameterException( |
181 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
182 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
183 | - ->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
181 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
182 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
183 | + ->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
184 | 184 | ); |
185 | 185 | } |
186 | 186 | |
187 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
188 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
189 | - if ( !( $relationEntityId instanceof ItemId ) ) { |
|
187 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
188 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
189 | + if (!($relationEntityId instanceof ItemId)) { |
|
190 | 190 | throw new ConstraintParameterException( |
191 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
192 | - ->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
193 | - ->withDataValue( new EntityIdValue( $relationEntityId ), Role::CONSTRAINT_PARAMETER_VALUE ) |
|
191 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
192 | + ->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
193 | + ->withDataValue(new EntityIdValue($relationEntityId), Role::CONSTRAINT_PARAMETER_VALUE) |
|
194 | 194 | ); |
195 | 195 | } |
196 | - return $this->mapItemId( $relationEntityId, [ |
|
197 | - $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ) => 'instance', |
|
198 | - $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ) => 'subclass', |
|
199 | - $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ) => 'instanceOrSubclass', |
|
200 | - ], $relationId ); |
|
196 | + return $this->mapItemId($relationEntityId, [ |
|
197 | + $this->config->get('WBQualityConstraintsInstanceOfRelationId') => 'instance', |
|
198 | + $this->config->get('WBQualityConstraintsSubclassOfRelationId') => 'subclass', |
|
199 | + $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId') => 'instanceOrSubclass', |
|
200 | + ], $relationId); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,20 +207,20 @@ discard block |
||
207 | 207 | * @throws ConstraintParameterException |
208 | 208 | * @return PropertyId |
209 | 209 | */ |
210 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
211 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
212 | - $this->requireValueParameter( $snak, $parameterId ); |
|
210 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
211 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
212 | + $this->requireValueParameter($snak, $parameterId); |
|
213 | 213 | $value = $snak->getDataValue(); |
214 | - if ( $value instanceof EntityIdValue ) { |
|
214 | + if ($value instanceof EntityIdValue) { |
|
215 | 215 | $id = $value->getEntityId(); |
216 | - if ( $id instanceof PropertyId ) { |
|
216 | + if ($id instanceof PropertyId) { |
|
217 | 217 | return $id; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | throw new ConstraintParameterException( |
221 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) ) |
|
222 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
223 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
221 | + (new ViolationMessage('wbqc-violation-message-parameter-property')) |
|
222 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
223 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
224 | 224 | ); |
225 | 225 | } |
226 | 226 | |
@@ -231,33 +231,33 @@ discard block |
||
231 | 231 | * @throws ConstraintParameterException if the parameter is invalid or missing |
232 | 232 | * @return PropertyId |
233 | 233 | */ |
234 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
235 | - $this->checkError( $constraintParameters ); |
|
236 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
237 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
234 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
235 | + $this->checkError($constraintParameters); |
|
236 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
237 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
238 | 238 | throw new ConstraintParameterException( |
239 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
240 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
241 | - ->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
239 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
240 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
241 | + ->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
242 | 242 | ); |
243 | 243 | } |
244 | 244 | |
245 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
246 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
245 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
246 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
247 | 247 | } |
248 | 248 | |
249 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
249 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
250 | 250 | $dataValue = $snak->getDataValue(); |
251 | - if ( $dataValue instanceof EntityIdValue ) { |
|
251 | + if ($dataValue instanceof EntityIdValue) { |
|
252 | 252 | $entityId = $dataValue->getEntityId(); |
253 | - if ( $entityId instanceof ItemId ) { |
|
254 | - return ItemIdSnakValue::fromItemId( $entityId ); |
|
253 | + if ($entityId instanceof ItemId) { |
|
254 | + return ItemIdSnakValue::fromItemId($entityId); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | throw new ConstraintParameterException( |
258 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
259 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
260 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
258 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
259 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
260 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
261 | 261 | ); |
262 | 262 | } |
263 | 263 | |
@@ -275,16 +275,16 @@ discard block |
||
275 | 275 | $required, |
276 | 276 | $parameterId = null |
277 | 277 | ) { |
278 | - $this->checkError( $constraintParameters ); |
|
279 | - if ( $parameterId === null ) { |
|
280 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
278 | + $this->checkError($constraintParameters); |
|
279 | + if ($parameterId === null) { |
|
280 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
281 | 281 | } |
282 | - if ( !array_key_exists( $parameterId, $constraintParameters ) ) { |
|
283 | - if ( $required ) { |
|
282 | + if (!array_key_exists($parameterId, $constraintParameters)) { |
|
283 | + if ($required) { |
|
284 | 284 | throw new ConstraintParameterException( |
285 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
286 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
287 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
285 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
286 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
287 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
288 | 288 | ); |
289 | 289 | } else { |
290 | 290 | return []; |
@@ -292,11 +292,11 @@ discard block |
||
292 | 292 | } |
293 | 293 | |
294 | 294 | $values = []; |
295 | - foreach ( $constraintParameters[$parameterId] as $parameter ) { |
|
296 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
297 | - switch ( true ) { |
|
295 | + foreach ($constraintParameters[$parameterId] as $parameter) { |
|
296 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
297 | + switch (true) { |
|
298 | 298 | case $snak instanceof PropertyValueSnak: |
299 | - $values[] = $this->parseItemIdParameter( $snak, $parameterId ); |
|
299 | + $values[] = $this->parseItemIdParameter($snak, $parameterId); |
|
300 | 300 | break; |
301 | 301 | case $snak instanceof PropertySomeValueSnak: |
302 | 302 | $values[] = ItemIdSnakValue::someValue(); |
@@ -324,13 +324,13 @@ discard block |
||
324 | 324 | bool $required, |
325 | 325 | string $parameterId |
326 | 326 | ): array { |
327 | - return array_map( static function ( ItemIdSnakValue $value ) use ( $parameterId ): ItemId { |
|
328 | - if ( $value->isValue() ) { |
|
327 | + return array_map(static function(ItemIdSnakValue $value) use ($parameterId): ItemId { |
|
328 | + if ($value->isValue()) { |
|
329 | 329 | return $value->getItemId(); |
330 | 330 | } else { |
331 | 331 | throw new ConstraintParameterException( |
332 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
333 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
332 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
333 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
334 | 334 | ); |
335 | 335 | } |
336 | 336 | }, $this->parseItemsParameter( |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | $constraintTypeItemId, |
339 | 339 | $required, |
340 | 340 | $parameterId |
341 | - ) ); |
|
341 | + )); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -346,18 +346,18 @@ discard block |
||
346 | 346 | * @throws ConstraintParameterException |
347 | 347 | * @return mixed elements of $mapping |
348 | 348 | */ |
349 | - private function mapItemId( ItemId $itemId, array $mapping, string $parameterId ) { |
|
349 | + private function mapItemId(ItemId $itemId, array $mapping, string $parameterId) { |
|
350 | 350 | $serialization = $itemId->getSerialization(); |
351 | - if ( array_key_exists( $serialization, $mapping ) ) { |
|
351 | + if (array_key_exists($serialization, $mapping)) { |
|
352 | 352 | return $mapping[$serialization]; |
353 | 353 | } else { |
354 | - $allowed = array_map( static function ( $id ) { |
|
355 | - return new ItemId( $id ); |
|
356 | - }, array_keys( $mapping ) ); |
|
354 | + $allowed = array_map(static function($id) { |
|
355 | + return new ItemId($id); |
|
356 | + }, array_keys($mapping)); |
|
357 | 357 | throw new ConstraintParameterException( |
358 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
359 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
360 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
358 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
359 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
360 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
361 | 361 | ); |
362 | 362 | } |
363 | 363 | } |
@@ -368,27 +368,27 @@ discard block |
||
368 | 368 | * @throws ConstraintParameterException if the parameter is invalid or missing |
369 | 369 | * @return PropertyId[] |
370 | 370 | */ |
371 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
372 | - $this->checkError( $constraintParameters ); |
|
373 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
374 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
371 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
372 | + $this->checkError($constraintParameters); |
|
373 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
374 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
375 | 375 | throw new ConstraintParameterException( |
376 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
377 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
378 | - ->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
376 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
377 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
378 | + ->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
379 | 379 | ); |
380 | 380 | } |
381 | 381 | |
382 | 382 | $parameters = $constraintParameters[$propertyId]; |
383 | - if ( count( $parameters ) === 1 && |
|
384 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
383 | + if (count($parameters) === 1 && |
|
384 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
385 | 385 | ) { |
386 | 386 | return []; |
387 | 387 | } |
388 | 388 | |
389 | 389 | $properties = []; |
390 | - foreach ( $parameters as $parameter ) { |
|
391 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
390 | + foreach ($parameters as $parameter) { |
|
391 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
392 | 392 | } |
393 | 393 | return $properties; |
394 | 394 | } |
@@ -399,16 +399,16 @@ discard block |
||
399 | 399 | * @throws ConstraintParameterException |
400 | 400 | * @return DataValue|null |
401 | 401 | */ |
402 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
403 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
404 | - if ( $snak instanceof PropertyValueSnak ) { |
|
402 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
403 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
404 | + if ($snak instanceof PropertyValueSnak) { |
|
405 | 405 | return $snak->getDataValue(); |
406 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
406 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
407 | 407 | return null; |
408 | 408 | } else { |
409 | 409 | throw new ConstraintParameterException( |
410 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
411 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
410 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
411 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
412 | 412 | ); |
413 | 413 | } |
414 | 414 | } |
@@ -418,10 +418,10 @@ discard block |
||
418 | 418 | * @param string $parameterId |
419 | 419 | * @return DataValue|null |
420 | 420 | */ |
421 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
421 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
422 | 422 | try { |
423 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
424 | - } catch ( ConstraintParameterException $e ) { |
|
423 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
424 | + } catch (ConstraintParameterException $e) { |
|
425 | 425 | // unknown value means “now” |
426 | 426 | return new NowValue(); |
427 | 427 | } |
@@ -434,14 +434,14 @@ discard block |
||
434 | 434 | * @param string $unit |
435 | 435 | * @return bool |
436 | 436 | */ |
437 | - private function exactlyOneQuantityWithUnit( ?DataValue $min, ?DataValue $max, $unit ) { |
|
438 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
439 | - !( $max instanceof UnboundedQuantityValue ) |
|
437 | + private function exactlyOneQuantityWithUnit(?DataValue $min, ?DataValue $max, $unit) { |
|
438 | + if (!($min instanceof UnboundedQuantityValue) || |
|
439 | + !($max instanceof UnboundedQuantityValue) |
|
440 | 440 | ) { |
441 | 441 | return false; |
442 | 442 | } |
443 | 443 | |
444 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
444 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -454,42 +454,42 @@ discard block |
||
454 | 454 | * @throws ConstraintParameterException if the parameter is invalid or missing |
455 | 455 | * @return DataValue[] if the parameter is invalid or missing |
456 | 456 | */ |
457 | - private function parseRangeParameter( array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type ) { |
|
458 | - $this->checkError( $constraintParameters ); |
|
459 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
460 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
457 | + private function parseRangeParameter(array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type) { |
|
458 | + $this->checkError($constraintParameters); |
|
459 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
460 | + !array_key_exists($maximumId, $constraintParameters) |
|
461 | 461 | ) { |
462 | 462 | throw new ConstraintParameterException( |
463 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) ) |
|
464 | - ->withDataValueType( $type ) |
|
465 | - ->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
466 | - ->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
467 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
463 | + (new ViolationMessage('wbqc-violation-message-range-parameters-needed')) |
|
464 | + ->withDataValueType($type) |
|
465 | + ->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
466 | + ->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
467 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
468 | 468 | ); |
469 | 469 | } |
470 | 470 | |
471 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
472 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
471 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
472 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
473 | 473 | $parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
474 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
475 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
474 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
475 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
476 | 476 | |
477 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
478 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
477 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
478 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
479 | 479 | throw new ConstraintParameterException( |
480 | - new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
480 | + new ViolationMessage('wbqc-violation-message-range-parameters-one-year') |
|
481 | 481 | ); |
482 | 482 | } |
483 | - if ( $min === null && $max === null || |
|
484 | - $min !== null && $max !== null && $min->equals( $max ) ) { |
|
483 | + if ($min === null && $max === null || |
|
484 | + $min !== null && $max !== null && $min->equals($max)) { |
|
485 | 485 | throw new ConstraintParameterException( |
486 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) ) |
|
487 | - ->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
488 | - ->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
486 | + (new ViolationMessage('wbqc-violation-message-range-parameters-same')) |
|
487 | + ->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
488 | + ->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
489 | 489 | ); |
490 | 490 | } |
491 | 491 | |
492 | - return [ $min, $max ]; |
|
492 | + return [$min, $max]; |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | /** |
@@ -499,11 +499,11 @@ discard block |
||
499 | 499 | * @throws ConstraintParameterException if the parameter is invalid or missing |
500 | 500 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
501 | 501 | */ |
502 | - public function parseQuantityRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
502 | + public function parseQuantityRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
503 | 503 | return $this->parseRangeParameter( |
504 | 504 | $constraintParameters, |
505 | - $this->config->get( 'WBQualityConstraintsMinimumQuantityId' ), |
|
506 | - $this->config->get( 'WBQualityConstraintsMaximumQuantityId' ), |
|
505 | + $this->config->get('WBQualityConstraintsMinimumQuantityId'), |
|
506 | + $this->config->get('WBQualityConstraintsMaximumQuantityId'), |
|
507 | 507 | $constraintTypeItemId, |
508 | 508 | 'quantity' |
509 | 509 | ); |
@@ -516,11 +516,11 @@ discard block |
||
516 | 516 | * @throws ConstraintParameterException if the parameter is invalid or missing |
517 | 517 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
518 | 518 | */ |
519 | - public function parseTimeRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
519 | + public function parseTimeRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
520 | 520 | return $this->parseRangeParameter( |
521 | 521 | $constraintParameters, |
522 | - $this->config->get( 'WBQualityConstraintsMinimumDateId' ), |
|
523 | - $this->config->get( 'WBQualityConstraintsMaximumDateId' ), |
|
522 | + $this->config->get('WBQualityConstraintsMinimumDateId'), |
|
523 | + $this->config->get('WBQualityConstraintsMaximumDateId'), |
|
524 | 524 | $constraintTypeItemId, |
525 | 525 | 'time' |
526 | 526 | ); |
@@ -532,20 +532,20 @@ discard block |
||
532 | 532 | * @throws ConstraintParameterException |
533 | 533 | * @return string[] |
534 | 534 | */ |
535 | - public function parseLanguageParameter( array $constraintParameters, $constraintTypeItemId ): array { |
|
536 | - $this->checkError( $constraintParameters ); |
|
537 | - $languagePropertyId = $this->config->get( 'WBQualityConstraintsLanguagePropertyId' ); |
|
538 | - if ( !array_key_exists( $languagePropertyId, $constraintParameters ) ) { |
|
535 | + public function parseLanguageParameter(array $constraintParameters, $constraintTypeItemId): array { |
|
536 | + $this->checkError($constraintParameters); |
|
537 | + $languagePropertyId = $this->config->get('WBQualityConstraintsLanguagePropertyId'); |
|
538 | + if (!array_key_exists($languagePropertyId, $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 NumericPropertyId( $languagePropertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
540 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
541 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
542 | + ->withEntityId(new NumericPropertyId($languagePropertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
543 | 543 | ); |
544 | 544 | } |
545 | 545 | |
546 | 546 | $languages = []; |
547 | - foreach ( $constraintParameters[$languagePropertyId] as $snak ) { |
|
548 | - $languages[] = $this->parseStringParameter( $snak, $languagePropertyId ); |
|
547 | + foreach ($constraintParameters[$languagePropertyId] as $snak) { |
|
548 | + $languages[] = $this->parseStringParameter($snak, $languagePropertyId); |
|
549 | 549 | } |
550 | 550 | return $languages; |
551 | 551 | } |
@@ -557,17 +557,17 @@ discard block |
||
557 | 557 | * @throws ConstraintParameterException |
558 | 558 | * @return string |
559 | 559 | */ |
560 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
561 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
562 | - $this->requireValueParameter( $snak, $parameterId ); |
|
560 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
561 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
562 | + $this->requireValueParameter($snak, $parameterId); |
|
563 | 563 | $value = $snak->getDataValue(); |
564 | - if ( $value instanceof StringValue ) { |
|
564 | + if ($value instanceof StringValue) { |
|
565 | 565 | return $value->getValue(); |
566 | 566 | } else { |
567 | 567 | throw new ConstraintParameterException( |
568 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) ) |
|
569 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
570 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
568 | + (new ViolationMessage('wbqc-violation-message-parameter-string')) |
|
569 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
570 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
571 | 571 | ); |
572 | 572 | } |
573 | 573 | } |
@@ -578,15 +578,15 @@ discard block |
||
578 | 578 | * @throws ConstraintParameterException if the parameter is invalid or missing |
579 | 579 | * @return string |
580 | 580 | */ |
581 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
582 | - $this->checkError( $constraintParameters ); |
|
583 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
584 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
581 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
582 | + $this->checkError($constraintParameters); |
|
583 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
584 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
585 | 585 | return ''; |
586 | 586 | } |
587 | 587 | |
588 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
589 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
588 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
589 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | /** |
@@ -595,19 +595,19 @@ discard block |
||
595 | 595 | * @throws ConstraintParameterException if the parameter is invalid or missing |
596 | 596 | * @return string |
597 | 597 | */ |
598 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
599 | - $this->checkError( $constraintParameters ); |
|
600 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
601 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
598 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
599 | + $this->checkError($constraintParameters); |
|
600 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
601 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
602 | 602 | throw new ConstraintParameterException( |
603 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
604 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
605 | - ->withEntityId( new NumericPropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
603 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
604 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
605 | + ->withEntityId(new NumericPropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
606 | 606 | ); |
607 | 607 | } |
608 | 608 | |
609 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
610 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
609 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
610 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | /** |
@@ -615,16 +615,16 @@ discard block |
||
615 | 615 | * @throws ConstraintParameterException if the parameter is invalid |
616 | 616 | * @return EntityId[] |
617 | 617 | */ |
618 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
619 | - $this->checkError( $constraintParameters ); |
|
620 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
621 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
618 | + public function parseExceptionParameter(array $constraintParameters) { |
|
619 | + $this->checkError($constraintParameters); |
|
620 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
621 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
622 | 622 | return []; |
623 | 623 | } |
624 | 624 | |
625 | 625 | return array_map( |
626 | - function ( $snakSerialization ) use ( $exceptionId ) { |
|
627 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
626 | + function($snakSerialization) use ($exceptionId) { |
|
627 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
628 | 628 | }, |
629 | 629 | $constraintParameters[$exceptionId] |
630 | 630 | ); |
@@ -635,39 +635,39 @@ discard block |
||
635 | 635 | * @throws ConstraintParameterException if the parameter is invalid |
636 | 636 | * @return string|null 'mandatory', 'suggestion' or null |
637 | 637 | */ |
638 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
639 | - $this->checkError( $constraintParameters ); |
|
640 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
641 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
638 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
639 | + $this->checkError($constraintParameters); |
|
640 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
641 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
642 | 642 | return null; |
643 | 643 | } |
644 | 644 | |
645 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
646 | - $supportedStatuses = [ new ItemId( $mandatoryId ) ]; |
|
647 | - if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) { |
|
648 | - $suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' ); |
|
649 | - $supportedStatuses[] = new ItemId( $suggestionId ); |
|
645 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
646 | + $supportedStatuses = [new ItemId($mandatoryId)]; |
|
647 | + if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) { |
|
648 | + $suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId'); |
|
649 | + $supportedStatuses[] = new ItemId($suggestionId); |
|
650 | 650 | } else { |
651 | 651 | $suggestionId = null; |
652 | 652 | } |
653 | 653 | |
654 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
655 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
656 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
654 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
655 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
656 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
657 | 657 | '@phan-var \Wikibase\DataModel\Snak\PropertyValueSnak $snak'; |
658 | 658 | $dataValue = $snak->getDataValue(); |
659 | 659 | '@phan-var EntityIdValue $dataValue'; |
660 | 660 | $entityId = $dataValue->getEntityId(); |
661 | 661 | $statusId = $entityId->getSerialization(); |
662 | 662 | |
663 | - if ( $statusId === $mandatoryId ) { |
|
663 | + if ($statusId === $mandatoryId) { |
|
664 | 664 | return 'mandatory'; |
665 | - } elseif ( $statusId === $suggestionId ) { |
|
665 | + } elseif ($statusId === $suggestionId) { |
|
666 | 666 | return 'suggestion'; |
667 | 667 | } else { |
668 | 668 | throw new ConstraintParameterException( |
669 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
670 | - ->withEntityId( new NumericPropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
669 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
670 | + ->withEntityId(new NumericPropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
671 | 671 | ->withEntityIdList( |
672 | 672 | $supportedStatuses, |
673 | 673 | Role::CONSTRAINT_PARAMETER_VALUE |
@@ -683,12 +683,12 @@ discard block |
||
683 | 683 | * @return void |
684 | 684 | * @throws ConstraintParameterException |
685 | 685 | */ |
686 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
687 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
686 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
687 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
688 | 688 | throw new ConstraintParameterException( |
689 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) ) |
|
690 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
691 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
689 | + (new ViolationMessage('wbqc-violation-message-parameter-monolingualtext')) |
|
690 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
691 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
692 | 692 | ); |
693 | 693 | } |
694 | 694 | } |
@@ -701,31 +701,31 @@ discard block |
||
701 | 701 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
702 | 702 | * @return MultilingualTextValue |
703 | 703 | */ |
704 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
704 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
705 | 705 | $result = []; |
706 | 706 | |
707 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
708 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
709 | - $this->requireValueParameter( $snak, $parameterId ); |
|
707 | + foreach ($snakSerializations as $snakSerialization) { |
|
708 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
709 | + $this->requireValueParameter($snak, $parameterId); |
|
710 | 710 | |
711 | 711 | $value = $snak->getDataValue(); |
712 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
712 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
713 | 713 | /** @var MonolingualTextValue $value */ |
714 | 714 | '@phan-var MonolingualTextValue $value'; |
715 | 715 | |
716 | 716 | $code = $value->getLanguageCode(); |
717 | - if ( array_key_exists( $code, $result ) ) { |
|
717 | + if (array_key_exists($code, $result)) { |
|
718 | 718 | throw new ConstraintParameterException( |
719 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) ) |
|
720 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
721 | - ->withLanguage( $code ) |
|
719 | + (new ViolationMessage('wbqc-violation-message-parameter-single-per-language')) |
|
720 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
721 | + ->withLanguage($code) |
|
722 | 722 | ); |
723 | 723 | } |
724 | 724 | |
725 | 725 | $result[$code] = $value; |
726 | 726 | } |
727 | 727 | |
728 | - return new MultilingualTextValue( $result ); |
|
728 | + return new MultilingualTextValue($result); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | /** |
@@ -733,11 +733,11 @@ discard block |
||
733 | 733 | * @throws ConstraintParameterException if the parameter is invalid |
734 | 734 | * @return MultilingualTextValue |
735 | 735 | */ |
736 | - public function parseSyntaxClarificationParameter( array $constraintParameters ) { |
|
737 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
736 | + public function parseSyntaxClarificationParameter(array $constraintParameters) { |
|
737 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
738 | 738 | |
739 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
740 | - return new MultilingualTextValue( [] ); |
|
739 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
740 | + return new MultilingualTextValue([]); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -770,14 +770,14 @@ discard block |
||
770 | 770 | array $validContextTypes, |
771 | 771 | array $validEntityTypes |
772 | 772 | ): array { |
773 | - $contextTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
773 | + $contextTypeParameterId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
774 | 774 | $contextTypeItemIds = $this->parseItemIdsParameter( |
775 | 775 | $constraintParameters, |
776 | 776 | $constraintTypeItemId, |
777 | 777 | false, |
778 | 778 | $contextTypeParameterId |
779 | 779 | ); |
780 | - $entityTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintEntityTypesId' ); |
|
780 | + $entityTypeParameterId = $this->config->get('WBQualityConstraintsConstraintEntityTypesId'); |
|
781 | 781 | $entityTypeItemIds = $this->parseItemIdsParameter( |
782 | 782 | $constraintParameters, |
783 | 783 | $constraintTypeItemId, |
@@ -793,26 +793,26 @@ discard block |
||
793 | 793 | $contextTypes = null; |
794 | 794 | $entityTypes = null; |
795 | 795 | |
796 | - if ( $contextTypeParameterId === $entityTypeParameterId ) { |
|
796 | + if ($contextTypeParameterId === $entityTypeParameterId) { |
|
797 | 797 | $itemIds = $contextTypeItemIds; |
798 | 798 | $mapping = $contextTypeMapping + $entityTypeMapping; |
799 | - foreach ( $itemIds as $itemId ) { |
|
800 | - $mapped = $this->mapItemId( $itemId, $mapping, $contextTypeParameterId ); |
|
801 | - if ( in_array( $mapped, $contextTypeMapping, true ) ) { |
|
799 | + foreach ($itemIds as $itemId) { |
|
800 | + $mapped = $this->mapItemId($itemId, $mapping, $contextTypeParameterId); |
|
801 | + if (in_array($mapped, $contextTypeMapping, true)) { |
|
802 | 802 | $contextTypes[] = $mapped; |
803 | 803 | } else { |
804 | 804 | $entityTypes[] = $mapped; |
805 | 805 | } |
806 | 806 | } |
807 | 807 | } else { |
808 | - foreach ( $contextTypeItemIds as $contextTypeItemId ) { |
|
808 | + foreach ($contextTypeItemIds as $contextTypeItemId) { |
|
809 | 809 | $contextTypes[] = $this->mapItemId( |
810 | 810 | $contextTypeItemId, |
811 | 811 | $contextTypeMapping, |
812 | 812 | $contextTypeParameterId |
813 | 813 | ); |
814 | 814 | } |
815 | - foreach ( $entityTypeItemIds as $entityTypeItemId ) { |
|
815 | + foreach ($entityTypeItemIds as $entityTypeItemId) { |
|
816 | 816 | $entityTypes[] = $this->mapItemId( |
817 | 817 | $entityTypeItemId, |
818 | 818 | $entityTypeMapping, |
@@ -821,21 +821,21 @@ discard block |
||
821 | 821 | } |
822 | 822 | } |
823 | 823 | |
824 | - $this->checkValidScope( $constraintTypeItemId, $contextTypes, $validContextTypes ); |
|
825 | - $this->checkValidScope( $constraintTypeItemId, $entityTypes, $validEntityTypes ); |
|
824 | + $this->checkValidScope($constraintTypeItemId, $contextTypes, $validContextTypes); |
|
825 | + $this->checkValidScope($constraintTypeItemId, $entityTypes, $validEntityTypes); |
|
826 | 826 | |
827 | - return [ $contextTypes, $entityTypes ]; |
|
827 | + return [$contextTypes, $entityTypes]; |
|
828 | 828 | } |
829 | 829 | |
830 | - private function checkValidScope( string $constraintTypeItemId, ?array $types, array $validTypes ): void { |
|
831 | - $invalidTypes = array_diff( $types ?: [], $validTypes ); |
|
832 | - if ( $invalidTypes !== [] ) { |
|
833 | - $invalidType = array_pop( $invalidTypes ); |
|
830 | + private function checkValidScope(string $constraintTypeItemId, ?array $types, array $validTypes): void { |
|
831 | + $invalidTypes = array_diff($types ?: [], $validTypes); |
|
832 | + if ($invalidTypes !== []) { |
|
833 | + $invalidType = array_pop($invalidTypes); |
|
834 | 834 | throw new ConstraintParameterException( |
835 | - ( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) ) |
|
836 | - ->withConstraintScope( $invalidType, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
837 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
838 | - ->withConstraintScopeList( $validTypes, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
835 | + (new ViolationMessage('wbqc-violation-message-invalid-scope')) |
|
836 | + ->withConstraintScope($invalidType, Role::CONSTRAINT_PARAMETER_VALUE) |
|
837 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
838 | + ->withConstraintScopeList($validTypes, Role::CONSTRAINT_PARAMETER_VALUE) |
|
839 | 839 | ); |
840 | 840 | } |
841 | 841 | } |
@@ -846,8 +846,8 @@ discard block |
||
846 | 846 | * @param ItemId $unitId |
847 | 847 | * @return string unit |
848 | 848 | */ |
849 | - private function parseUnitParameter( ItemId $unitId ) { |
|
850 | - return $this->unitItemConceptBaseUri . $unitId->getSerialization(); |
|
849 | + private function parseUnitParameter(ItemId $unitId) { |
|
850 | + return $this->unitItemConceptBaseUri.$unitId->getSerialization(); |
|
851 | 851 | } |
852 | 852 | |
853 | 853 | /** |
@@ -857,23 +857,23 @@ discard block |
||
857 | 857 | * @return UnitsParameter |
858 | 858 | * @throws ConstraintParameterException |
859 | 859 | */ |
860 | - private function parseUnitItem( ItemIdSnakValue $item ) { |
|
861 | - switch ( true ) { |
|
860 | + private function parseUnitItem(ItemIdSnakValue $item) { |
|
861 | + switch (true) { |
|
862 | 862 | case $item->isValue(): |
863 | - $unit = $this->parseUnitParameter( $item->getItemId() ); |
|
863 | + $unit = $this->parseUnitParameter($item->getItemId()); |
|
864 | 864 | return new UnitsParameter( |
865 | - [ $item->getItemId() ], |
|
866 | - [ UnboundedQuantityValue::newFromNumber( 1, $unit ) ], |
|
865 | + [$item->getItemId()], |
|
866 | + [UnboundedQuantityValue::newFromNumber(1, $unit)], |
|
867 | 867 | false |
868 | 868 | ); |
869 | 869 | case $item->isSomeValue(): |
870 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
870 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
871 | 871 | throw new ConstraintParameterException( |
872 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
873 | - ->withEntityId( new NumericPropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
872 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
873 | + ->withEntityId(new NumericPropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
874 | 874 | ); |
875 | 875 | case $item->isNoValue(): |
876 | - return new UnitsParameter( [], [], true ); |
|
876 | + return new UnitsParameter([], [], true); |
|
877 | 877 | } |
878 | 878 | } |
879 | 879 | |
@@ -883,36 +883,36 @@ discard block |
||
883 | 883 | * @throws ConstraintParameterException if the parameter is invalid or missing |
884 | 884 | * @return UnitsParameter |
885 | 885 | */ |
886 | - public function parseUnitsParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
887 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
886 | + public function parseUnitsParameter(array $constraintParameters, $constraintTypeItemId) { |
|
887 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
888 | 888 | $unitItems = []; |
889 | 889 | $unitQuantities = []; |
890 | 890 | $unitlessAllowed = false; |
891 | 891 | |
892 | - foreach ( $items as $item ) { |
|
893 | - $unit = $this->parseUnitItem( $item ); |
|
894 | - $unitItems = array_merge( $unitItems, $unit->getUnitItemIds() ); |
|
895 | - $unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() ); |
|
892 | + foreach ($items as $item) { |
|
893 | + $unit = $this->parseUnitItem($item); |
|
894 | + $unitItems = array_merge($unitItems, $unit->getUnitItemIds()); |
|
895 | + $unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities()); |
|
896 | 896 | $unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed(); |
897 | 897 | } |
898 | 898 | |
899 | - if ( $unitQuantities === [] && !$unitlessAllowed ) { |
|
899 | + if ($unitQuantities === [] && !$unitlessAllowed) { |
|
900 | 900 | throw new LogicException( |
901 | 901 | 'The "units" parameter is required, and yet we seem to be missing any allowed unit' |
902 | 902 | ); |
903 | 903 | } |
904 | 904 | |
905 | - return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed ); |
|
905 | + return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | private function getEntityTypeMapping(): array { |
909 | 909 | return [ |
910 | - $this->config->get( 'WBQualityConstraintsWikibaseItemId' ) => 'item', |
|
911 | - $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) => 'property', |
|
912 | - $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) => 'lexeme', |
|
913 | - $this->config->get( 'WBQualityConstraintsWikibaseFormId' ) => 'form', |
|
914 | - $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) => 'sense', |
|
915 | - $this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ) => 'mediainfo', |
|
910 | + $this->config->get('WBQualityConstraintsWikibaseItemId') => 'item', |
|
911 | + $this->config->get('WBQualityConstraintsWikibasePropertyId') => 'property', |
|
912 | + $this->config->get('WBQualityConstraintsWikibaseLexemeId') => 'lexeme', |
|
913 | + $this->config->get('WBQualityConstraintsWikibaseFormId') => 'form', |
|
914 | + $this->config->get('WBQualityConstraintsWikibaseSenseId') => 'sense', |
|
915 | + $this->config->get('WBQualityConstraintsWikibaseMediaInfoId') => 'mediainfo', |
|
916 | 916 | ]; |
917 | 917 | } |
918 | 918 | |
@@ -922,10 +922,10 @@ discard block |
||
922 | 922 | * @throws ConstraintParameterException if the parameter is invalid or missing |
923 | 923 | * @return EntityTypesParameter |
924 | 924 | */ |
925 | - public function parseEntityTypesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
925 | + public function parseEntityTypesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
926 | 926 | $entityTypes = []; |
927 | 927 | $entityTypeItemIds = []; |
928 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
928 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
929 | 929 | $itemIds = $this->parseItemIdsParameter( |
930 | 930 | $constraintParameters, |
931 | 931 | $constraintTypeItemId, |
@@ -934,22 +934,22 @@ discard block |
||
934 | 934 | ); |
935 | 935 | |
936 | 936 | $mapping = $this->getEntityTypeMapping(); |
937 | - foreach ( $itemIds as $itemId ) { |
|
938 | - $entityType = $this->mapItemId( $itemId, $mapping, $parameterId ); |
|
937 | + foreach ($itemIds as $itemId) { |
|
938 | + $entityType = $this->mapItemId($itemId, $mapping, $parameterId); |
|
939 | 939 | $entityTypes[] = $entityType; |
940 | 940 | $entityTypeItemIds[] = $itemId; |
941 | 941 | } |
942 | 942 | |
943 | - if ( empty( $entityTypes ) ) { |
|
943 | + if (empty($entityTypes)) { |
|
944 | 944 | // @codeCoverageIgnoreStart |
945 | 945 | throw new LogicException( |
946 | - 'The "entity types" parameter is required, ' . |
|
946 | + 'The "entity types" parameter is required, '. |
|
947 | 947 | 'and yet we seem to be missing any allowed entity type' |
948 | 948 | ); |
949 | 949 | // @codeCoverageIgnoreEnd |
950 | 950 | } |
951 | 951 | |
952 | - return new EntityTypesParameter( $entityTypes, $entityTypeItemIds ); |
|
952 | + return new EntityTypesParameter($entityTypes, $entityTypeItemIds); |
|
953 | 953 | } |
954 | 954 | |
955 | 955 | /** |
@@ -957,18 +957,18 @@ discard block |
||
957 | 957 | * @throws ConstraintParameterException if the parameter is invalid |
958 | 958 | * @return PropertyId[] |
959 | 959 | */ |
960 | - public function parseSeparatorsParameter( array $constraintParameters ) { |
|
961 | - $separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' ); |
|
960 | + public function parseSeparatorsParameter(array $constraintParameters) { |
|
961 | + $separatorId = $this->config->get('WBQualityConstraintsSeparatorId'); |
|
962 | 962 | |
963 | - if ( !array_key_exists( $separatorId, $constraintParameters ) ) { |
|
963 | + if (!array_key_exists($separatorId, $constraintParameters)) { |
|
964 | 964 | return []; |
965 | 965 | } |
966 | 966 | |
967 | 967 | $parameters = $constraintParameters[$separatorId]; |
968 | 968 | $separators = []; |
969 | 969 | |
970 | - foreach ( $parameters as $parameter ) { |
|
971 | - $separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId ); |
|
970 | + foreach ($parameters as $parameter) { |
|
971 | + $separators[] = $this->parsePropertyIdParameter($parameter, $separatorId); |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | return $separators; |
@@ -976,17 +976,17 @@ discard block |
||
976 | 976 | |
977 | 977 | private function getConstraintScopeContextTypeMapping(): array { |
978 | 978 | return [ |
979 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ) => Context::TYPE_STATEMENT, |
|
980 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ) => Context::TYPE_QUALIFIER, |
|
981 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ) => Context::TYPE_REFERENCE, |
|
979 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId') => Context::TYPE_STATEMENT, |
|
980 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId') => Context::TYPE_QUALIFIER, |
|
981 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId') => Context::TYPE_REFERENCE, |
|
982 | 982 | ]; |
983 | 983 | } |
984 | 984 | |
985 | 985 | private function getPropertyScopeContextTypeMapping(): array { |
986 | 986 | return [ |
987 | - $this->config->get( 'WBQualityConstraintsAsMainValueId' ) => Context::TYPE_STATEMENT, |
|
988 | - $this->config->get( 'WBQualityConstraintsAsQualifiersId' ) => Context::TYPE_QUALIFIER, |
|
989 | - $this->config->get( 'WBQualityConstraintsAsReferencesId' ) => Context::TYPE_REFERENCE, |
|
987 | + $this->config->get('WBQualityConstraintsAsMainValueId') => Context::TYPE_STATEMENT, |
|
988 | + $this->config->get('WBQualityConstraintsAsQualifiersId') => Context::TYPE_QUALIFIER, |
|
989 | + $this->config->get('WBQualityConstraintsAsReferencesId') => Context::TYPE_REFERENCE, |
|
990 | 990 | ]; |
991 | 991 | } |
992 | 992 | |
@@ -996,9 +996,9 @@ discard block |
||
996 | 996 | * @throws ConstraintParameterException if the parameter is invalid or missing |
997 | 997 | * @return string[] list of Context::TYPE_* constants |
998 | 998 | */ |
999 | - public function parsePropertyScopeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
999 | + public function parsePropertyScopeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
1000 | 1000 | $contextTypes = []; |
1001 | - $parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' ); |
|
1001 | + $parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId'); |
|
1002 | 1002 | $itemIds = $this->parseItemIdsParameter( |
1003 | 1003 | $constraintParameters, |
1004 | 1004 | $constraintTypeItemId, |
@@ -1007,14 +1007,14 @@ discard block |
||
1007 | 1007 | ); |
1008 | 1008 | |
1009 | 1009 | $mapping = $this->getPropertyScopeContextTypeMapping(); |
1010 | - foreach ( $itemIds as $itemId ) { |
|
1011 | - $contextTypes[] = $this->mapItemId( $itemId, $mapping, $parameterId ); |
|
1010 | + foreach ($itemIds as $itemId) { |
|
1011 | + $contextTypes[] = $this->mapItemId($itemId, $mapping, $parameterId); |
|
1012 | 1012 | } |
1013 | 1013 | |
1014 | - if ( empty( $contextTypes ) ) { |
|
1014 | + if (empty($contextTypes)) { |
|
1015 | 1015 | // @codeCoverageIgnoreStart |
1016 | 1016 | throw new LogicException( |
1017 | - 'The "property scope" parameter is required, ' . |
|
1017 | + 'The "property scope" parameter is required, '. |
|
1018 | 1018 | 'and yet we seem to be missing any allowed scope' |
1019 | 1019 | ); |
1020 | 1020 | // @codeCoverageIgnoreEnd |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | * @throws ConstraintParameterException |
74 | 74 | * @return array [ DataValue|null $min, DataValue|null $max, NumericPropertyId $property, array $parameters ] |
75 | 75 | */ |
76 | - private function parseConstraintParameters( Constraint $constraint ) { |
|
77 | - list( $min, $max ) = $this->constraintParameterParser->parseQuantityRangeParameter( |
|
76 | + private function parseConstraintParameters(Constraint $constraint) { |
|
77 | + list($min, $max) = $this->constraintParameterParser->parseQuantityRangeParameter( |
|
78 | 78 | $constraint->getConstraintParameters(), |
79 | 79 | $constraint->getConstraintTypeItemId() |
80 | 80 | ); |
@@ -84,15 +84,15 @@ discard block |
||
84 | 84 | ); |
85 | 85 | |
86 | 86 | $parameters = []; |
87 | - if ( $min !== null ) { |
|
88 | - $parameters['minimum_quantity'] = [ $min ]; |
|
87 | + if ($min !== null) { |
|
88 | + $parameters['minimum_quantity'] = [$min]; |
|
89 | 89 | } |
90 | - if ( $max !== null ) { |
|
91 | - $parameters['maximum_quantity'] = [ $max ]; |
|
90 | + if ($max !== null) { |
|
91 | + $parameters['maximum_quantity'] = [$max]; |
|
92 | 92 | } |
93 | - $parameters['property'] = [ $property ]; |
|
93 | + $parameters['property'] = [$property]; |
|
94 | 94 | |
95 | - return [ $min, $max, $property, $parameters ]; |
|
95 | + return [$min, $max, $property, $parameters]; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @return bool |
104 | 104 | */ |
105 | - private function rangeInYears( $min, $max ) { |
|
106 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
105 | + private function rangeInYears($min, $max) { |
|
106 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
107 | 107 | |
108 | - if ( $min !== null && $min->getUnit() === $yearUnit ) { |
|
108 | + if ($min !== null && $min->getUnit() === $yearUnit) { |
|
109 | 109 | return true; |
110 | 110 | } |
111 | - if ( $max !== null && $max->getUnit() === $yearUnit ) { |
|
111 | + if ($max !== null && $max->getUnit() === $yearUnit) { |
|
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | |
@@ -124,30 +124,30 @@ discard block |
||
124 | 124 | * @throws ConstraintParameterException |
125 | 125 | * @return CheckResult |
126 | 126 | */ |
127 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
128 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
129 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
127 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
128 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
129 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | $parameters = []; |
133 | 133 | |
134 | 134 | $snak = $context->getSnak(); |
135 | 135 | |
136 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
136 | + if (!$snak instanceof PropertyValueSnak) { |
|
137 | 137 | // nothing to check |
138 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
138 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $minuend = $snak->getDataValue(); |
142 | 142 | '@phan-var \DataValues\TimeValue|\DataValues\QuantityValue|\DataValues\UnboundedQuantityValue $minuend'; |
143 | 143 | |
144 | 144 | /** @var NumericPropertyId $property */ |
145 | - list( $min, $max, $property, $parameters ) = $this->parseConstraintParameters( $constraint ); |
|
145 | + list($min, $max, $property, $parameters) = $this->parseConstraintParameters($constraint); |
|
146 | 146 | |
147 | 147 | // checks only the first occurrence of the referenced property |
148 | - foreach ( $context->getSnakGroup( Context::GROUP_NON_DEPRECATED ) as $otherSnak ) { |
|
148 | + foreach ($context->getSnakGroup(Context::GROUP_NON_DEPRECATED) as $otherSnak) { |
|
149 | 149 | if ( |
150 | - !$property->equals( $otherSnak->getPropertyId() ) || |
|
150 | + !$property->equals($otherSnak->getPropertyId()) || |
|
151 | 151 | !$otherSnak instanceof PropertyValueSnak |
152 | 152 | ) { |
153 | 153 | continue; |
@@ -155,30 +155,29 @@ discard block |
||
155 | 155 | |
156 | 156 | $subtrahend = $otherSnak->getDataValue(); |
157 | 157 | '@phan-var \DataValues\TimeValue|\DataValues\QuantityValue|\DataValues\UnboundedQuantityValue $subtrahend'; |
158 | - if ( $subtrahend->getType() === $minuend->getType() ) { |
|
159 | - $diff = $this->rangeInYears( $min, $max ) && $minuend->getType() === 'time' ? |
|
160 | - $this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) : |
|
161 | - $this->rangeCheckerHelper->getDifference( $minuend, $subtrahend ); |
|
158 | + if ($subtrahend->getType() === $minuend->getType()) { |
|
159 | + $diff = $this->rangeInYears($min, $max) && $minuend->getType() === 'time' ? |
|
160 | + $this->rangeCheckerHelper->getDifferenceInYears($minuend, $subtrahend) : $this->rangeCheckerHelper->getDifference($minuend, $subtrahend); |
|
162 | 161 | |
163 | - if ( $this->rangeCheckerHelper->getComparison( $min, $diff ) > 0 || |
|
164 | - $this->rangeCheckerHelper->getComparison( $diff, $max ) > 0 |
|
162 | + if ($this->rangeCheckerHelper->getComparison($min, $diff) > 0 || |
|
163 | + $this->rangeCheckerHelper->getComparison($diff, $max) > 0 |
|
165 | 164 | ) { |
166 | 165 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
167 | - $openness = $min !== null ? ( $max !== null ? '' : '-rightopen' ) : '-leftopen'; |
|
166 | + $openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen'; |
|
168 | 167 | // possible message keys: |
169 | 168 | // wbqc-violation-message-diff-within-range |
170 | 169 | // wbqc-violation-message-diff-within-range-leftopen |
171 | 170 | // wbqc-violation-message-diff-within-range-rightopen |
172 | - $message = ( new ViolationMessage( "wbqc-violation-message-diff-within-range$openness" ) ) |
|
173 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
174 | - ->withDataValue( $minuend, Role::OBJECT ) |
|
175 | - ->withEntityId( $otherSnak->getPropertyId(), Role::PREDICATE ) |
|
176 | - ->withDataValue( $subtrahend, Role::OBJECT ); |
|
177 | - if ( $min !== null ) { |
|
178 | - $message = $message->withDataValue( $min, Role::OBJECT ); |
|
171 | + $message = (new ViolationMessage("wbqc-violation-message-diff-within-range$openness")) |
|
172 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
173 | + ->withDataValue($minuend, Role::OBJECT) |
|
174 | + ->withEntityId($otherSnak->getPropertyId(), Role::PREDICATE) |
|
175 | + ->withDataValue($subtrahend, Role::OBJECT); |
|
176 | + if ($min !== null) { |
|
177 | + $message = $message->withDataValue($min, Role::OBJECT); |
|
179 | 178 | } |
180 | - if ( $max !== null ) { |
|
181 | - $message = $message->withDataValue( $max, Role::OBJECT ); |
|
179 | + if ($max !== null) { |
|
180 | + $message = $message->withDataValue($max, Role::OBJECT); |
|
182 | 181 | } |
183 | 182 | $status = CheckResult::STATUS_VIOLATION; |
184 | 183 | } else { |
@@ -186,17 +185,17 @@ discard block |
||
186 | 185 | $status = CheckResult::STATUS_COMPLIANCE; |
187 | 186 | } |
188 | 187 | } else { |
189 | - $message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-must-have-equal-types' ); |
|
188 | + $message = new ViolationMessage('wbqc-violation-message-diff-within-range-must-have-equal-types'); |
|
190 | 189 | $status = CheckResult::STATUS_VIOLATION; |
191 | 190 | } |
192 | 191 | |
193 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
192 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
194 | 193 | } |
195 | 194 | |
196 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
195 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
197 | 196 | } |
198 | 197 | |
199 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
198 | + public function checkConstraintParameters(Constraint $constraint) { |
|
200 | 199 | $constraintParameters = $constraint->getConstraintParameters(); |
201 | 200 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
202 | 201 | $exceptions = []; |
@@ -205,7 +204,7 @@ discard block |
||
205 | 204 | $constraintParameters, |
206 | 205 | $constraintTypeItemId |
207 | 206 | ); |
208 | - } catch ( ConstraintParameterException $e ) { |
|
207 | + } catch (ConstraintParameterException $e) { |
|
209 | 208 | $exceptions[] = $e; |
210 | 209 | } |
211 | 210 | try { |
@@ -213,7 +212,7 @@ discard block |
||
213 | 212 | $constraintParameters, |
214 | 213 | $constraintTypeItemId |
215 | 214 | ); |
216 | - } catch ( ConstraintParameterException $e ) { |
|
215 | + } catch (ConstraintParameterException $e) { |
|
217 | 216 | $exceptions[] = $e; |
218 | 217 | } |
219 | 218 | return $exceptions; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @codeCoverageIgnore This method is purely declarative. |
80 | 80 | */ |
81 | 81 | public function getDefaultContextTypes() { |
82 | - return [ Context::TYPE_STATEMENT ]; |
|
82 | + return [Context::TYPE_STATEMENT]; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** @codeCoverageIgnore This method is purely declarative. */ |
@@ -96,31 +96,31 @@ discard block |
||
96 | 96 | * @return CheckResult |
97 | 97 | * @throws \ConfigException |
98 | 98 | */ |
99 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
100 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
101 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
99 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
100 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
101 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
102 | 102 | } |
103 | 103 | $snak = $context->getSnak(); |
104 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
104 | + if (!$snak instanceof PropertyValueSnak) { |
|
105 | 105 | // nothing to check |
106 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
106 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | $dataValue = $snak->getDataValue(); |
110 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
110 | + if (!$dataValue instanceof EntityIdValue) { |
|
111 | 111 | // wrong data type |
112 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
113 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
114 | - ->withDataValueType( 'wikibase-entityid' ); |
|
115 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
112 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
113 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
114 | + ->withDataValueType('wikibase-entityid'); |
|
115 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $objectId = $dataValue->getEntityId(); |
119 | - $objectItem = $this->entityLookup->getEntity( $objectId ); |
|
120 | - if ( !( $objectItem instanceof StatementListProvider ) ) { |
|
119 | + $objectItem = $this->entityLookup->getEntity($objectId); |
|
120 | + if (!($objectItem instanceof StatementListProvider)) { |
|
121 | 121 | // object was deleted/doesn't exist |
122 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
123 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
122 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
123 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
124 | 124 | } |
125 | 125 | /** @var Statement[] $objectStatements */ |
126 | 126 | $objectStatements = $objectItem->getStatements()->toArray(); |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | $subjectId = $context->getEntity()->getId(); |
129 | 129 | $subjectStatements = $context->getEntity()->getStatements()->toArray(); |
130 | 130 | /** @var String[] $startPropertyIds */ |
131 | - $startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS ); |
|
131 | + $startPropertyIds = $this->config->get(self::CONFIG_VARIABLE_START_PROPERTY_IDS); |
|
132 | 132 | /** @var String[] $endPropertyIds */ |
133 | - $endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS ); |
|
133 | + $endPropertyIds = $this->config->get(self::CONFIG_VARIABLE_END_PROPERTY_IDS); |
|
134 | 134 | $subjectStartValue = $this->getExtremeValue( |
135 | 135 | $startPropertyIds, |
136 | 136 | $subjectStatements, |
@@ -152,15 +152,15 @@ discard block |
||
152 | 152 | 'end' |
153 | 153 | ); |
154 | 154 | if ( |
155 | - $this->rangeCheckerHelper->getComparison( $subjectStartValue, $subjectEndValue ) <= 0 && |
|
156 | - $this->rangeCheckerHelper->getComparison( $objectStartValue, $objectEndValue ) <= 0 && ( |
|
157 | - $this->rangeCheckerHelper->getComparison( $subjectEndValue, $objectStartValue ) < 0 || |
|
158 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectStartValue ) < 0 |
|
155 | + $this->rangeCheckerHelper->getComparison($subjectStartValue, $subjectEndValue) <= 0 && |
|
156 | + $this->rangeCheckerHelper->getComparison($objectStartValue, $objectEndValue) <= 0 && ( |
|
157 | + $this->rangeCheckerHelper->getComparison($subjectEndValue, $objectStartValue) < 0 || |
|
158 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectStartValue) < 0 |
|
159 | 159 | ) |
160 | 160 | ) { |
161 | 161 | if ( |
162 | 162 | $subjectEndValue == null || |
163 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectEndValue ) < 0 |
|
163 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectEndValue) < 0 |
|
164 | 164 | ) { |
165 | 165 | $earlierEntityId = $objectId; |
166 | 166 | $minEndValue = $objectEndValue; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $message = null; |
184 | 184 | $status = CheckResult::STATUS_COMPLIANCE; |
185 | 185 | } |
186 | - return new CheckResult( $context, $constraint, [], $status, $message ); |
|
186 | + return new CheckResult($context, $constraint, [], $status, $message); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @return DataValue|null |
195 | 195 | */ |
196 | - private function getExtremeValue( $extremePropertyIds, $statements, $startOrEnd ) { |
|
197 | - if ( $startOrEnd !== 'start' && $startOrEnd !== 'end' ) { |
|
198 | - throw new \InvalidArgumentException( '$startOrEnd must be \'start\' or \'end\'.' ); |
|
196 | + private function getExtremeValue($extremePropertyIds, $statements, $startOrEnd) { |
|
197 | + if ($startOrEnd !== 'start' && $startOrEnd !== 'end') { |
|
198 | + throw new \InvalidArgumentException('$startOrEnd must be \'start\' or \'end\'.'); |
|
199 | 199 | } |
200 | 200 | $extremeValue = null; |
201 | - foreach ( $extremePropertyIds as $extremePropertyId ) { |
|
202 | - $statementList = new StatementList( ...$statements ); |
|
203 | - $extremeStatements = $statementList->getByPropertyId( new NumericPropertyId( $extremePropertyId ) ); |
|
201 | + foreach ($extremePropertyIds as $extremePropertyId) { |
|
202 | + $statementList = new StatementList(...$statements); |
|
203 | + $extremeStatements = $statementList->getByPropertyId(new NumericPropertyId($extremePropertyId)); |
|
204 | 204 | /** @var Statement $extremeStatement */ |
205 | - foreach ( $extremeStatements as $extremeStatement ) { |
|
206 | - if ( $extremeStatement->getRank() !== Statement::RANK_DEPRECATED ) { |
|
205 | + foreach ($extremeStatements as $extremeStatement) { |
|
206 | + if ($extremeStatement->getRank() !== Statement::RANK_DEPRECATED) { |
|
207 | 207 | $snak = $extremeStatement->getMainSnak(); |
208 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
208 | + if (!$snak instanceof PropertyValueSnak) { |
|
209 | 209 | return null; |
210 | 210 | } else { |
211 | 211 | $comparison = $this->rangeCheckerHelper->getComparison( |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | ); |
215 | 215 | if ( |
216 | 216 | $extremeValue === null || |
217 | - ( $startOrEnd === 'start' && $comparison < 0 ) || |
|
218 | - ( $startOrEnd === 'end' && $comparison > 0 ) |
|
217 | + ($startOrEnd === 'start' && $comparison < 0) || |
|
218 | + ($startOrEnd === 'end' && $comparison > 0) |
|
219 | 219 | ) { |
220 | 220 | $extremeValue = $snak->getDataValue(); |
221 | 221 | } |
@@ -245,17 +245,16 @@ discard block |
||
245 | 245 | DataValue $maxStartValue |
246 | 246 | ) { |
247 | 247 | $messageKey = $earlierEntityId === $subjectId ? |
248 | - 'wbqc-violation-message-contemporary-subject-earlier' : |
|
249 | - 'wbqc-violation-message-contemporary-value-earlier'; |
|
250 | - return ( new ViolationMessage( $messageKey ) ) |
|
251 | - ->withEntityId( $subjectId, Role::SUBJECT ) |
|
252 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
253 | - ->withEntityId( $objectId, Role::OBJECT ) |
|
254 | - ->withDataValue( $minEndValue, Role::OBJECT ) |
|
255 | - ->withDataValue( $maxStartValue, Role::OBJECT ); |
|
248 | + 'wbqc-violation-message-contemporary-subject-earlier' : 'wbqc-violation-message-contemporary-value-earlier'; |
|
249 | + return (new ViolationMessage($messageKey)) |
|
250 | + ->withEntityId($subjectId, Role::SUBJECT) |
|
251 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
252 | + ->withEntityId($objectId, Role::OBJECT) |
|
253 | + ->withDataValue($minEndValue, Role::OBJECT) |
|
254 | + ->withDataValue($maxStartValue, Role::OBJECT); |
|
256 | 255 | } |
257 | 256 | |
258 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
257 | + public function checkConstraintParameters(Constraint $constraint) { |
|
259 | 258 | // no parameters |
260 | 259 | return []; |
261 | 260 | } |
@@ -25,22 +25,22 @@ |
||
25 | 25 | */ |
26 | 26 | private const NULL_PROPERTY_ID = 'P2147483647'; |
27 | 27 | |
28 | - public function __construct( ContextCursor $contextCursor ) { |
|
28 | + public function __construct(ContextCursor $contextCursor) { |
|
29 | 29 | $constraint = new Constraint( |
30 | 30 | 'null', |
31 | - new NumericPropertyId( self::NULL_PROPERTY_ID ), |
|
31 | + new NumericPropertyId(self::NULL_PROPERTY_ID), |
|
32 | 32 | 'none', |
33 | 33 | [] |
34 | 34 | ); |
35 | - parent::__construct( $contextCursor, $constraint ); |
|
35 | + parent::__construct($contextCursor, $constraint); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function getConstraint() { |
39 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
39 | + throw new DomainException('NullResult holds no constraint'); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function getConstraintId() { |
43 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
43 | + throw new DomainException('NullResult holds no constraint'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -10,14 +10,13 @@ |
||
10 | 10 | */ |
11 | 11 | class ConstraintDeserializer { |
12 | 12 | |
13 | - public function deserialize( array $serialization ) { |
|
13 | + public function deserialize(array $serialization) { |
|
14 | 14 | return new Constraint( |
15 | 15 | $serialization['id'], |
16 | - new NumericPropertyId( $serialization['pid'] ), |
|
16 | + new NumericPropertyId($serialization['pid']), |
|
17 | 17 | $serialization['qid'], |
18 | - array_key_exists( 'params', $serialization ) ? |
|
19 | - $serialization['params'] : |
|
20 | - [] |
|
18 | + array_key_exists('params', $serialization) ? |
|
19 | + $serialization['params'] : [] |
|
21 | 20 | ); |
22 | 21 | } |
23 | 22 |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | * @param CachedCheckResults $checkResults |
51 | 51 | * @return CachedCheckConstraintsResponse |
52 | 52 | */ |
53 | - public function render( CachedCheckResults $checkResults ) { |
|
53 | + public function render(CachedCheckResults $checkResults) { |
|
54 | 54 | $response = []; |
55 | - foreach ( $checkResults->getArray() as $checkResult ) { |
|
56 | - $resultArray = $this->checkResultToArray( $checkResult ); |
|
57 | - $checkResult->getContextCursor()->storeCheckResultInArray( $resultArray, $response ); |
|
55 | + foreach ($checkResults->getArray() as $checkResult) { |
|
56 | + $resultArray = $this->checkResultToArray($checkResult); |
|
57 | + $checkResult->getContextCursor()->storeCheckResultInArray($resultArray, $response); |
|
58 | 58 | } |
59 | 59 | return new CachedCheckConstraintsResponse( |
60 | 60 | $response, |
@@ -62,19 +62,19 @@ discard block |
||
62 | 62 | ); |
63 | 63 | } |
64 | 64 | |
65 | - public function checkResultToArray( CheckResult $checkResult ) { |
|
66 | - if ( $checkResult instanceof NullResult ) { |
|
65 | + public function checkResultToArray(CheckResult $checkResult) { |
|
66 | + if ($checkResult instanceof NullResult) { |
|
67 | 67 | return null; |
68 | 68 | } |
69 | 69 | |
70 | 70 | $constraintId = $checkResult->getConstraint()->getConstraintId(); |
71 | 71 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
72 | - $constraintPropertyId = new NumericPropertyId( $checkResult->getContextCursor()->getSnakPropertyId() ); |
|
72 | + $constraintPropertyId = new NumericPropertyId($checkResult->getContextCursor()->getSnakPropertyId()); |
|
73 | 73 | |
74 | - $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
74 | + $title = $this->entityTitleLookup->getTitleForId($constraintPropertyId); |
|
75 | 75 | $talkTitle = $title->getTalkPageIfDefined(); |
76 | - $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
77 | - $link = $title->getFullURL() . '#' . $constraintId; |
|
76 | + $typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId)); |
|
77 | + $link = $title->getFullURL().'#'.$constraintId; |
|
78 | 78 | |
79 | 79 | $constraint = [ |
80 | 80 | 'id' => $constraintId, |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | 'constraint' => $constraint |
91 | 91 | ]; |
92 | 92 | $message = $checkResult->getMessage(); |
93 | - if ( $message ) { |
|
94 | - $result['message-html'] = $this->violationMessageRenderer->render( $message ); |
|
93 | + if ($message) { |
|
94 | + $result['message-html'] = $this->violationMessageRenderer->render($message); |
|
95 | 95 | } |
96 | - if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) { |
|
96 | + if ($checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT) { |
|
97 | 97 | $result['claim'] = $checkResult->getContextCursor()->getStatementGuid(); |
98 | 98 | } |
99 | 99 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
100 | - if ( $cachingMetadataArray !== null ) { |
|
100 | + if ($cachingMetadataArray !== null) { |
|
101 | 101 | $result['cached'] = $cachingMetadataArray; |
102 | 102 | } |
103 | 103 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @return bool |
17 | 17 | * @throws DBUnexpectedError |
18 | 18 | */ |
19 | - public function insertBatch( array $constraints ); |
|
19 | + public function insertBatch(array $constraints); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Delete all constraints for the property ID. |
@@ -25,6 +25,6 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @throws DBUnexpectedError |
27 | 27 | */ |
28 | - public function deleteForProperty( NumericPropertyId $propertyId ); |
|
28 | + public function deleteForProperty(NumericPropertyId $propertyId); |
|
29 | 29 | |
30 | 30 | } |
@@ -24,16 +24,16 @@ discard block |
||
24 | 24 | * then using the main DBLoadBalancer service may be incorrect. |
25 | 25 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
26 | 26 | */ |
27 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
27 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
28 | 28 | $this->lb = $lb; |
29 | 29 | $this->dbName = $dbName; |
30 | 30 | } |
31 | 31 | |
32 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
33 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
32 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
33 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
34 | 34 | |
35 | - if ( strlen( $json ) > 50000 ) { |
|
36 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
35 | + if (strlen($json) > 50000) { |
|
36 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | return $json; |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | * @throws DBUnexpectedError |
46 | 46 | * @return bool |
47 | 47 | */ |
48 | - public function insertBatch( array $constraints ) { |
|
48 | + public function insertBatch(array $constraints) { |
|
49 | 49 | $accumulator = array_map( |
50 | - function ( Constraint $constraint ) { |
|
50 | + function(Constraint $constraint) { |
|
51 | 51 | return [ |
52 | 52 | 'constraint_guid' => $constraint->getConstraintId(), |
53 | 53 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
54 | 54 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
55 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
55 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
56 | 56 | ]; |
57 | 57 | }, |
58 | 58 | $constraints |
59 | 59 | ); |
60 | 60 | |
61 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_PRIMARY, [], $this->dbName ); |
|
62 | - return $dbw->insert( 'wbqc_constraints', $accumulator, __METHOD__ ); |
|
61 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_PRIMARY, [], $this->dbName); |
|
62 | + return $dbw->insert('wbqc_constraints', $accumulator, __METHOD__); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @throws DBUnexpectedError |
71 | 71 | */ |
72 | - public function deleteForProperty( NumericPropertyId $propertyId ) { |
|
73 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_PRIMARY, [], $this->dbName ); |
|
72 | + public function deleteForProperty(NumericPropertyId $propertyId) { |
|
73 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_PRIMARY, [], $this->dbName); |
|
74 | 74 | $dbw->delete( |
75 | 75 | 'wbqc_constraints', |
76 | 76 | [ |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @param BagOStuff $cache |
28 | 28 | */ |
29 | - public function __construct( BagOStuff $cache ) { |
|
29 | + public function __construct(BagOStuff $cache) { |
|
30 | 30 | $this->cache = $cache; |
31 | 31 | } |
32 | 32 | |
@@ -37,17 +37,17 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @throws \Wikimedia\Assert\ParameterTypeException |
39 | 39 | */ |
40 | - private function makeKey( $id ) { |
|
41 | - if ( empty( trim( $id ) ) ) { |
|
42 | - throw new ParameterTypeException( '$id', 'non-empty string' ); |
|
40 | + private function makeKey($id) { |
|
41 | + if (empty(trim($id))) { |
|
42 | + throw new ParameterTypeException('$id', 'non-empty string'); |
|
43 | 43 | } |
44 | 44 | |
45 | - Assert::parameterType( 'string', $id, '$id' ); |
|
45 | + Assert::parameterType('string', $id, '$id'); |
|
46 | 46 | |
47 | 47 | return $this->cache->makeKey( |
48 | 48 | 'WikibaseQualityConstraints', |
49 | 49 | 'ExpiryLock', |
50 | - (string)$id |
|
50 | + (string) $id |
|
51 | 51 | ); |
52 | 52 | } |
53 | 53 | |
@@ -59,15 +59,15 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @throws \Wikimedia\Assert\ParameterTypeException |
61 | 61 | */ |
62 | - public function lock( $id, ConvertibleTimestamp $expiryTimestamp ) { |
|
62 | + public function lock($id, ConvertibleTimestamp $expiryTimestamp) { |
|
63 | 63 | |
64 | - $cacheId = $this->makeKey( $id ); |
|
64 | + $cacheId = $this->makeKey($id); |
|
65 | 65 | |
66 | - if ( !$this->isLockedInternal( $cacheId ) ) { |
|
66 | + if (!$this->isLockedInternal($cacheId)) { |
|
67 | 67 | return $this->cache->set( |
68 | 68 | $cacheId, |
69 | - $expiryTimestamp->getTimestamp( TS_UNIX ), |
|
70 | - (int)$expiryTimestamp->getTimestamp( TS_UNIX ) |
|
69 | + $expiryTimestamp->getTimestamp(TS_UNIX), |
|
70 | + (int) $expiryTimestamp->getTimestamp(TS_UNIX) |
|
71 | 71 | ); |
72 | 72 | } else { |
73 | 73 | return false; |
@@ -81,20 +81,20 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @throws \Wikimedia\Assert\ParameterTypeException |
83 | 83 | */ |
84 | - private function isLockedInternal( $cacheId ) { |
|
85 | - $expiryTime = $this->cache->get( $cacheId ); |
|
86 | - if ( !$expiryTime ) { |
|
84 | + private function isLockedInternal($cacheId) { |
|
85 | + $expiryTime = $this->cache->get($cacheId); |
|
86 | + if (!$expiryTime) { |
|
87 | 87 | return false; |
88 | 88 | } |
89 | 89 | |
90 | 90 | try { |
91 | - $lockExpiryTimeStamp = new ConvertibleTimestamp( $expiryTime ); |
|
92 | - } catch ( TimestampException $exception ) { |
|
91 | + $lockExpiryTimeStamp = new ConvertibleTimestamp($expiryTime); |
|
92 | + } catch (TimestampException $exception) { |
|
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | |
96 | 96 | $now = new ConvertibleTimestamp(); |
97 | - if ( $now->timestamp < $lockExpiryTimeStamp->timestamp ) { |
|
97 | + if ($now->timestamp < $lockExpiryTimeStamp->timestamp) { |
|
98 | 98 | return true; |
99 | 99 | } else { |
100 | 100 | return false; |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @throws \Wikimedia\Assert\ParameterTypeException |
110 | 110 | */ |
111 | - public function isLocked( $id ) { |
|
112 | - return $this->isLockedInternal( $this->makeKey( $id ) ); |
|
111 | + public function isLocked($id) { |
|
112 | + return $this->isLockedInternal($this->makeKey($id)); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | } |