@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | * @param array $parameters |
78 | 78 | * @throws ConstraintParameterException |
79 | 79 | */ |
80 | - public function checkError( array $parameters ) { |
|
81 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
80 | + public function checkError(array $parameters) { |
|
81 | + if (array_key_exists('@error', $parameters)) { |
|
82 | 82 | $error = $parameters['@error']; |
83 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
83 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
84 | 84 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
85 | 85 | } else { |
86 | 86 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
87 | 87 | } |
88 | - throw new ConstraintParameterException( wfMessage( $msg )->escaped() ); |
|
88 | + throw new ConstraintParameterException(wfMessage($msg)->escaped()); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | * @param string $parameterId |
96 | 96 | * @throws ConstraintParameterException |
97 | 97 | */ |
98 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
99 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
98 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
99 | + if (count($parameters[$parameterId]) !== 1) { |
|
100 | 100 | throw new ConstraintParameterException( |
101 | - wfMessage( 'wbqc-violation-message-parameter-single' ) |
|
102 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
101 | + wfMessage('wbqc-violation-message-parameter-single') |
|
102 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
103 | 103 | ->escaped() |
104 | 104 | ); |
105 | 105 | } |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * @return void |
113 | 113 | * @throws ConstraintParameterException |
114 | 114 | */ |
115 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
116 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
115 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
116 | + if (!($snak instanceof PropertyValueSnak)) { |
|
117 | 117 | throw new ConstraintParameterException( |
118 | - wfMessage( 'wbqc-violation-message-parameter-value' ) |
|
119 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
118 | + wfMessage('wbqc-violation-message-parameter-value') |
|
119 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
120 | 120 | ->escaped() |
121 | 121 | ); |
122 | 122 | } |
@@ -129,18 +129,18 @@ discard block |
||
129 | 129 | * @throws ConstraintParameterException |
130 | 130 | * @return EntityId |
131 | 131 | */ |
132 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
133 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
134 | - $this->requireValueParameter( $snak, $parameterId ); |
|
132 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
133 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
134 | + $this->requireValueParameter($snak, $parameterId); |
|
135 | 135 | $value = $snak->getDataValue(); |
136 | - if ( $value instanceof EntityIdValue ) { |
|
136 | + if ($value instanceof EntityIdValue) { |
|
137 | 137 | return $value->getEntityId(); |
138 | 138 | } else { |
139 | 139 | throw new ConstraintParameterException( |
140 | - wfMessage( 'wbqc-violation-message-parameter-entity' ) |
|
140 | + wfMessage('wbqc-violation-message-parameter-entity') |
|
141 | 141 | ->rawParams( |
142 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
143 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
142 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
143 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
144 | 144 | ) |
145 | 145 | ->escaped() |
146 | 146 | ); |
@@ -153,21 +153,21 @@ discard block |
||
153 | 153 | * @throws ConstraintParameterException if the parameter is invalid or missing |
154 | 154 | * @return string[] class entity ID serializations |
155 | 155 | */ |
156 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
157 | - $this->checkError( $constraintParameters ); |
|
158 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
159 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
156 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
157 | + $this->checkError($constraintParameters); |
|
158 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
159 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
160 | 160 | throw new ConstraintParameterException( |
161 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
162 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
163 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $classId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
161 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
162 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
163 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($classId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
164 | 164 | ->escaped() |
165 | 165 | ); |
166 | 166 | } |
167 | 167 | |
168 | 168 | $classes = []; |
169 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
170 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
169 | + foreach ($constraintParameters[$classId] as $class) { |
|
170 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
171 | 171 | } |
172 | 172 | return $classes; |
173 | 173 | } |
@@ -178,24 +178,24 @@ discard block |
||
178 | 178 | * @throws ConstraintParameterException if the parameter is invalid or missing |
179 | 179 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
180 | 180 | */ |
181 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
182 | - $this->checkError( $constraintParameters ); |
|
183 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
184 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
181 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
182 | + $this->checkError($constraintParameters); |
|
183 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
184 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
185 | 185 | throw new ConstraintParameterException( |
186 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
187 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
188 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
186 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
187 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
188 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
189 | 189 | ->escaped() |
190 | 190 | ); |
191 | 191 | } |
192 | 192 | |
193 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
194 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
195 | - $instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ); |
|
196 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ); |
|
197 | - $instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ); |
|
198 | - switch ( $relationEntityId ) { |
|
193 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
194 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
195 | + $instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId'); |
|
196 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId'); |
|
197 | + $instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId'); |
|
198 | + switch ($relationEntityId) { |
|
199 | 199 | case $instanceId: |
200 | 200 | return 'instance'; |
201 | 201 | case $subclassId: |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | return 'instanceOrSubclass'; |
205 | 205 | default: |
206 | 206 | throw new ConstraintParameterException( |
207 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
208 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
209 | - ->numParams( 3 ) |
|
210 | - ->rawParams( $this->constraintParameterRenderer->formatItemIdList( |
|
211 | - [ $instanceId, $subclassId, $instanceOrSubclassId ], |
|
207 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
208 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
209 | + ->numParams(3) |
|
210 | + ->rawParams($this->constraintParameterRenderer->formatItemIdList( |
|
211 | + [$instanceId, $subclassId, $instanceOrSubclassId], |
|
212 | 212 | Role::CONSTRAINT_PARAMETER_VALUE |
213 | - ) ) |
|
213 | + )) |
|
214 | 214 | ->escaped() |
215 | 215 | ); |
216 | 216 | } |
@@ -223,21 +223,21 @@ discard block |
||
223 | 223 | * @throws ConstraintParameterException |
224 | 224 | * @return PropertyId |
225 | 225 | */ |
226 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
227 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
228 | - $this->requireValueParameter( $snak, $parameterId ); |
|
226 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
227 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
228 | + $this->requireValueParameter($snak, $parameterId); |
|
229 | 229 | $value = $snak->getDataValue(); |
230 | - if ( $value instanceof EntityIdValue ) { |
|
230 | + if ($value instanceof EntityIdValue) { |
|
231 | 231 | $id = $value->getEntityId(); |
232 | - if ( $id instanceof PropertyId ) { |
|
232 | + if ($id instanceof PropertyId) { |
|
233 | 233 | return $id; |
234 | 234 | } |
235 | 235 | } |
236 | 236 | throw new ConstraintParameterException( |
237 | - wfMessage( 'wbqc-violation-message-parameter-property' ) |
|
237 | + wfMessage('wbqc-violation-message-parameter-property') |
|
238 | 238 | ->rawParams( |
239 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
240 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
239 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
240 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
241 | 241 | ) |
242 | 242 | ->escaped() |
243 | 243 | ); |
@@ -250,34 +250,34 @@ discard block |
||
250 | 250 | * @throws ConstraintParameterException if the parameter is invalid or missing |
251 | 251 | * @return PropertyId |
252 | 252 | */ |
253 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
254 | - $this->checkError( $constraintParameters ); |
|
255 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
256 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
253 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
254 | + $this->checkError($constraintParameters); |
|
255 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
256 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
257 | 257 | throw new ConstraintParameterException( |
258 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
259 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
260 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
258 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
259 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
260 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
261 | 261 | ->escaped() |
262 | 262 | ); |
263 | 263 | } |
264 | 264 | |
265 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
266 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
265 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
266 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
267 | 267 | } |
268 | 268 | |
269 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
269 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
270 | 270 | $dataValue = $snak->getDataValue(); |
271 | - if ( $dataValue instanceof EntityIdValue && |
|
271 | + if ($dataValue instanceof EntityIdValue && |
|
272 | 272 | $dataValue->getEntityId() instanceof ItemId |
273 | 273 | ) { |
274 | - return ItemIdSnakValue::fromItemId( $dataValue->getEntityId() ); |
|
274 | + return ItemIdSnakValue::fromItemId($dataValue->getEntityId()); |
|
275 | 275 | } else { |
276 | 276 | throw new ConstraintParameterException( |
277 | - wfMessage( 'wbqc-violation-message-parameter-item' ) |
|
277 | + wfMessage('wbqc-violation-message-parameter-item') |
|
278 | 278 | ->rawParams( |
279 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
280 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
279 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
280 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
281 | 281 | ) |
282 | 282 | ->escaped() |
283 | 283 | ); |
@@ -291,15 +291,15 @@ discard block |
||
291 | 291 | * @throws ConstraintParameterException if the parameter is invalid or missing |
292 | 292 | * @return ItemIdSnakValue[] array of values |
293 | 293 | */ |
294 | - public function parseItemsParameter( array $constraintParameters, $constraintTypeItemId, $required ) { |
|
295 | - $this->checkError( $constraintParameters ); |
|
296 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
297 | - if ( !array_key_exists( $qualifierId, $constraintParameters ) ) { |
|
298 | - if ( $required ) { |
|
294 | + public function parseItemsParameter(array $constraintParameters, $constraintTypeItemId, $required) { |
|
295 | + $this->checkError($constraintParameters); |
|
296 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
297 | + if (!array_key_exists($qualifierId, $constraintParameters)) { |
|
298 | + if ($required) { |
|
299 | 299 | throw new ConstraintParameterException( |
300 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
301 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
302 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
300 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
301 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
302 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
303 | 303 | ->escaped() |
304 | 304 | ); |
305 | 305 | } else { |
@@ -308,11 +308,11 @@ discard block |
||
308 | 308 | } |
309 | 309 | |
310 | 310 | $values = []; |
311 | - foreach ( $constraintParameters[$qualifierId] as $parameter ) { |
|
312 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
313 | - switch ( true ) { |
|
311 | + foreach ($constraintParameters[$qualifierId] as $parameter) { |
|
312 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
313 | + switch (true) { |
|
314 | 314 | case $snak instanceof PropertyValueSnak: |
315 | - $values[] = $this->parseItemIdParameter( $snak, $qualifierId ); |
|
315 | + $values[] = $this->parseItemIdParameter($snak, $qualifierId); |
|
316 | 316 | break; |
317 | 317 | case $snak instanceof PropertySomeValueSnak: |
318 | 318 | $values[] = ItemIdSnakValue::someValue(); |
@@ -331,28 +331,28 @@ discard block |
||
331 | 331 | * @throws ConstraintParameterException if the parameter is invalid or missing |
332 | 332 | * @return PropertyId[] |
333 | 333 | */ |
334 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
335 | - $this->checkError( $constraintParameters ); |
|
336 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
337 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
334 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
335 | + $this->checkError($constraintParameters); |
|
336 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
337 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
338 | 338 | throw new ConstraintParameterException( |
339 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
340 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
341 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
339 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
340 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
341 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
342 | 342 | ->escaped() |
343 | 343 | ); |
344 | 344 | } |
345 | 345 | |
346 | 346 | $parameters = $constraintParameters[$propertyId]; |
347 | - if ( count( $parameters ) === 1 && |
|
348 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
347 | + if (count($parameters) === 1 && |
|
348 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
349 | 349 | ) { |
350 | 350 | return []; |
351 | 351 | } |
352 | 352 | |
353 | 353 | $properties = []; |
354 | - foreach ( $parameters as $parameter ) { |
|
355 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
354 | + foreach ($parameters as $parameter) { |
|
355 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
356 | 356 | } |
357 | 357 | return $properties; |
358 | 358 | } |
@@ -363,16 +363,16 @@ discard block |
||
363 | 363 | * @throws ConstraintParameterException |
364 | 364 | * @return DataValue|null |
365 | 365 | */ |
366 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
367 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
368 | - if ( $snak instanceof PropertyValueSnak ) { |
|
366 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
367 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
368 | + if ($snak instanceof PropertyValueSnak) { |
|
369 | 369 | return $snak->getDataValue(); |
370 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
370 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
371 | 371 | return null; |
372 | 372 | } else { |
373 | 373 | throw new ConstraintParameterException( |
374 | - wfMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) |
|
375 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
374 | + wfMessage('wbqc-violation-message-parameter-value-or-novalue') |
|
375 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
376 | 376 | ->escaped() |
377 | 377 | ); |
378 | 378 | } |
@@ -383,10 +383,10 @@ discard block |
||
383 | 383 | * @param string $parameterId |
384 | 384 | * @return DataValue|null |
385 | 385 | */ |
386 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
386 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
387 | 387 | try { |
388 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
389 | - } catch ( ConstraintParameterException $e ) { |
|
388 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
389 | + } catch (ConstraintParameterException $e) { |
|
390 | 390 | // unknown value means “now” |
391 | 391 | return new NowValue(); |
392 | 392 | } |
@@ -399,14 +399,14 @@ discard block |
||
399 | 399 | * @param string $unit |
400 | 400 | * @return bool |
401 | 401 | */ |
402 | - private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) { |
|
403 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
404 | - !( $max instanceof UnboundedQuantityValue ) |
|
402 | + private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) { |
|
403 | + if (!($min instanceof UnboundedQuantityValue) || |
|
404 | + !($max instanceof UnboundedQuantityValue) |
|
405 | 405 | ) { |
406 | 406 | return false; |
407 | 407 | } |
408 | 408 | |
409 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
409 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | /** |
@@ -417,9 +417,9 @@ discard block |
||
417 | 417 | * @throws ConstraintParameterException if the parameter is invalid or missing |
418 | 418 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
419 | 419 | */ |
420 | - public function parseRangeParameter( array $constraintParameters, $constraintTypeItemId, $type ) { |
|
421 | - $this->checkError( $constraintParameters ); |
|
422 | - switch ( $type ) { |
|
420 | + public function parseRangeParameter(array $constraintParameters, $constraintTypeItemId, $type) { |
|
421 | + $this->checkError($constraintParameters); |
|
422 | + switch ($type) { |
|
423 | 423 | case 'quantity': |
424 | 424 | $configKey = 'Quantity'; |
425 | 425 | break; |
@@ -428,58 +428,58 @@ discard block |
||
428 | 428 | break; |
429 | 429 | default: |
430 | 430 | throw new ConstraintParameterException( |
431 | - wfMessage( 'wbqc-violation-message-value-needed-of-types-2' ) |
|
431 | + wfMessage('wbqc-violation-message-value-needed-of-types-2') |
|
432 | 432 | ->rawParams( |
433 | - $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ), |
|
434 | - wfMessage( 'datatypes-type-quantity' )->escaped(), |
|
435 | - wfMessage( 'datatypes-type-time' )->escaped() |
|
433 | + $this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM), |
|
434 | + wfMessage('datatypes-type-quantity')->escaped(), |
|
435 | + wfMessage('datatypes-type-time')->escaped() |
|
436 | 436 | ) |
437 | 437 | ->escaped() |
438 | 438 | ); |
439 | 439 | } |
440 | - $minimumId = $this->config->get( 'WBQualityConstraintsMinimum' . $configKey . 'Id' ); |
|
441 | - $maximumId = $this->config->get( 'WBQualityConstraintsMaximum' . $configKey . 'Id' ); |
|
442 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
443 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
440 | + $minimumId = $this->config->get('WBQualityConstraintsMinimum'.$configKey.'Id'); |
|
441 | + $maximumId = $this->config->get('WBQualityConstraintsMaximum'.$configKey.'Id'); |
|
442 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
443 | + !array_key_exists($maximumId, $constraintParameters) |
|
444 | 444 | ) { |
445 | 445 | throw new ConstraintParameterException( |
446 | - wfMessage( 'wbqc-violation-message-range-parameters-needed' ) |
|
446 | + wfMessage('wbqc-violation-message-range-parameters-needed') |
|
447 | 447 | ->rawParams( |
448 | - wfMessage( 'datatypes-type-' . $type )->escaped(), |
|
449 | - $this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
450 | - $this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
448 | + wfMessage('datatypes-type-'.$type)->escaped(), |
|
449 | + $this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
450 | + $this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
451 | 451 | ) |
452 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
452 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
453 | 453 | ->escaped() |
454 | 454 | ); |
455 | 455 | } |
456 | 456 | |
457 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
458 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
457 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
458 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
459 | 459 | $parseFunction = $configKey === 'Date' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
460 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
461 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
460 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
461 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
462 | 462 | |
463 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
464 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
463 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
464 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
465 | 465 | throw new ConstraintParameterException( |
466 | - wfMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
466 | + wfMessage('wbqc-violation-message-range-parameters-one-year') |
|
467 | 467 | ->escaped() |
468 | 468 | ); |
469 | 469 | } |
470 | - if ( $min === null && $max === null || |
|
471 | - $min !== null && $max !== null && $min->equals( $max ) ) { |
|
470 | + if ($min === null && $max === null || |
|
471 | + $min !== null && $max !== null && $min->equals($max)) { |
|
472 | 472 | throw new ConstraintParameterException( |
473 | - wfMessage( 'wbqc-violation-message-range-parameters-same' ) |
|
473 | + wfMessage('wbqc-violation-message-range-parameters-same') |
|
474 | 474 | ->rawParams( |
475 | - $this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
476 | - $this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
475 | + $this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
476 | + $this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
477 | 477 | ) |
478 | 478 | ->escaped() |
479 | 479 | ); |
480 | 480 | } |
481 | 481 | |
482 | - return [ $min, $max ]; |
|
482 | + return [$min, $max]; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -489,18 +489,18 @@ discard block |
||
489 | 489 | * @throws ConstraintParameterException |
490 | 490 | * @return string |
491 | 491 | */ |
492 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
493 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
494 | - $this->requireValueParameter( $snak, $parameterId ); |
|
492 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
493 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
494 | + $this->requireValueParameter($snak, $parameterId); |
|
495 | 495 | $value = $snak->getDataValue(); |
496 | - if ( $value instanceof StringValue ) { |
|
496 | + if ($value instanceof StringValue) { |
|
497 | 497 | return $value->getValue(); |
498 | 498 | } else { |
499 | 499 | throw new ConstraintParameterException( |
500 | - wfMessage( 'wbqc-violation-message-parameter-string' ) |
|
500 | + wfMessage('wbqc-violation-message-parameter-string') |
|
501 | 501 | ->rawParams( |
502 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
503 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
502 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
503 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
504 | 504 | ) |
505 | 505 | ->escaped() |
506 | 506 | ); |
@@ -513,15 +513,15 @@ discard block |
||
513 | 513 | * @throws ConstraintParameterException if the parameter is invalid or missing |
514 | 514 | * @return string |
515 | 515 | */ |
516 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
517 | - $this->checkError( $constraintParameters ); |
|
518 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
519 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
516 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
517 | + $this->checkError($constraintParameters); |
|
518 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
519 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
520 | 520 | return ''; |
521 | 521 | } |
522 | 522 | |
523 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
524 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
523 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
524 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -530,20 +530,20 @@ discard block |
||
530 | 530 | * @throws ConstraintParameterException if the parameter is invalid or missing |
531 | 531 | * @return string |
532 | 532 | */ |
533 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
534 | - $this->checkError( $constraintParameters ); |
|
535 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
536 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
533 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
534 | + $this->checkError($constraintParameters); |
|
535 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
536 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
537 | 537 | throw new ConstraintParameterException( |
538 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
539 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
540 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $formatId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
538 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
539 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
540 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($formatId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
541 | 541 | ->escaped() |
542 | 542 | ); |
543 | 543 | } |
544 | 544 | |
545 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
546 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
545 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
546 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -551,16 +551,16 @@ discard block |
||
551 | 551 | * @throws ConstraintParameterException if the parameter is invalid |
552 | 552 | * @return EntityId[] |
553 | 553 | */ |
554 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
555 | - $this->checkError( $constraintParameters ); |
|
556 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
557 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
554 | + public function parseExceptionParameter(array $constraintParameters) { |
|
555 | + $this->checkError($constraintParameters); |
|
556 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
557 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
558 | 558 | return []; |
559 | 559 | } |
560 | 560 | |
561 | 561 | return array_map( |
562 | - function( $snakSerialization ) use ( $exceptionId ) { |
|
563 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
562 | + function($snakSerialization) use ($exceptionId) { |
|
563 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
564 | 564 | }, |
565 | 565 | $constraintParameters[$exceptionId] |
566 | 566 | ); |
@@ -571,27 +571,27 @@ discard block |
||
571 | 571 | * @throws ConstraintParameterException if the parameter is invalid |
572 | 572 | * @return string|null 'mandatory' or null |
573 | 573 | */ |
574 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
575 | - $this->checkError( $constraintParameters ); |
|
576 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
577 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
574 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
575 | + $this->checkError($constraintParameters); |
|
576 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
577 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
578 | 578 | return null; |
579 | 579 | } |
580 | 580 | |
581 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
582 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
583 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
584 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
581 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
582 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
583 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
584 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
585 | 585 | $statusId = $snak->getDataValue()->getEntityId()->getSerialization(); |
586 | 586 | |
587 | - if ( $statusId === $mandatoryId ) { |
|
587 | + if ($statusId === $mandatoryId) { |
|
588 | 588 | return 'mandatory'; |
589 | 589 | } else { |
590 | 590 | throw new ConstraintParameterException( |
591 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
592 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
593 | - ->numParams( 1 ) |
|
594 | - ->rawParams( $this->constraintParameterRenderer->formatItemIdList( [ $mandatoryId ], Role::CONSTRAINT_PARAMETER_VALUE ) ) |
|
591 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
592 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
593 | + ->numParams(1) |
|
594 | + ->rawParams($this->constraintParameterRenderer->formatItemIdList([$mandatoryId], Role::CONSTRAINT_PARAMETER_VALUE)) |
|
595 | 595 | ->escaped() |
596 | 596 | ); |
597 | 597 | } |
@@ -604,13 +604,13 @@ discard block |
||
604 | 604 | * @return void |
605 | 605 | * @throws ConstraintParameterException |
606 | 606 | */ |
607 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
608 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
607 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
608 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
609 | 609 | throw new ConstraintParameterException( |
610 | - wfMessage( 'wbqc-violation-message-parameter-monolingualtext' ) |
|
610 | + wfMessage('wbqc-violation-message-parameter-monolingualtext') |
|
611 | 611 | ->rawParams( |
612 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
613 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
612 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
613 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
614 | 614 | ) |
615 | 615 | ->escaped() |
616 | 616 | ); |
@@ -625,26 +625,26 @@ discard block |
||
625 | 625 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
626 | 626 | * @return MultilingualTextValue |
627 | 627 | */ |
628 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
628 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
629 | 629 | $result = []; |
630 | 630 | |
631 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
632 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
633 | - $this->requireValueParameter( $snak, $parameterId ); |
|
631 | + foreach ($snakSerializations as $snakSerialization) { |
|
632 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
633 | + $this->requireValueParameter($snak, $parameterId); |
|
634 | 634 | |
635 | 635 | $value = $snak->getDataValue(); |
636 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
636 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
637 | 637 | /** @var MonolingualTextValue $value */ |
638 | 638 | |
639 | 639 | $code = $value->getLanguageCode(); |
640 | - if ( array_key_exists( $code, $result ) ) { |
|
640 | + if (array_key_exists($code, $result)) { |
|
641 | 641 | throw new ConstraintParameterException( |
642 | - wfMessage( 'wbqc-violation-message-parameter-single-per-language' ) |
|
642 | + wfMessage('wbqc-violation-message-parameter-single-per-language') |
|
643 | 643 | ->rawParams( |
644 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
644 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
645 | 645 | ) |
646 | 646 | ->plaintextParams( |
647 | - Language::fetchLanguageName( $code ), |
|
647 | + Language::fetchLanguageName($code), |
|
648 | 648 | $code |
649 | 649 | ) |
650 | 650 | ->escaped() |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | $result[$code] = $value; |
655 | 655 | } |
656 | 656 | |
657 | - return new MultilingualTextValue( $result ); |
|
657 | + return new MultilingualTextValue($result); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -662,11 +662,11 @@ discard block |
||
662 | 662 | * @throws ConstraintParameterException if the parameter is invalid |
663 | 663 | * @return MultilingualTextValue |
664 | 664 | */ |
665 | - public function parseSyntaxClarificationParameter( array $constraintParameters ) { |
|
666 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
665 | + public function parseSyntaxClarificationParameter(array $constraintParameters) { |
|
666 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
667 | 667 | |
668 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
669 | - return new MultilingualTextValue( [] ); |
|
668 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
669 | + return new MultilingualTextValue([]); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -685,20 +685,20 @@ discard block |
||
685 | 685 | * @throws ConstraintParameterException if the parameter is invalid |
686 | 686 | * @return string[]|null Context::TYPE_* constants |
687 | 687 | */ |
688 | - public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) { |
|
689 | - $constraintScopeId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
690 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ); |
|
691 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ); |
|
692 | - $referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ); |
|
688 | + public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) { |
|
689 | + $constraintScopeId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
690 | + $mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId'); |
|
691 | + $qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId'); |
|
692 | + $referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId'); |
|
693 | 693 | |
694 | - if ( !array_key_exists( $constraintScopeId, $constraintParameters ) ) { |
|
694 | + if (!array_key_exists($constraintScopeId, $constraintParameters)) { |
|
695 | 695 | return null; |
696 | 696 | } |
697 | 697 | |
698 | 698 | $contextTypes = []; |
699 | - foreach ( $constraintParameters[$constraintScopeId] as $snakSerialization ) { |
|
700 | - $scopeEntityId = $this->parseEntityIdParameter( $snakSerialization, $constraintScopeId ); |
|
701 | - switch ( $scopeEntityId->getSerialization() ) { |
|
699 | + foreach ($constraintParameters[$constraintScopeId] as $snakSerialization) { |
|
700 | + $scopeEntityId = $this->parseEntityIdParameter($snakSerialization, $constraintScopeId); |
|
701 | + switch ($scopeEntityId->getSerialization()) { |
|
702 | 702 | case $mainSnakId: |
703 | 703 | $contextTypes[] = Context::TYPE_STATEMENT; |
704 | 704 | break; |
@@ -710,14 +710,14 @@ discard block |
||
710 | 710 | break; |
711 | 711 | default: |
712 | 712 | throw new ConstraintParameterException( |
713 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
713 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
714 | 714 | ->rawParams( |
715 | 715 | $this->constraintParameterRenderer->formatPropertyId( |
716 | 716 | $constraintScopeId, |
717 | 717 | Role::CONSTRAINT_PARAMETER_PROPERTY |
718 | 718 | ) |
719 | 719 | ) |
720 | - ->numParams( 3 ) |
|
720 | + ->numParams(3) |
|
721 | 721 | ->rawParams( |
722 | 722 | $this->constraintParameterRenderer->formatItemIdList( |
723 | 723 | [ |
@@ -733,12 +733,12 @@ discard block |
||
733 | 733 | } |
734 | 734 | } |
735 | 735 | |
736 | - if ( $validScopes !== null ) { |
|
737 | - $invalidScopes = array_diff( $contextTypes, $validScopes ); |
|
738 | - if ( $invalidScopes !== [] ) { |
|
739 | - $invalidScope = array_pop( $invalidScopes ); |
|
736 | + if ($validScopes !== null) { |
|
737 | + $invalidScopes = array_diff($contextTypes, $validScopes); |
|
738 | + if ($invalidScopes !== []) { |
|
739 | + $invalidScope = array_pop($invalidScopes); |
|
740 | 740 | throw new ConstraintParameterException( |
741 | - wfMessage( 'wbqc-violation-message-invalid-scope' ) |
|
741 | + wfMessage('wbqc-violation-message-invalid-scope') |
|
742 | 742 | ->rawParams( |
743 | 743 | $this->constraintParameterRenderer->formatConstraintScope( |
744 | 744 | $invalidScope, |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | Role::CONSTRAINT_TYPE_ITEM |
750 | 750 | ) |
751 | 751 | ) |
752 | - ->numParams( count( $validScopes ) ) |
|
752 | + ->numParams(count($validScopes)) |
|
753 | 753 | ->rawParams( |
754 | 754 | $this->constraintParameterRenderer->formatConstraintScopeList( |
755 | 755 | $validScopes, |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | * @throws ConstraintParameterException |
89 | 89 | * @return CheckResult |
90 | 90 | */ |
91 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
92 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
93 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
91 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
92 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
93 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $parameters = []; |
@@ -98,28 +98,28 @@ discard block |
||
98 | 98 | |
99 | 99 | $snak = $context->getSnak(); |
100 | 100 | |
101 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
101 | + if (!$snak instanceof PropertyValueSnak) { |
|
102 | 102 | // nothing to check |
103 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
103 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | $dataValue = $snak->getDataValue(); |
107 | 107 | |
108 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
108 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
109 | 109 | $constraintParameters, |
110 | 110 | $constraint->getConstraintTypeItemId(), |
111 | 111 | $dataValue->getType() |
112 | 112 | ); |
113 | 113 | $parameterKey = $dataValue->getType() === 'quantity' ? 'quantity' : 'date'; |
114 | - if ( $min !== null ) { |
|
115 | - $parameters['minimum_' . $parameterKey] = [ $min ]; |
|
114 | + if ($min !== null) { |
|
115 | + $parameters['minimum_'.$parameterKey] = [$min]; |
|
116 | 116 | } |
117 | - if ( $max !== null ) { |
|
118 | - $parameters['maximum_' . $parameterKey] = [ $max ]; |
|
117 | + if ($max !== null) { |
|
118 | + $parameters['maximum_'.$parameterKey] = [$max]; |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( $this->rangeCheckerHelper->getComparison( $min, $dataValue ) > 0 || |
|
122 | - $this->rangeCheckerHelper->getComparison( $dataValue, $max ) > 0 |
|
121 | + if ($this->rangeCheckerHelper->getComparison($min, $dataValue) > 0 || |
|
122 | + $this->rangeCheckerHelper->getComparison($dataValue, $max) > 0 |
|
123 | 123 | ) { |
124 | 124 | $message = $this->getViolationMessage( |
125 | 125 | $context->getSnak()->getPropertyId(), |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $status = CheckResult::STATUS_COMPLIANCE; |
134 | 134 | } |
135 | 135 | |
136 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
136 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @return ViolationMessage |
146 | 146 | */ |
147 | - private function getViolationMessage( PropertyId $predicate, DataValue $value, $min, $max ) { |
|
147 | + private function getViolationMessage(PropertyId $predicate, DataValue $value, $min, $max) { |
|
148 | 148 | // possible message keys: |
149 | 149 | // wbqc-violation-message-range-quantity-closed |
150 | 150 | // wbqc-violation-message-range-quantity-leftopen |
@@ -157,39 +157,39 @@ discard block |
||
157 | 157 | // wbqc-violation-message-range-time-rightopen |
158 | 158 | // wbqc-violation-message-range-time-rightopen-leftnow |
159 | 159 | $messageKey = 'wbqc-violation-message-range'; |
160 | - $messageKey .= '-' . $value->getType(); |
|
160 | + $messageKey .= '-'.$value->getType(); |
|
161 | 161 | // at least one of $min, $max is set, otherwise there could be no violation |
162 | - $messageKey .= '-' . ( $min !== null ? ( $max !== null ? 'closed' : 'rightopen' ) : 'leftopen' ); |
|
163 | - if ( $min instanceof NowValue ) { |
|
162 | + $messageKey .= '-'.($min !== null ? ($max !== null ? 'closed' : 'rightopen') : 'leftopen'); |
|
163 | + if ($min instanceof NowValue) { |
|
164 | 164 | $messageKey .= '-leftnow'; |
165 | - } elseif ( $max instanceof NowValue ) { |
|
165 | + } elseif ($max instanceof NowValue) { |
|
166 | 166 | $messageKey .= '-rightnow'; |
167 | 167 | } |
168 | - $message = ( new ViolationMessage( $messageKey ) ) |
|
169 | - ->withEntityId( $predicate, Role::PREDICATE ) |
|
170 | - ->withDataValue( $value, Role::OBJECT ); |
|
171 | - if ( $min !== null && !( $min instanceof NowValue ) ) { |
|
172 | - $message = $message->withDataValue( $min, Role::OBJECT ); |
|
168 | + $message = (new ViolationMessage($messageKey)) |
|
169 | + ->withEntityId($predicate, Role::PREDICATE) |
|
170 | + ->withDataValue($value, Role::OBJECT); |
|
171 | + if ($min !== null && !($min instanceof NowValue)) { |
|
172 | + $message = $message->withDataValue($min, Role::OBJECT); |
|
173 | 173 | } |
174 | - if ( $max !== null && !( $max instanceof NowValue ) ) { |
|
175 | - $message = $message->withDataValue( $max, Role::OBJECT ); |
|
174 | + if ($max !== null && !($max instanceof NowValue)) { |
|
175 | + $message = $message->withDataValue($max, Role::OBJECT); |
|
176 | 176 | } |
177 | 177 | return $message; |
178 | 178 | } |
179 | 179 | |
180 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
180 | + public function checkConstraintParameters(Constraint $constraint) { |
|
181 | 181 | $constraintParameters = $constraint->getConstraintParameters(); |
182 | 182 | $exceptions = []; |
183 | 183 | try { |
184 | 184 | // we don’t have a data value here, so get the type from the property instead |
185 | 185 | // (the distinction between data type and data value type is irrelevant for 'quantity' and 'time') |
186 | - $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty( $constraint->getPropertyId() ); |
|
186 | + $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty($constraint->getPropertyId()); |
|
187 | 187 | $this->constraintParameterParser->parseRangeParameter( |
188 | 188 | $constraintParameters, |
189 | 189 | $constraint->getConstraintTypeItemId(), |
190 | 190 | $type |
191 | 191 | ); |
192 | - } catch ( ConstraintParameterException $e ) { |
|
192 | + } catch (ConstraintParameterException $e) { |
|
193 | 193 | $exceptions[] = $e; |
194 | 194 | } |
195 | 195 | return $exceptions; |
@@ -149,11 +149,11 @@ discard block |
||
149 | 149 | public function getDataValue() { |
150 | 150 | $mainSnak = $this->context->getSnak(); |
151 | 151 | |
152 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
152 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
153 | 153 | return $mainSnak->getDataValue(); |
154 | 154 | } |
155 | 155 | |
156 | - throw new LogicException( 'Cannot get DataValue, Snak is of type ' . $this->getSnakType() . '.' ); |
|
156 | + throw new LogicException('Cannot get DataValue, Snak is of type '.$this->getSnakType().'.'); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @param string $key |
182 | 182 | * @param string $value |
183 | 183 | */ |
184 | - public function addParameter( $key, $value ) { |
|
184 | + public function addParameter($key, $value) { |
|
185 | 185 | $this->parameters[$key][] = $value; |
186 | 186 | } |
187 | 187 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | /** |
196 | 196 | * @param string $status |
197 | 197 | */ |
198 | - public function setStatus( $status ) { |
|
198 | + public function setStatus($status) { |
|
199 | 199 | $this->status = $status; |
200 | 200 | } |
201 | 201 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @param Metadata $metadata |
211 | 211 | * @return self |
212 | 212 | */ |
213 | - public function withMetadata( Metadata $metadata ) { |
|
213 | + public function withMetadata(Metadata $metadata) { |
|
214 | 214 | $this->metadata = $metadata; |
215 | 215 | return $this; |
216 | 216 | } |
@@ -16,8 +16,8 @@ |
||
16 | 16 | /** |
17 | 17 | * @param string $message HTML |
18 | 18 | */ |
19 | - public function __construct( $message ) { |
|
20 | - parent::__construct( $message ); |
|
19 | + public function __construct($message) { |
|
20 | + parent::__construct($message); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -137,14 +137,14 @@ discard block |
||
137 | 137 | callable $defaultResults = null |
138 | 138 | ) { |
139 | 139 | |
140 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
141 | - if ( $entity instanceof StatementListProvider ) { |
|
140 | + $entity = $this->entityLookup->getEntity($entityId); |
|
141 | + if ($entity instanceof StatementListProvider) { |
|
142 | 142 | $result = $this->checkEveryStatement( |
143 | - $this->entityLookup->getEntity( $entityId ), |
|
143 | + $this->entityLookup->getEntity($entityId), |
|
144 | 144 | $constraintIds, |
145 | 145 | $defaultResults |
146 | 146 | ); |
147 | - $output = $this->sortResult( $result ); |
|
147 | + $output = $this->sortResult($result); |
|
148 | 148 | return $output; |
149 | 149 | } |
150 | 150 | |
@@ -170,19 +170,19 @@ discard block |
||
170 | 170 | callable $defaultResults = null |
171 | 171 | ) { |
172 | 172 | |
173 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
173 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
174 | 174 | $entityId = $parsedGuid->getEntityId(); |
175 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
176 | - if ( $entity instanceof StatementListProvider ) { |
|
177 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
178 | - if ( $statement ) { |
|
175 | + $entity = $this->entityLookup->getEntity($entityId); |
|
176 | + if ($entity instanceof StatementListProvider) { |
|
177 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
178 | + if ($statement) { |
|
179 | 179 | $result = $this->checkStatement( |
180 | 180 | $entity, |
181 | 181 | $statement, |
182 | 182 | $constraintIds, |
183 | 183 | $defaultResults |
184 | 184 | ); |
185 | - $output = $this->sortResult( $result ); |
|
185 | + $output = $this->sortResult($result); |
|
186 | 186 | return $output; |
187 | 187 | } |
188 | 188 | } |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | return []; |
191 | 191 | } |
192 | 192 | |
193 | - private function getAllowedContextTypes( Constraint $constraint ) { |
|
194 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
193 | + private function getAllowedContextTypes(Constraint $constraint) { |
|
194 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
195 | 195 | return [ |
196 | 196 | Context::TYPE_STATEMENT, |
197 | 197 | Context::TYPE_QUALIFIER, |
@@ -199,12 +199,12 @@ discard block |
||
199 | 199 | ]; |
200 | 200 | } |
201 | 201 | |
202 | - return array_keys( array_filter( |
|
202 | + return array_keys(array_filter( |
|
203 | 203 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
204 | - function ( $resultStatus ) { |
|
204 | + function($resultStatus) { |
|
205 | 205 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
206 | 206 | } |
207 | - ) ); |
|
207 | + )); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -215,32 +215,32 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return ConstraintParameterException[] |
217 | 217 | */ |
218 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
218 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
219 | 219 | $constraintParameters = $constraint->getConstraintParameters(); |
220 | 220 | try { |
221 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
222 | - } catch ( ConstraintParameterException $e ) { |
|
223 | - return [ $e ]; |
|
221 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
222 | + } catch (ConstraintParameterException $e) { |
|
223 | + return [$e]; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | $problems = []; |
227 | 227 | try { |
228 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
229 | - } catch ( ConstraintParameterException $e ) { |
|
228 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
229 | + } catch (ConstraintParameterException $e) { |
|
230 | 230 | $problems[] = $e; |
231 | 231 | } |
232 | 232 | try { |
233 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
234 | - } catch ( ConstraintParameterException $e ) { |
|
233 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
234 | + } catch (ConstraintParameterException $e) { |
|
235 | 235 | $problems[] = $e; |
236 | 236 | } |
237 | 237 | try { |
238 | 238 | $this->constraintParameterParser->parseConstraintScopeParameter( |
239 | 239 | $constraintParameters, |
240 | 240 | $constraint->getConstraintTypeItemId(), |
241 | - $this->getAllowedContextTypes( $constraint ) |
|
241 | + $this->getAllowedContextTypes($constraint) |
|
242 | 242 | ); |
243 | - } catch ( ConstraintParameterException $e ) { |
|
243 | + } catch (ConstraintParameterException $e) { |
|
244 | 244 | $problems[] = $e; |
245 | 245 | } |
246 | 246 | return $problems; |
@@ -253,16 +253,16 @@ discard block |
||
253 | 253 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
254 | 254 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
255 | 255 | */ |
256 | - public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) { |
|
257 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
256 | + public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) { |
|
257 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
258 | 258 | $result = []; |
259 | 259 | |
260 | - foreach ( $constraints as $constraint ) { |
|
261 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
260 | + foreach ($constraints as $constraint) { |
|
261 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
262 | 262 | |
263 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
263 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
264 | 264 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
265 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
265 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | $result[$constraint->getConstraintId()] = $problems; |
@@ -279,17 +279,17 @@ discard block |
||
279 | 279 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
280 | 280 | * (empty means all parameters okay), or null if constraint is not found |
281 | 281 | */ |
282 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
283 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
284 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
282 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
283 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
284 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
285 | 285 | |
286 | - foreach ( $constraints as $constraint ) { |
|
287 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
288 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
286 | + foreach ($constraints as $constraint) { |
|
287 | + if ($constraint->getConstraintId() === $constraintId) { |
|
288 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
289 | 289 | |
290 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
290 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
291 | 291 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
292 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
292 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | return $problems; |
@@ -314,14 +314,14 @@ discard block |
||
314 | 314 | $result = []; |
315 | 315 | |
316 | 316 | /** @var Statement $statement */ |
317 | - foreach ( $entity->getStatements() as $statement ) { |
|
318 | - $result = array_merge( $result, |
|
317 | + foreach ($entity->getStatements() as $statement) { |
|
318 | + $result = array_merge($result, |
|
319 | 319 | $this->checkStatement( |
320 | 320 | $entity, |
321 | 321 | $statement, |
322 | 322 | $constraintIds, |
323 | 323 | $defaultResults |
324 | - ) ); |
|
324 | + )); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | return $result; |
@@ -343,32 +343,32 @@ discard block |
||
343 | 343 | ) { |
344 | 344 | $result = []; |
345 | 345 | |
346 | - $result = array_merge( $result, |
|
346 | + $result = array_merge($result, |
|
347 | 347 | $this->checkConstraintsForMainSnak( |
348 | 348 | $entity, |
349 | 349 | $statement, |
350 | 350 | $constraintIds, |
351 | 351 | $defaultResults |
352 | - ) ); |
|
352 | + )); |
|
353 | 353 | |
354 | - if ( $this->checkQualifiers ) { |
|
355 | - $result = array_merge( $result, |
|
354 | + if ($this->checkQualifiers) { |
|
355 | + $result = array_merge($result, |
|
356 | 356 | $this->checkConstraintsForQualifiers( |
357 | 357 | $entity, |
358 | 358 | $statement, |
359 | 359 | $constraintIds, |
360 | 360 | $defaultResults |
361 | - ) ); |
|
361 | + )); |
|
362 | 362 | } |
363 | 363 | |
364 | - if ( $this->checkReferences ) { |
|
365 | - $result = array_merge( $result, |
|
364 | + if ($this->checkReferences) { |
|
365 | + $result = array_merge($result, |
|
366 | 366 | $this->checkConstraintsForReferences( |
367 | 367 | $entity, |
368 | 368 | $statement, |
369 | 369 | $constraintIds, |
370 | 370 | $defaultResults |
371 | - ) ); |
|
371 | + )); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | return $result; |
@@ -383,12 +383,12 @@ discard block |
||
383 | 383 | * @param string[]|null $constraintIds |
384 | 384 | * @return Constraint[] |
385 | 385 | */ |
386 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
387 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
388 | - if ( $constraintIds !== null ) { |
|
386 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
387 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
388 | + if ($constraintIds !== null) { |
|
389 | 389 | $constraintsToUse = []; |
390 | - foreach ( $constraints as $constraint ) { |
|
391 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
390 | + foreach ($constraints as $constraint) { |
|
391 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
392 | 392 | $constraintsToUse[] = $constraint; |
393 | 393 | } |
394 | 394 | } |
@@ -412,29 +412,29 @@ discard block |
||
412 | 412 | array $constraintIds = null, |
413 | 413 | callable $defaultResults = null |
414 | 414 | ) { |
415 | - $context = new MainSnakContext( $entity, $statement ); |
|
415 | + $context = new MainSnakContext($entity, $statement); |
|
416 | 416 | $constraints = $this->getConstraintsToUse( |
417 | 417 | $statement->getPropertyId(), |
418 | 418 | $constraintIds |
419 | 419 | ); |
420 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
420 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
421 | 421 | |
422 | - foreach ( $constraints as $constraint ) { |
|
422 | + foreach ($constraints as $constraint) { |
|
423 | 423 | $parameters = $constraint->getConstraintParameters(); |
424 | 424 | try { |
425 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
426 | - } catch ( ConstraintParameterException $e ) { |
|
427 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
425 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
426 | + } catch (ConstraintParameterException $e) { |
|
427 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
428 | 428 | continue; |
429 | 429 | } |
430 | 430 | |
431 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
432 | - $message = wfMessage( 'wbqc-exception-message' )->escaped(); |
|
433 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
431 | + if (in_array($entity->getId(), $exceptions)) { |
|
432 | + $message = wfMessage('wbqc-exception-message')->escaped(); |
|
433 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
434 | 434 | continue; |
435 | 435 | } |
436 | 436 | |
437 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
437 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | return $result; |
@@ -456,24 +456,24 @@ discard block |
||
456 | 456 | ) { |
457 | 457 | $result = []; |
458 | 458 | |
459 | - if ( in_array( |
|
459 | + if (in_array( |
|
460 | 460 | $statement->getPropertyId()->getSerialization(), |
461 | 461 | $this->propertiesWithViolatingQualifiers |
462 | - ) ) { |
|
462 | + )) { |
|
463 | 463 | return $result; |
464 | 464 | } |
465 | 465 | |
466 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
467 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
468 | - if ( $defaultResults !== null ) { |
|
469 | - $result = array_merge( $result, $defaultResults( $qualifierContext ) ); |
|
466 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
467 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
468 | + if ($defaultResults !== null) { |
|
469 | + $result = array_merge($result, $defaultResults($qualifierContext)); |
|
470 | 470 | } |
471 | 471 | $qualifierConstraints = $this->getConstraintsToUse( |
472 | 472 | $qualifierContext->getSnak()->getPropertyId(), |
473 | 473 | $constraintIds |
474 | 474 | ); |
475 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
476 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
475 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
476 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
@@ -497,19 +497,19 @@ discard block |
||
497 | 497 | $result = []; |
498 | 498 | |
499 | 499 | /** @var Reference $reference */ |
500 | - foreach ( $statement->getReferences() as $reference ) { |
|
501 | - foreach ( $reference->getSnaks() as $snak ) { |
|
500 | + foreach ($statement->getReferences() as $reference) { |
|
501 | + foreach ($reference->getSnaks() as $snak) { |
|
502 | 502 | $referenceContext = new ReferenceContext( |
503 | 503 | $entity, $statement, $reference, $snak |
504 | 504 | ); |
505 | - if ( $defaultResults !== null ) { |
|
506 | - $result = array_merge( $result, $defaultResults( $referenceContext ) ); |
|
505 | + if ($defaultResults !== null) { |
|
506 | + $result = array_merge($result, $defaultResults($referenceContext)); |
|
507 | 507 | } |
508 | 508 | $referenceConstraints = $this->getConstraintsToUse( |
509 | 509 | $referenceContext->getSnak()->getPropertyId(), |
510 | 510 | $constraintIds |
511 | 511 | ); |
512 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
512 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
513 | 513 | $result[] = $this->getCheckResultFor( |
514 | 514 | $referenceContext, |
515 | 515 | $referenceConstraint |
@@ -528,65 +528,65 @@ discard block |
||
528 | 528 | * @throws InvalidArgumentException |
529 | 529 | * @return CheckResult |
530 | 530 | */ |
531 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
532 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
531 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
532 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
533 | 533 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
534 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
534 | + $result = $this->handleScope($checker, $context, $constraint); |
|
535 | 535 | |
536 | - if ( $result !== null ) { |
|
537 | - $this->addMetadata( $result ); |
|
536 | + if ($result !== null) { |
|
537 | + $this->addMetadata($result); |
|
538 | 538 | return $result; |
539 | 539 | } |
540 | 540 | |
541 | - $startTime = microtime( true ); |
|
541 | + $startTime = microtime(true); |
|
542 | 542 | try { |
543 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
544 | - } catch ( ConstraintParameterException $e ) { |
|
545 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
546 | - } catch ( SparqlHelperException $e ) { |
|
547 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
548 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
543 | + $result = $checker->checkConstraint($context, $constraint); |
|
544 | + } catch (ConstraintParameterException $e) { |
|
545 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
546 | + } catch (SparqlHelperException $e) { |
|
547 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
548 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
549 | 549 | } |
550 | - $endTime = microtime( true ); |
|
550 | + $endTime = microtime(true); |
|
551 | 551 | |
552 | - $this->addMetadata( $result ); |
|
552 | + $this->addMetadata($result); |
|
553 | 553 | |
554 | 554 | try { |
555 | 555 | $constraintStatus = $this->constraintParameterParser |
556 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
557 | - } catch ( ConstraintParameterException $e ) { |
|
558 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
556 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
557 | + } catch (ConstraintParameterException $e) { |
|
558 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
559 | 559 | $constraintStatus = null; |
560 | 560 | } |
561 | - if ( $constraintStatus === null ) { |
|
561 | + if ($constraintStatus === null) { |
|
562 | 562 | // downgrade violation to warning |
563 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
564 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
563 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
564 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
565 | 565 | } |
566 | 566 | } else { |
567 | - if ( $constraintStatus !== 'mandatory' ) { |
|
567 | + if ($constraintStatus !== 'mandatory') { |
|
568 | 568 | // @codeCoverageIgnoreStart |
569 | 569 | throw new LogicException( |
570 | - "Unknown constraint status '$constraintStatus', " . |
|
570 | + "Unknown constraint status '$constraintStatus', ". |
|
571 | 571 | "only known status is 'mandatory'" |
572 | 572 | ); |
573 | 573 | // @codeCoverageIgnoreEnd |
574 | 574 | } |
575 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
575 | + $result->addParameter('constraint_status', $constraintStatus); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | $this->loggingHelper->logConstraintCheck( |
579 | 579 | $context, |
580 | 580 | $constraint, |
581 | 581 | $result, |
582 | - get_class( $checker ), |
|
582 | + get_class($checker), |
|
583 | 583 | $endTime - $startTime, |
584 | 584 | __METHOD__ |
585 | 585 | ); |
586 | 586 | |
587 | 587 | return $result; |
588 | 588 | } else { |
589 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
589 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
590 | 590 | } |
591 | 591 | } |
592 | 592 | |
@@ -600,29 +600,29 @@ discard block |
||
600 | 600 | $constraint->getConstraintParameters(), |
601 | 601 | $constraint->getConstraintTypeItemId() |
602 | 602 | ); |
603 | - } catch ( ConstraintParameterException $e ) { |
|
604 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
603 | + } catch (ConstraintParameterException $e) { |
|
604 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
605 | 605 | } |
606 | - if ( $checkedContextTypes === null ) { |
|
606 | + if ($checkedContextTypes === null) { |
|
607 | 607 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
608 | 608 | } |
609 | - if ( !in_array( $context->getType(), $checkedContextTypes ) ) { |
|
610 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
609 | + if (!in_array($context->getType(), $checkedContextTypes)) { |
|
610 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
611 | 611 | } |
612 | - if ( $checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO ) { |
|
613 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
612 | + if ($checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO) { |
|
613 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
614 | 614 | } |
615 | 615 | return null; |
616 | 616 | } |
617 | 617 | |
618 | - private function addMetadata( CheckResult $result ) { |
|
619 | - $result->withMetadata( Metadata::merge( [ |
|
618 | + private function addMetadata(CheckResult $result) { |
|
619 | + $result->withMetadata(Metadata::merge([ |
|
620 | 620 | $result->getMetadata(), |
621 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
622 | - DependencyMetadata::ofEntityId( $result->getEntityId() ), |
|
623 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
624 | - ] ) ), |
|
625 | - ] ) ); |
|
621 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
622 | + DependencyMetadata::ofEntityId($result->getEntityId()), |
|
623 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
624 | + ])), |
|
625 | + ])); |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | /** |
@@ -630,12 +630,12 @@ discard block |
||
630 | 630 | * |
631 | 631 | * @return CheckResult[] |
632 | 632 | */ |
633 | - private function sortResult( array $result ) { |
|
634 | - if ( count( $result ) < 2 ) { |
|
633 | + private function sortResult(array $result) { |
|
634 | + if (count($result) < 2) { |
|
635 | 635 | return $result; |
636 | 636 | } |
637 | 637 | |
638 | - $sortFunction = function ( CheckResult $a, CheckResult $b ) { |
|
638 | + $sortFunction = function(CheckResult $a, CheckResult $b) { |
|
639 | 639 | $orderNum = 0; |
640 | 640 | $order = [ |
641 | 641 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -651,45 +651,45 @@ discard block |
||
651 | 651 | $statusA = $a->getStatus(); |
652 | 652 | $statusB = $b->getStatus(); |
653 | 653 | |
654 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
655 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
654 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
655 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
656 | 656 | |
657 | - if ( $orderA === $orderB ) { |
|
657 | + if ($orderA === $orderB) { |
|
658 | 658 | $pidA = $a->getContext()->getSnak()->getPropertyId()->getSerialization(); |
659 | 659 | $pidB = $b->getContext()->getSnak()->getPropertyId()->getSerialization(); |
660 | 660 | |
661 | - if ( $pidA === $pidB ) { |
|
661 | + if ($pidA === $pidB) { |
|
662 | 662 | $hashA = $a->getContext()->getSnak()->getHash(); |
663 | 663 | $hashB = $b->getContext()->getSnak()->getHash(); |
664 | 664 | |
665 | - if ( $hashA === $hashB ) { |
|
666 | - if ( $a instanceof NullResult ) { |
|
665 | + if ($hashA === $hashB) { |
|
666 | + if ($a instanceof NullResult) { |
|
667 | 667 | return $b instanceof NullResult ? 0 : -1; |
668 | 668 | } |
669 | - if ( $b instanceof NullResult ) { |
|
669 | + if ($b instanceof NullResult) { |
|
670 | 670 | return $a instanceof NullResult ? 0 : 1; |
671 | 671 | } |
672 | 672 | |
673 | 673 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
674 | 674 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
675 | 675 | |
676 | - if ( $typeA == $typeB ) { |
|
676 | + if ($typeA == $typeB) { |
|
677 | 677 | return 0; |
678 | 678 | } else { |
679 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
679 | + return ($typeA > $typeB) ? 1 : -1; |
|
680 | 680 | } |
681 | 681 | } else { |
682 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
682 | + return ($hashA > $hashB) ? 1 : -1; |
|
683 | 683 | } |
684 | 684 | } else { |
685 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
685 | + return ($pidA > $pidB) ? 1 : -1; |
|
686 | 686 | } |
687 | 687 | } else { |
688 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
688 | + return ($orderA > $orderB) ? 1 : -1; |
|
689 | 689 | } |
690 | 690 | }; |
691 | 691 | |
692 | - uasort( $result, $sortFunction ); |
|
692 | + uasort($result, $sortFunction); |
|
693 | 693 | |
694 | 694 | return $result; |
695 | 695 | } |
@@ -16,27 +16,27 @@ |
||
16 | 16 | */ |
17 | 17 | private $timeValueCalculator; |
18 | 18 | |
19 | - public function __construct( TimeValueCalculator $timeValueCalculator = null ) { |
|
19 | + public function __construct(TimeValueCalculator $timeValueCalculator = null) { |
|
20 | 20 | $this->timeValueCalculator = $timeValueCalculator ?: new TimeValueCalculator(); |
21 | 21 | } |
22 | 22 | |
23 | - public function getComparison( TimeValue $lhs, TimeValue $rhs ) { |
|
24 | - $lhsTimestamp = $this->timeValueCalculator->getTimestamp( $lhs ); |
|
25 | - $rhsTimestamp = $this->timeValueCalculator->getTimestamp( $rhs ); |
|
23 | + public function getComparison(TimeValue $lhs, TimeValue $rhs) { |
|
24 | + $lhsTimestamp = $this->timeValueCalculator->getTimestamp($lhs); |
|
25 | + $rhsTimestamp = $this->timeValueCalculator->getTimestamp($rhs); |
|
26 | 26 | |
27 | - if ( $lhsTimestamp === $rhsTimestamp ) { |
|
27 | + if ($lhsTimestamp === $rhsTimestamp) { |
|
28 | 28 | return 0; |
29 | 29 | } |
30 | 30 | |
31 | 31 | return $lhsTimestamp < $rhsTimestamp ? -1 : 1; |
32 | 32 | } |
33 | 33 | |
34 | - public function getMinimum( TimeValue $timeValue1, TimeValue $timeValue2 ) { |
|
35 | - return $this->getComparison( $timeValue1, $timeValue2 ) <= 0 ? $timeValue1 : $timeValue2; |
|
34 | + public function getMinimum(TimeValue $timeValue1, TimeValue $timeValue2) { |
|
35 | + return $this->getComparison($timeValue1, $timeValue2) <= 0 ? $timeValue1 : $timeValue2; |
|
36 | 36 | } |
37 | 37 | |
38 | - public function isFutureTime( TimeValue $timeValue ) { |
|
39 | - return $this->getComparison( $timeValue, new NowValue() ) >= 0; |
|
38 | + public function isFutureTime(TimeValue $timeValue) { |
|
39 | + return $this->getComparison($timeValue, new NowValue()) >= 0; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | UnitConverter $unitConverter = null |
52 | 52 | ) { |
53 | 53 | $this->config = $config; |
54 | - $this->timeParser = ( new TimeParserFactory() )->getTimeParser(); |
|
54 | + $this->timeParser = (new TimeParserFactory())->getTimeParser(); |
|
55 | 55 | $this->timeCalculator = new TimeValueCalculator(); |
56 | 56 | $this->timeValueComparer = new TimeValueComparer(); |
57 | 57 | $this->unitConverter = $unitConverter; |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | * @param UnboundedQuantityValue $value |
62 | 62 | * @return UnboundedQuantityValue $value converted to standard units if possible, otherwise unchanged $value. |
63 | 63 | */ |
64 | - private function standardize( UnboundedQuantityValue $value ) { |
|
65 | - if ( $this->unitConverter !== null ) { |
|
66 | - $standard = $this->unitConverter->toStandardUnits( $value ); |
|
67 | - if ( $standard !== null ) { |
|
64 | + private function standardize(UnboundedQuantityValue $value) { |
|
65 | + if ($this->unitConverter !== null) { |
|
66 | + $standard = $this->unitConverter->toStandardUnits($value); |
|
67 | + if ($standard !== null) { |
|
68 | 68 | return $standard; |
69 | 69 | } else { |
70 | 70 | return $value; |
@@ -86,29 +86,29 @@ discard block |
||
86 | 86 | * when $lhs is respectively less than, equal to, or greater than $rhs. |
87 | 87 | * (In other words, just like the “spaceship” operator <=>.) |
88 | 88 | */ |
89 | - public function getComparison( DataValue $lhs = null, DataValue $rhs = null ) { |
|
90 | - if ( $lhs === null || $rhs === null ) { |
|
89 | + public function getComparison(DataValue $lhs = null, DataValue $rhs = null) { |
|
90 | + if ($lhs === null || $rhs === null) { |
|
91 | 91 | return 0; |
92 | 92 | } |
93 | 93 | |
94 | - if ( $lhs->getType() !== $rhs->getType() ) { |
|
95 | - throw new InvalidArgumentException( 'Different data value types' ); |
|
94 | + if ($lhs->getType() !== $rhs->getType()) { |
|
95 | + throw new InvalidArgumentException('Different data value types'); |
|
96 | 96 | } |
97 | 97 | |
98 | - switch ( $lhs->getType() ) { |
|
98 | + switch ($lhs->getType()) { |
|
99 | 99 | case 'time': |
100 | 100 | /** @var TimeValue $lhs */ |
101 | 101 | /** @var TimeValue $rhs */ |
102 | - return $this->timeValueComparer->getComparison( $lhs, $rhs ); |
|
102 | + return $this->timeValueComparer->getComparison($lhs, $rhs); |
|
103 | 103 | case 'quantity': |
104 | 104 | /** @var QuantityValue|UnboundedQuantityValue $lhs */ |
105 | 105 | /** @var QuantityValue|UnboundedQuantityValue $rhs */ |
106 | - $lhsStandard = $this->standardize( $lhs ); |
|
107 | - $rhsStandard = $this->standardize( $rhs ); |
|
108 | - return $lhsStandard->getAmount()->compare( $rhsStandard->getAmount() ); |
|
106 | + $lhsStandard = $this->standardize($lhs); |
|
107 | + $rhsStandard = $this->standardize($rhs); |
|
108 | + return $lhsStandard->getAmount()->compare($rhsStandard->getAmount()); |
|
109 | 109 | } |
110 | 110 | |
111 | - throw new InvalidArgumentException( 'Unsupported data value type' ); |
|
111 | + throw new InvalidArgumentException('Unsupported data value type'); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -123,67 +123,67 @@ discard block |
||
123 | 123 | * @throws InvalidArgumentException if the values do not both have the same, supported data value type |
124 | 124 | * @return UnboundedQuantityValue |
125 | 125 | */ |
126 | - public function getDifference( DataValue $minuend, DataValue $subtrahend ) { |
|
127 | - if ( $minuend->getType() === 'time' && $subtrahend->getType() === 'time' ) { |
|
128 | - $minuendSeconds = $this->timeCalculator->getTimestamp( $minuend ); |
|
129 | - $subtrahendSeconds = $this->timeCalculator->getTimestamp( $subtrahend ); |
|
126 | + public function getDifference(DataValue $minuend, DataValue $subtrahend) { |
|
127 | + if ($minuend->getType() === 'time' && $subtrahend->getType() === 'time') { |
|
128 | + $minuendSeconds = $this->timeCalculator->getTimestamp($minuend); |
|
129 | + $subtrahendSeconds = $this->timeCalculator->getTimestamp($subtrahend); |
|
130 | 130 | return UnboundedQuantityValue::newFromNumber( |
131 | 131 | $minuendSeconds - $subtrahendSeconds, |
132 | - $this->config->get( 'WBQualityConstraintsSecondUnit' ) |
|
132 | + $this->config->get('WBQualityConstraintsSecondUnit') |
|
133 | 133 | ); |
134 | 134 | } |
135 | - if ( $minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity' ) { |
|
136 | - $minuendStandard = $this->standardize( $minuend ); |
|
137 | - $subtrahendStandard = $this->standardize( $subtrahend ); |
|
135 | + if ($minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity') { |
|
136 | + $minuendStandard = $this->standardize($minuend); |
|
137 | + $subtrahendStandard = $this->standardize($subtrahend); |
|
138 | 138 | $minuendValue = $minuendStandard->getAmount()->getValueFloat(); |
139 | 139 | $subtrahendValue = $subtrahendStandard->getAmount()->getValueFloat(); |
140 | 140 | $diff = $minuendValue - $subtrahendValue; |
141 | 141 | // we don’t check whether both quantities have the same standard unit – |
142 | 142 | // that’s the job of a different constraint type, Units (T164372) |
143 | - return UnboundedQuantityValue::newFromNumber( $diff, $minuendStandard->getUnit() ); |
|
143 | + return UnboundedQuantityValue::newFromNumber($diff, $minuendStandard->getUnit()); |
|
144 | 144 | } |
145 | 145 | |
146 | - throw new InvalidArgumentException( 'Unsupported or different data value types' ); |
|
146 | + throw new InvalidArgumentException('Unsupported or different data value types'); |
|
147 | 147 | } |
148 | 148 | |
149 | - public function getDifferenceInYears( TimeValue $minuend, TimeValue $subtrahend ) { |
|
150 | - if ( !preg_match( '/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches ) || |
|
151 | - !preg_match( '/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches ) |
|
149 | + public function getDifferenceInYears(TimeValue $minuend, TimeValue $subtrahend) { |
|
150 | + if (!preg_match('/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches) || |
|
151 | + !preg_match('/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches) |
|
152 | 152 | ) { |
153 | - throw new InvalidArgumentException( 'TimeValue::getTime() did not match expected format' ); |
|
153 | + throw new InvalidArgumentException('TimeValue::getTime() did not match expected format'); |
|
154 | 154 | } |
155 | - $minuendYear = (float)$minuendMatches[1]; |
|
156 | - $subtrahendYear = (float)$subtrahendMatches[1]; |
|
155 | + $minuendYear = (float) $minuendMatches[1]; |
|
156 | + $subtrahendYear = (float) $subtrahendMatches[1]; |
|
157 | 157 | $minuendRest = $minuendMatches[2]; |
158 | 158 | $subtrahendRest = $subtrahendMatches[2]; |
159 | 159 | |
160 | 160 | // calculate difference of years |
161 | 161 | $diff = $minuendYear - $subtrahendYear; |
162 | - if ( $minuendYear > 0.0 && $subtrahendYear < 0.0 ) { |
|
162 | + if ($minuendYear > 0.0 && $subtrahendYear < 0.0) { |
|
163 | 163 | $diff -= 1.0; // there is no year 0, remove it from difference |
164 | - } elseif ( $minuendYear < 0.0 && $subtrahendYear > 0.0 ) { |
|
164 | + } elseif ($minuendYear < 0.0 && $subtrahendYear > 0.0) { |
|
165 | 165 | $diff -= -1.0; // there is no year 0, remove it from negative difference |
166 | 166 | } |
167 | 167 | |
168 | 168 | // adjust for date within year by parsing the month-day part within the same year |
169 | - $minuendDateValue = $this->timeParser->parse( '+0000000000001970-' . $minuendRest ); |
|
170 | - $subtrahendDateValue = $this->timeParser->parse( '+0000000000001970-' . $subtrahendRest ); |
|
171 | - $minuendDateSeconds = $this->timeCalculator->getTimestamp( $minuendDateValue ); |
|
172 | - $subtrahendDateSeconds = $this->timeCalculator->getTimestamp( $subtrahendDateValue ); |
|
173 | - if ( $minuendDateSeconds < $subtrahendDateSeconds ) { |
|
169 | + $minuendDateValue = $this->timeParser->parse('+0000000000001970-'.$minuendRest); |
|
170 | + $subtrahendDateValue = $this->timeParser->parse('+0000000000001970-'.$subtrahendRest); |
|
171 | + $minuendDateSeconds = $this->timeCalculator->getTimestamp($minuendDateValue); |
|
172 | + $subtrahendDateSeconds = $this->timeCalculator->getTimestamp($subtrahendDateValue); |
|
173 | + if ($minuendDateSeconds < $subtrahendDateSeconds) { |
|
174 | 174 | // difference in the last year is actually less than one full year |
175 | 175 | // e. g. 1975-03-01 - 1974-09-01 is just six months |
176 | 176 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
177 | 177 | $diff -= 0.5; |
178 | - } elseif ( $minuendDateSeconds > $subtrahendDateSeconds ) { |
|
178 | + } elseif ($minuendDateSeconds > $subtrahendDateSeconds) { |
|
179 | 179 | // difference in the last year is actually more than one full year |
180 | 180 | // e. g. 1975-09-01 - 1974-03-01 is 18 months |
181 | 181 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
182 | 182 | $diff += 0.5; |
183 | 183 | } |
184 | 184 | |
185 | - $unit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
186 | - return UnboundedQuantityValue::newFromNumber( $diff, $unit ); |
|
185 | + $unit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
186 | + return UnboundedQuantityValue::newFromNumber($diff, $unit); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @return string |
29 | 29 | */ |
30 | 30 | public function getTime() { |
31 | - return gmdate( '+Y-m-d\TH:i:s\Z' ); |
|
31 | + return gmdate('+Y-m-d\TH:i:s\Z'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | public function getTimezone() { |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | } |
41 | 41 | |
42 | 42 | public function getArrayValue() { |
43 | - throw new LogicException( 'NowValue should never be serialized' ); |
|
43 | + throw new LogicException('NowValue should never be serialized'); |
|
44 | 44 | } |
45 | 45 | |
46 | - public function equals( $value ) { |
|
47 | - return get_class( $value ) === self::class; |
|
46 | + public function equals($value) { |
|
47 | + return get_class($value) === self::class; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
@@ -108,18 +108,18 @@ discard block |
||
108 | 108 | $this->violationMessageDeserializer = $violationMessageDeserializer; |
109 | 109 | $this->dataFactory = $dataFactory; |
110 | 110 | |
111 | - $this->entityPrefix = $rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY ); |
|
111 | + $this->entityPrefix = $rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY); |
|
112 | 112 | $this->prefixes = <<<EOT |
113 | -PREFIX wd: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY )}> |
|
114 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
115 | -PREFIX wdt: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_DIRECT_CLAIM )}> |
|
116 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}> |
|
117 | -PREFIX p: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM )}> |
|
118 | -PREFIX ps: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM_STATEMENT )}> |
|
119 | -PREFIX pq: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER )}> |
|
120 | -PREFIX pqv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER_VALUE )}> |
|
121 | -PREFIX pr: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE )}> |
|
122 | -PREFIX prv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE_VALUE )}> |
|
113 | +PREFIX wd: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY)}> |
|
114 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
115 | +PREFIX wdt: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_DIRECT_CLAIM)}> |
|
116 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}> |
|
117 | +PREFIX p: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM)}> |
|
118 | +PREFIX ps: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM_STATEMENT)}> |
|
119 | +PREFIX pq: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER)}> |
|
120 | +PREFIX pqv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER_VALUE)}> |
|
121 | +PREFIX pr: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE)}> |
|
122 | +PREFIX prv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE_VALUE)}> |
|
123 | 123 | PREFIX wikibase: <http://wikiba.se/ontology#> |
124 | 124 | PREFIX wikibase-beta: <http://wikiba.se/ontology-beta#> |
125 | 125 | EOT; |
@@ -134,21 +134,21 @@ discard block |
||
134 | 134 | * @return CachedBool |
135 | 135 | * @throws SparqlHelperException if the query times out or some other error occurs |
136 | 136 | */ |
137 | - public function hasType( $id, array $classes, $withInstance ) { |
|
138 | - $instanceOfId = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
139 | - $subclassOfId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
137 | + public function hasType($id, array $classes, $withInstance) { |
|
138 | + $instanceOfId = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
139 | + $subclassOfId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
140 | 140 | |
141 | - $path = ( $withInstance ? "wdt:$instanceOfId/" : "" ) . "wdt:$subclassOfId*"; |
|
141 | + $path = ($withInstance ? "wdt:$instanceOfId/" : "")."wdt:$subclassOfId*"; |
|
142 | 142 | |
143 | 143 | $metadatas = []; |
144 | 144 | |
145 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
146 | - $classesValues = implode( ' ', array_map( |
|
147 | - function( $class ) { |
|
148 | - return 'wd:' . $class; |
|
145 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
146 | + $classesValues = implode(' ', array_map( |
|
147 | + function($class) { |
|
148 | + return 'wd:'.$class; |
|
149 | 149 | }, |
150 | 150 | $classesChunk |
151 | - ) ); |
|
151 | + )); |
|
152 | 152 | |
153 | 153 | $query = <<<EOF |
154 | 154 | ASK { |
@@ -159,19 +159,19 @@ discard block |
||
159 | 159 | EOF; |
160 | 160 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
161 | 161 | |
162 | - $result = $this->runQuery( $query ); |
|
162 | + $result = $this->runQuery($query); |
|
163 | 163 | $metadatas[] = $result->getMetadata(); |
164 | - if ( $result->getArray()['boolean'] ) { |
|
164 | + if ($result->getArray()['boolean']) { |
|
165 | 165 | return new CachedBool( |
166 | 166 | true, |
167 | - Metadata::merge( $metadatas ) |
|
167 | + Metadata::merge($metadatas) |
|
168 | 168 | ); |
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | 172 | return new CachedBool( |
173 | 173 | false, |
174 | - Metadata::merge( $metadatas ) |
|
174 | + Metadata::merge($metadatas) |
|
175 | 175 | ); |
176 | 176 | } |
177 | 177 | |
@@ -187,10 +187,10 @@ discard block |
||
187 | 187 | $ignoreDeprecatedStatements |
188 | 188 | ) { |
189 | 189 | $pid = $statement->getPropertyId()->serialize(); |
190 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
190 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
191 | 191 | |
192 | 192 | $deprecatedFilter = ''; |
193 | - if ( $ignoreDeprecatedStatements ) { |
|
193 | + if ($ignoreDeprecatedStatements) { |
|
194 | 194 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
195 | 195 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }'; |
196 | 196 | } |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | LIMIT 10 |
211 | 211 | EOF; |
212 | 212 | |
213 | - $result = $this->runQuery( $query ); |
|
213 | + $result = $this->runQuery($query); |
|
214 | 214 | |
215 | - return $this->getOtherEntities( $result ); |
|
215 | + return $this->getOtherEntities($result); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -237,16 +237,15 @@ discard block |
||
237 | 237 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
238 | 238 | $snak->getPropertyId() |
239 | 239 | ); |
240 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
241 | - if ( $isFullValue ) { |
|
240 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
241 | + if ($isFullValue) { |
|
242 | 242 | $prefix .= 'v'; |
243 | 243 | } |
244 | 244 | $path = $type === Context::TYPE_QUALIFIER ? |
245 | - "$prefix:$pid" : |
|
246 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
245 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
247 | 246 | |
248 | 247 | $deprecatedFilter = ''; |
249 | - if ( $ignoreDeprecatedStatements ) { |
|
248 | + if ($ignoreDeprecatedStatements) { |
|
250 | 249 | $deprecatedFilter = <<< EOF |
251 | 250 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
252 | 251 | MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. } |
@@ -267,9 +266,9 @@ discard block |
||
267 | 266 | LIMIT 10 |
268 | 267 | EOF; |
269 | 268 | |
270 | - $result = $this->runQuery( $query ); |
|
269 | + $result = $this->runQuery($query); |
|
271 | 270 | |
272 | - return $this->getOtherEntities( $result ); |
|
271 | + return $this->getOtherEntities($result); |
|
273 | 272 | } |
274 | 273 | |
275 | 274 | /** |
@@ -279,8 +278,8 @@ discard block |
||
279 | 278 | * |
280 | 279 | * @return string |
281 | 280 | */ |
282 | - private function stringLiteral( $text ) { |
|
283 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
281 | + private function stringLiteral($text) { |
|
282 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
284 | 283 | } |
285 | 284 | |
286 | 285 | /** |
@@ -290,17 +289,17 @@ discard block |
||
290 | 289 | * |
291 | 290 | * @return CachedEntityIds |
292 | 291 | */ |
293 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
294 | - return new CachedEntityIds( array_map( |
|
295 | - function ( $resultBindings ) { |
|
292 | + private function getOtherEntities(CachedQueryResults $results) { |
|
293 | + return new CachedEntityIds(array_map( |
|
294 | + function($resultBindings) { |
|
296 | 295 | $entityIRI = $resultBindings['otherEntity']['value']; |
297 | - $entityPrefixLength = strlen( $this->entityPrefix ); |
|
298 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $this->entityPrefix ) { |
|
296 | + $entityPrefixLength = strlen($this->entityPrefix); |
|
297 | + if (substr($entityIRI, 0, $entityPrefixLength) === $this->entityPrefix) { |
|
299 | 298 | try { |
300 | 299 | return $this->entityIdParser->parse( |
301 | - substr( $entityIRI, $entityPrefixLength ) |
|
300 | + substr($entityIRI, $entityPrefixLength) |
|
302 | 301 | ); |
303 | - } catch ( EntityIdParsingException $e ) { |
|
302 | + } catch (EntityIdParsingException $e) { |
|
304 | 303 | // fall through |
305 | 304 | } |
306 | 305 | } |
@@ -308,7 +307,7 @@ discard block |
||
308 | 307 | return null; |
309 | 308 | }, |
310 | 309 | $results->getArray()['results']['bindings'] |
311 | - ), $results->getMetadata() ); |
|
310 | + ), $results->getMetadata()); |
|
312 | 311 | } |
313 | 312 | |
314 | 313 | // @codingStandardsIgnoreStart cyclomatic complexity of this function is too high |
@@ -321,47 +320,47 @@ discard block |
||
321 | 320 | * @return array the literal or IRI as a string in SPARQL syntax, |
322 | 321 | * and a boolean indicating whether it refers to a full value node or not |
323 | 322 | */ |
324 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
325 | - switch ( $dataType ) { |
|
323 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
324 | + switch ($dataType) { |
|
326 | 325 | case 'string': |
327 | 326 | case 'external-id': |
328 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
327 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
329 | 328 | case 'commonsMedia': |
330 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
331 | - return [ '<' . $url . '>', false ]; |
|
329 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
330 | + return ['<'.$url.'>', false]; |
|
332 | 331 | case 'geo-shape': |
333 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
334 | - return [ '<' . $url . '>', false ]; |
|
332 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
333 | + return ['<'.$url.'>', false]; |
|
335 | 334 | case 'tabular-data': |
336 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
337 | - return [ '<' . $url . '>', false ]; |
|
335 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
336 | + return ['<'.$url.'>', false]; |
|
338 | 337 | case 'url': |
339 | 338 | $url = $dataValue->getValue(); |
340 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
339 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
341 | 340 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
342 | 341 | // such an URL should never reach us, so just throw |
343 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
342 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
344 | 343 | } |
345 | - return [ '<' . $url . '>', false ]; |
|
344 | + return ['<'.$url.'>', false]; |
|
346 | 345 | case 'wikibase-item': |
347 | 346 | case 'wikibase-property': |
348 | 347 | /** @var EntityIdValue $dataValue */ |
349 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
348 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
350 | 349 | case 'monolingualtext': |
351 | 350 | /** @var MonolingualTextValue $dataValue */ |
352 | 351 | $lang = $dataValue->getLanguageCode(); |
353 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
352 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
354 | 353 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
355 | 354 | // such a language tag should never reach us, so just throw |
356 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
355 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
357 | 356 | } |
358 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
357 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
359 | 358 | case 'globe-coordinate': |
360 | 359 | case 'quantity': |
361 | 360 | case 'time': |
362 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
361 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
363 | 362 | default: |
364 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
363 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
365 | 364 | } |
366 | 365 | } |
367 | 366 | // @codingStandardsIgnoreEnd |
@@ -374,44 +373,44 @@ discard block |
||
374 | 373 | * @throws SparqlHelperException if the query times out or some other error occurs |
375 | 374 | * @throws ConstraintParameterException if the $regex is invalid |
376 | 375 | */ |
377 | - public function matchesRegularExpression( $text, $regex ) { |
|
376 | + public function matchesRegularExpression($text, $regex) { |
|
378 | 377 | // caching wrapper around matchesRegularExpressionWithSparql |
379 | 378 | |
380 | - $textHash = hash( 'sha256', $text ); |
|
379 | + $textHash = hash('sha256', $text); |
|
381 | 380 | $cacheKey = $this->cache->makeKey( |
382 | 381 | 'WikibaseQualityConstraints', // extension |
383 | 382 | 'regex', // action |
384 | 383 | 'WDQS-Java', // regex flavor |
385 | - hash( 'sha256', $regex ) |
|
384 | + hash('sha256', $regex) |
|
386 | 385 | ); |
387 | - $cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
386 | + $cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
388 | 387 | |
389 | 388 | $cacheMapArray = $this->cache->getWithSetCallback( |
390 | 389 | $cacheKey, |
391 | 390 | WANObjectCache::TTL_DAY, |
392 | - function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) { |
|
391 | + function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) { |
|
393 | 392 | // Initialize the cache map if not set |
394 | - if ( $cacheMapArray === false ) { |
|
393 | + if ($cacheMapArray === false) { |
|
395 | 394 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
396 | - $this->dataFactory->increment( $key ); |
|
395 | + $this->dataFactory->increment($key); |
|
397 | 396 | return []; |
398 | 397 | } |
399 | 398 | |
400 | 399 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
401 | - $this->dataFactory->increment( $key ); |
|
402 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize ); |
|
403 | - if ( $cacheMap->has( $textHash ) ) { |
|
400 | + $this->dataFactory->increment($key); |
|
401 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize); |
|
402 | + if ($cacheMap->has($textHash)) { |
|
404 | 403 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
405 | - $this->dataFactory->increment( $key ); |
|
406 | - $cacheMap->get( $textHash ); // ping cache |
|
404 | + $this->dataFactory->increment($key); |
|
405 | + $cacheMap->get($textHash); // ping cache |
|
407 | 406 | } else { |
408 | 407 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
409 | - $this->dataFactory->increment( $key ); |
|
408 | + $this->dataFactory->increment($key); |
|
410 | 409 | try { |
411 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
412 | - } catch ( ConstraintParameterException $e ) { |
|
413 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
414 | - } catch ( SparqlHelperException $e ) { |
|
410 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
411 | + } catch (ConstraintParameterException $e) { |
|
412 | + $matches = $this->serializeConstraintParameterException($e); |
|
413 | + } catch (SparqlHelperException $e) { |
|
415 | 414 | // don’t cache this |
416 | 415 | return $cacheMap->toArray(); |
417 | 416 | } |
@@ -435,36 +434,36 @@ discard block |
||
435 | 434 | ] |
436 | 435 | ); |
437 | 436 | |
438 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
437 | + if (isset($cacheMapArray[$textHash])) { |
|
439 | 438 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
440 | - $this->dataFactory->increment( $key ); |
|
439 | + $this->dataFactory->increment($key); |
|
441 | 440 | $matches = $cacheMapArray[$textHash]; |
442 | - if ( is_bool( $matches ) ) { |
|
441 | + if (is_bool($matches)) { |
|
443 | 442 | return $matches; |
444 | - } elseif ( is_array( $matches ) && |
|
445 | - $matches['type'] == ConstraintParameterException::class ) { |
|
446 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
443 | + } elseif (is_array($matches) && |
|
444 | + $matches['type'] == ConstraintParameterException::class) { |
|
445 | + throw $this->deserializeConstraintParameterException($matches); |
|
447 | 446 | } else { |
448 | 447 | throw new MWException( |
449 | - 'Value of unknown type in object cache (' . |
|
450 | - 'cache key: ' . $cacheKey . ', ' . |
|
451 | - 'cache map key: ' . $textHash . ', ' . |
|
452 | - 'value type: ' . gettype( $matches ) . ')' |
|
448 | + 'Value of unknown type in object cache ('. |
|
449 | + 'cache key: '.$cacheKey.', '. |
|
450 | + 'cache map key: '.$textHash.', '. |
|
451 | + 'value type: '.gettype($matches).')' |
|
453 | 452 | ); |
454 | 453 | } |
455 | 454 | } else { |
456 | 455 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
457 | - $this->dataFactory->increment( $key ); |
|
458 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
456 | + $this->dataFactory->increment($key); |
|
457 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
459 | 458 | } |
460 | 459 | } |
461 | 460 | |
462 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
461 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
463 | 462 | $message = $cpe->getViolationMessage(); |
464 | - if ( $message instanceof ViolationMessage ) { |
|
463 | + if ($message instanceof ViolationMessage) { |
|
465 | 464 | return [ |
466 | 465 | 'type' => ConstraintParameterException::class, |
467 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $message ), |
|
466 | + 'violationMessage' => $this->violationMessageSerializer->serialize($message), |
|
468 | 467 | ]; |
469 | 468 | } else { |
470 | 469 | return [ |
@@ -474,15 +473,15 @@ discard block |
||
474 | 473 | } |
475 | 474 | } |
476 | 475 | |
477 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
478 | - if ( array_key_exists( 'violationMessage', $serialization ) ) { |
|
476 | + private function deserializeConstraintParameterException(array $serialization) { |
|
477 | + if (array_key_exists('violationMessage', $serialization)) { |
|
479 | 478 | $message = $this->violationMessageDeserializer->deserialize( |
480 | 479 | $serialization['violationMessage'] |
481 | 480 | ); |
482 | 481 | } else { |
483 | 482 | $message = $serialization['message']; |
484 | 483 | } |
485 | - return new ConstraintParameterException( $message ); |
|
484 | + return new ConstraintParameterException($message); |
|
486 | 485 | } |
487 | 486 | |
488 | 487 | /** |
@@ -496,26 +495,26 @@ discard block |
||
496 | 495 | * @throws SparqlHelperException if the query times out or some other error occurs |
497 | 496 | * @throws ConstraintParameterException if the $regex is invalid |
498 | 497 | */ |
499 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
500 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
501 | - $regexStringLiteral = $this->stringLiteral( '^' . $regex . '$' ); |
|
498 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
499 | + $textStringLiteral = $this->stringLiteral($text); |
|
500 | + $regexStringLiteral = $this->stringLiteral('^'.$regex.'$'); |
|
502 | 501 | |
503 | 502 | $query = <<<EOF |
504 | 503 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
505 | 504 | EOF; |
506 | 505 | |
507 | - $result = $this->runQuery( $query ); |
|
506 | + $result = $this->runQuery($query); |
|
508 | 507 | |
509 | 508 | $vars = $result->getArray()['results']['bindings'][0]; |
510 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
509 | + if (array_key_exists('matches', $vars)) { |
|
511 | 510 | // true or false ⇒ regex okay, text matches or not |
512 | 511 | return $vars['matches']['value'] === 'true'; |
513 | 512 | } else { |
514 | 513 | // empty result: regex broken |
515 | 514 | throw new ConstraintParameterException( |
516 | - wfMessage( 'wbqc-violation-message-parameter-regex' ) |
|
517 | - ->rawParams( ConstraintParameterRenderer::formatByRole( Role::CONSTRAINT_PARAMETER_VALUE, |
|
518 | - '<code><nowiki>' . htmlspecialchars( $regex ) . '</nowiki></code>' ) ) |
|
515 | + wfMessage('wbqc-violation-message-parameter-regex') |
|
516 | + ->rawParams(ConstraintParameterRenderer::formatByRole(Role::CONSTRAINT_PARAMETER_VALUE, |
|
517 | + '<code><nowiki>'.htmlspecialchars($regex).'</nowiki></code>')) |
|
519 | 518 | ->escaped() |
520 | 519 | ); |
521 | 520 | } |
@@ -528,14 +527,14 @@ discard block |
||
528 | 527 | * |
529 | 528 | * @return boolean |
530 | 529 | */ |
531 | - public function isTimeout( $responseContent ) { |
|
532 | - $timeoutRegex = implode( '|', array_map( |
|
533 | - function ( $fqn ) { |
|
534 | - return preg_quote( $fqn, '/' ); |
|
530 | + public function isTimeout($responseContent) { |
|
531 | + $timeoutRegex = implode('|', array_map( |
|
532 | + function($fqn) { |
|
533 | + return preg_quote($fqn, '/'); |
|
535 | 534 | }, |
536 | - $this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' ) |
|
537 | - ) ); |
|
538 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
535 | + $this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses') |
|
536 | + )); |
|
537 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
539 | 538 | } |
540 | 539 | |
541 | 540 | /** |
@@ -547,17 +546,17 @@ discard block |
||
547 | 546 | * @return integer|boolean the max-age (in seconds) |
548 | 547 | * or a plain boolean if no max-age can be determined |
549 | 548 | */ |
550 | - public function getCacheMaxAge( $responseHeaders ) { |
|
549 | + public function getCacheMaxAge($responseHeaders) { |
|
551 | 550 | if ( |
552 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
553 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
551 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
552 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
554 | 553 | ) { |
555 | 554 | $maxage = []; |
556 | 555 | if ( |
557 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
558 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
556 | + array_key_exists('cache-control', $responseHeaders) && |
|
557 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
559 | 558 | ) { |
560 | - return intval( $maxage[1] ); |
|
559 | + return intval($maxage[1]); |
|
561 | 560 | } else { |
562 | 561 | return true; |
563 | 562 | } |
@@ -575,59 +574,58 @@ discard block |
||
575 | 574 | * |
576 | 575 | * @throws SparqlHelperException if the query times out or some other error occurs |
577 | 576 | */ |
578 | - public function runQuery( $query ) { |
|
577 | + public function runQuery($query) { |
|
579 | 578 | |
580 | - $endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
581 | - $maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
582 | - $url = $endpoint . '?' . http_build_query( |
|
579 | + $endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint'); |
|
580 | + $maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
581 | + $url = $endpoint.'?'.http_build_query( |
|
583 | 582 | [ |
584 | - 'query' => "#wbqc\n" . $this->prefixes . $query, |
|
583 | + 'query' => "#wbqc\n".$this->prefixes.$query, |
|
585 | 584 | 'format' => 'json', |
586 | 585 | 'maxQueryTimeMillis' => $maxQueryTimeMillis, |
587 | 586 | ], |
588 | - null, ini_get( 'arg_separator.output' ), |
|
587 | + null, ini_get('arg_separator.output'), |
|
589 | 588 | // encode spaces with %20, not + |
590 | 589 | PHP_QUERY_RFC3986 |
591 | 590 | ); |
592 | 591 | |
593 | 592 | $options = [ |
594 | 593 | 'method' => 'GET', |
595 | - 'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ), |
|
594 | + 'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000), |
|
596 | 595 | 'connectTimeout' => 'default', |
597 | 596 | ]; |
598 | - $request = MWHttpRequest::factory( $url, $options ); |
|
599 | - $startTime = microtime( true ); |
|
597 | + $request = MWHttpRequest::factory($url, $options); |
|
598 | + $startTime = microtime(true); |
|
600 | 599 | $status = $request->execute(); |
601 | - $endTime = microtime( true ); |
|
600 | + $endTime = microtime(true); |
|
602 | 601 | $this->dataFactory->timing( |
603 | 602 | 'wikibase.quality.constraints.sparql.timing', |
604 | - ( $endTime - $startTime ) * 1000 |
|
603 | + ($endTime - $startTime) * 1000 |
|
605 | 604 | ); |
606 | 605 | |
607 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
608 | - if ( $maxAge ) { |
|
609 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
606 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
607 | + if ($maxAge) { |
|
608 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
610 | 609 | } |
611 | 610 | |
612 | - if ( $status->isOK() ) { |
|
611 | + if ($status->isOK()) { |
|
613 | 612 | $json = $request->getContent(); |
614 | - $arr = json_decode( $json, true ); |
|
613 | + $arr = json_decode($json, true); |
|
615 | 614 | return new CachedQueryResults( |
616 | 615 | $arr, |
617 | 616 | Metadata::ofCachingMetadata( |
618 | 617 | $maxAge ? |
619 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
620 | - CachingMetadata::fresh() |
|
618 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
621 | 619 | ) |
622 | 620 | ); |
623 | 621 | } else { |
624 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
622 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
625 | 623 | |
626 | 624 | $this->dataFactory->increment( |
627 | 625 | "wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}" |
628 | 626 | ); |
629 | 627 | |
630 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
628 | + if ($this->isTimeout($request->getContent())) { |
|
631 | 629 | $this->dataFactory->increment( |
632 | 630 | 'wikibase.quality.constraints.sparql.error.timeout' |
633 | 631 | ); |