@@ -77,17 +77,17 @@ discard block |
||
77 | 77 | * @param ViolationMessage $violationMessage |
78 | 78 | * @return string |
79 | 79 | */ |
80 | - public function render( ViolationMessage $violationMessage ) { |
|
80 | + public function render(ViolationMessage $violationMessage) { |
|
81 | 81 | $messageKey = $violationMessage->getMessageKey(); |
82 | - $paramsLists = [ [] ]; |
|
83 | - foreach ( $violationMessage->getArguments() as $argument ) { |
|
84 | - $params = $this->renderArgument( $argument ); |
|
82 | + $paramsLists = [[]]; |
|
83 | + foreach ($violationMessage->getArguments() as $argument) { |
|
84 | + $params = $this->renderArgument($argument); |
|
85 | 85 | $paramsLists[] = $params; |
86 | 86 | } |
87 | - $allParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
87 | + $allParams = call_user_func_array('array_merge', $paramsLists); |
|
88 | 88 | return $this->messageLocalizer |
89 | - ->msg( $messageKey ) |
|
90 | - ->params( $allParams ) |
|
89 | + ->msg($messageKey) |
|
90 | + ->params($allParams) |
|
91 | 91 | ->escaped(); |
92 | 92 | } |
93 | 93 | |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | * @param string|null $role one of the Role::* constants |
97 | 97 | * @return string HTML |
98 | 98 | */ |
99 | - protected function addRole( $value, $role ) { |
|
100 | - if ( $role === null ) { |
|
99 | + protected function addRole($value, $role) { |
|
100 | + if ($role === null) { |
|
101 | 101 | return $value; |
102 | 102 | } |
103 | 103 | |
104 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' . |
|
105 | - $value . |
|
104 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'. |
|
105 | + $value. |
|
106 | 106 | '</span>'; |
107 | 107 | } |
108 | 108 | |
@@ -110,15 +110,15 @@ discard block |
||
110 | 110 | * @param string $key message key |
111 | 111 | * @return string HTML |
112 | 112 | */ |
113 | - protected function msgEscaped( $key ) { |
|
114 | - return $this->messageLocalizer->msg( $key )->escaped(); |
|
113 | + protected function msgEscaped($key) { |
|
114 | + return $this->messageLocalizer->msg($key)->escaped(); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
118 | 118 | * @param array $argument |
119 | 119 | * @return array[] params (for Message::params) |
120 | 120 | */ |
121 | - protected function renderArgument( array $argument ) { |
|
121 | + protected function renderArgument(array $argument) { |
|
122 | 122 | $methods = [ |
123 | 123 | ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId', |
124 | 124 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList', |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | $value = $argument['value']; |
139 | 139 | $role = $argument['role']; |
140 | 140 | |
141 | - if ( array_key_exists( $type, $methods ) ) { |
|
141 | + if (array_key_exists($type, $methods)) { |
|
142 | 142 | $method = $methods[$type]; |
143 | - $params = $this->$method( $value, $role ); |
|
143 | + $params = $this->$method($value, $role); |
|
144 | 144 | } else { |
145 | 145 | throw new InvalidArgumentException( |
146 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
146 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
147 | 147 | ); |
148 | 148 | } |
149 | 149 | |
@@ -157,46 +157,46 @@ discard block |
||
157 | 157 | * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ]) |
158 | 158 | * @return array[] list of parameters as accepted by Message::params() |
159 | 159 | */ |
160 | - private function renderList( array $list, $role, callable $render ) { |
|
161 | - if ( $list === [] ) { |
|
160 | + private function renderList(array $list, $role, callable $render) { |
|
161 | + if ($list === []) { |
|
162 | 162 | return [ |
163 | - Message::numParam( 0 ), |
|
164 | - Message::rawParam( '<ul></ul>' ), |
|
163 | + Message::numParam(0), |
|
164 | + Message::rawParam('<ul></ul>'), |
|
165 | 165 | ]; |
166 | 166 | } |
167 | 167 | |
168 | - if ( count( $list ) > $this->maxListLength ) { |
|
169 | - $list = array_slice( $list, 0, $this->maxListLength ); |
|
168 | + if (count($list) > $this->maxListLength) { |
|
169 | + $list = array_slice($list, 0, $this->maxListLength); |
|
170 | 170 | $truncated = true; |
171 | 171 | } |
172 | 172 | |
173 | 173 | $renderedParamsLists = array_map( |
174 | 174 | $render, |
175 | 175 | $list, |
176 | - array_fill( 0, count( $list ), $role ) |
|
176 | + array_fill(0, count($list), $role) |
|
177 | 177 | ); |
178 | 178 | $renderedParams = array_map( |
179 | - function ( $params ) { |
|
179 | + function($params) { |
|
180 | 180 | return $params[0]; |
181 | 181 | }, |
182 | 182 | $renderedParamsLists |
183 | 183 | ); |
184 | 184 | $renderedElements = array_map( |
185 | - function ( $param ) { |
|
185 | + function($param) { |
|
186 | 186 | return $param['raw']; |
187 | 187 | }, |
188 | 188 | $renderedParams |
189 | 189 | ); |
190 | - if ( isset( $truncated ) ) { |
|
191 | - $renderedElements[] = $this->msgEscaped( 'ellipsis' ); |
|
190 | + if (isset($truncated)) { |
|
191 | + $renderedElements[] = $this->msgEscaped('ellipsis'); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | return array_merge( |
195 | 195 | [ |
196 | - Message::numParam( count( $list ) ), |
|
196 | + Message::numParam(count($list)), |
|
197 | 197 | Message::rawParam( |
198 | - '<ul><li>' . |
|
199 | - implode( '</li><li>', $renderedElements ) . |
|
198 | + '<ul><li>'. |
|
199 | + implode('</li><li>', $renderedElements). |
|
200 | 200 | '</li></ul>' |
201 | 201 | ), |
202 | 202 | ], |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | * @param string|null $role one of the Role::* constants |
210 | 210 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
211 | 211 | */ |
212 | - private function renderEntityId( EntityId $entityId, $role ) { |
|
213 | - return [ Message::rawParam( $this->addRole( |
|
214 | - $this->entityIdFormatter->formatEntityId( $entityId ), |
|
212 | + private function renderEntityId(EntityId $entityId, $role) { |
|
213 | + return [Message::rawParam($this->addRole( |
|
214 | + $this->entityIdFormatter->formatEntityId($entityId), |
|
215 | 215 | $role |
216 | - ) ) ]; |
|
216 | + ))]; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | * @param string|null $role one of the Role::* constants |
222 | 222 | * @return array[] list of parameters as accepted by Message::params() |
223 | 223 | */ |
224 | - private function renderEntityIdList( array $entityIdList, $role ) { |
|
225 | - return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] ); |
|
224 | + private function renderEntityIdList(array $entityIdList, $role) { |
|
225 | + return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -230,24 +230,24 @@ discard block |
||
230 | 230 | * @param string|null $role one of the Role::* constants |
231 | 231 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
232 | 232 | */ |
233 | - private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) { |
|
234 | - switch ( true ) { |
|
233 | + private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) { |
|
234 | + switch (true) { |
|
235 | 235 | case $value->isValue(): |
236 | - return $this->renderEntityId( $value->getItemId(), $role ); |
|
236 | + return $this->renderEntityId($value->getItemId(), $role); |
|
237 | 237 | case $value->isSomeValue(): |
238 | - return [ Message::rawParam( $this->addRole( |
|
239 | - '<span class="wikibase-snakview-variation-somevaluesnak">' . |
|
240 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-somevalue' ) . |
|
238 | + return [Message::rawParam($this->addRole( |
|
239 | + '<span class="wikibase-snakview-variation-somevaluesnak">'. |
|
240 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-somevalue'). |
|
241 | 241 | '</span>', |
242 | 242 | $role |
243 | - ) ) ]; |
|
243 | + ))]; |
|
244 | 244 | case $value->isNoValue(): |
245 | - return [ Message::rawParam( $this->addRole( |
|
246 | - '<span class="wikibase-snakview-variation-novaluesnak">' . |
|
247 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-novalue' ) . |
|
245 | + return [Message::rawParam($this->addRole( |
|
246 | + '<span class="wikibase-snakview-variation-novaluesnak">'. |
|
247 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-novalue'). |
|
248 | 248 | '</span>', |
249 | 249 | $role |
250 | - ) ) ]; |
|
250 | + ))]; |
|
251 | 251 | default: |
252 | 252 | // @codeCoverageIgnoreStart |
253 | 253 | throw new LogicException( |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | * @param string|null $role one of the Role::* constants |
263 | 263 | * @return array[] list of parameters as accepted by Message::params() |
264 | 264 | */ |
265 | - private function renderItemIdSnakValueList( array $valueList, $role ) { |
|
266 | - return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] ); |
|
265 | + private function renderItemIdSnakValueList(array $valueList, $role) { |
|
266 | + return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -271,11 +271,11 @@ discard block |
||
271 | 271 | * @param string|null $role one of the Role::* constants |
272 | 272 | * @return array[] list of parameters as accepted by Message::params() |
273 | 273 | */ |
274 | - private function renderDataValue( DataValue $dataValue, $role ) { |
|
275 | - return [ Message::rawParam( $this->addRole( |
|
276 | - $this->dataValueFormatter->format( $dataValue ), |
|
274 | + private function renderDataValue(DataValue $dataValue, $role) { |
|
275 | + return [Message::rawParam($this->addRole( |
|
276 | + $this->dataValueFormatter->format($dataValue), |
|
277 | 277 | $role |
278 | - ) ) ]; |
|
278 | + ))]; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @param string|null $role one of the Role::* constants |
284 | 284 | * @return array[] list of parameters as accepted by Message::params() |
285 | 285 | */ |
286 | - private function renderDataValueType( $dataValueType, $role ) { |
|
286 | + private function renderDataValueType($dataValueType, $role) { |
|
287 | 287 | $messageKeys = [ |
288 | 288 | 'string' => 'datatypes-type-string', |
289 | 289 | 'monolingualtext' => 'datatypes-type-monolingualtext', |
@@ -292,15 +292,15 @@ discard block |
||
292 | 292 | 'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid', |
293 | 293 | ]; |
294 | 294 | |
295 | - if ( array_key_exists( $dataValueType, $messageKeys ) ) { |
|
296 | - return [ Message::rawParam( $this->addRole( |
|
297 | - $this->msgEscaped( $messageKeys[$dataValueType] ), |
|
295 | + if (array_key_exists($dataValueType, $messageKeys)) { |
|
296 | + return [Message::rawParam($this->addRole( |
|
297 | + $this->msgEscaped($messageKeys[$dataValueType]), |
|
298 | 298 | $role |
299 | - ) ) ]; |
|
299 | + ))]; |
|
300 | 300 | } else { |
301 | 301 | // @codeCoverageIgnoreStart |
302 | 302 | throw new LogicException( |
303 | - 'Unknown data value type ' . $dataValueType |
|
303 | + 'Unknown data value type '.$dataValueType |
|
304 | 304 | ); |
305 | 305 | // @codeCoverageIgnoreEnd |
306 | 306 | } |
@@ -311,11 +311,11 @@ discard block |
||
311 | 311 | * @param string|null $role one of the Role::* constants |
312 | 312 | * @return array[] list of parameters as accepted by Message::params() |
313 | 313 | */ |
314 | - private function renderInlineCode( $code, $role ) { |
|
315 | - return [ Message::rawParam( $this->addRole( |
|
316 | - '<code>' . htmlspecialchars( $code ) . '</code>', |
|
314 | + private function renderInlineCode($code, $role) { |
|
315 | + return [Message::rawParam($this->addRole( |
|
316 | + '<code>'.htmlspecialchars($code).'</code>', |
|
317 | 317 | $role |
318 | - ) ) ]; |
|
318 | + ))]; |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | * @param string|null $role one of the Role::* constants |
324 | 324 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
325 | 325 | */ |
326 | - private function renderConstraintScope( $scope, $role ) { |
|
327 | - switch ( $scope ) { |
|
326 | + private function renderConstraintScope($scope, $role) { |
|
327 | + switch ($scope) { |
|
328 | 328 | case Context::TYPE_STATEMENT: |
329 | 329 | $itemId = $this->config->get( |
330 | 330 | 'WBQualityConstraintsConstraintCheckedOnMainValueId' |
@@ -344,10 +344,10 @@ discard block |
||
344 | 344 | // callers should never let this happen, but if it does happen, |
345 | 345 | // showing “unknown value” seems reasonable |
346 | 346 | // @codeCoverageIgnoreStart |
347 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
347 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
348 | 348 | // @codeCoverageIgnoreEnd |
349 | 349 | } |
350 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
350 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -355,8 +355,8 @@ discard block |
||
355 | 355 | * @param string|null $role one of the Role::* constants |
356 | 356 | * @return array[] list of parameters as accepted by Message::params() |
357 | 357 | */ |
358 | - private function renderConstraintScopeList( array $scopeList, $role ) { |
|
359 | - return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] ); |
|
358 | + private function renderConstraintScopeList(array $scopeList, $role) { |
|
359 | + return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
@@ -364,25 +364,25 @@ discard block |
||
364 | 364 | * @param string|null $role one of the Role::* constants |
365 | 365 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
366 | 366 | */ |
367 | - private function renderPropertyScope( $scope, $role ) { |
|
368 | - switch ( $scope ) { |
|
367 | + private function renderPropertyScope($scope, $role) { |
|
368 | + switch ($scope) { |
|
369 | 369 | case Context::TYPE_STATEMENT: |
370 | - $itemId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
370 | + $itemId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
371 | 371 | break; |
372 | 372 | case Context::TYPE_QUALIFIER: |
373 | - $itemId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
373 | + $itemId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
374 | 374 | break; |
375 | 375 | case Context::TYPE_REFERENCE: |
376 | - $itemId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
376 | + $itemId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
377 | 377 | break; |
378 | 378 | default: |
379 | 379 | // callers should never let this happen, but if it does happen, |
380 | 380 | // showing “unknown value” seems reasonable |
381 | 381 | // @codeCoverageIgnoreStart |
382 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
382 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
383 | 383 | // @codeCoverageIgnoreEnd |
384 | 384 | } |
385 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
385 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -390,8 +390,8 @@ discard block |
||
390 | 390 | * @param string|null $role one of the Role::* constants |
391 | 391 | * @return array[] list of parameters as accepted by Message::params() |
392 | 392 | */ |
393 | - private function renderPropertyScopeList( array $scopeList, $role ) { |
|
394 | - return $this->renderList( $scopeList, $role, [ $this, 'renderPropertyScope' ] ); |
|
393 | + private function renderPropertyScopeList(array $scopeList, $role) { |
|
394 | + return $this->renderList($scopeList, $role, [$this, 'renderPropertyScope']); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
@@ -399,10 +399,10 @@ discard block |
||
399 | 399 | * @param string|null $role one of the Role::* constants |
400 | 400 | * @return array[] list of parameters as accepted by Message::params() |
401 | 401 | */ |
402 | - private function renderLanguage( $languageCode, $role ) { |
|
402 | + private function renderLanguage($languageCode, $role) { |
|
403 | 403 | return [ |
404 | - Message::plaintextParam( Language::fetchLanguageName( $languageCode ) ), |
|
405 | - Message::plaintextParam( $languageCode ), |
|
404 | + Message::plaintextParam(Language::fetchLanguageName($languageCode)), |
|
405 | + Message::plaintextParam($languageCode), |
|
406 | 406 | ]; |
407 | 407 | } |
408 | 408 |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | * @param ViolationMessage $violationMessage |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - public function render( ViolationMessage $violationMessage ) { |
|
58 | - if ( !array_key_exists( $violationMessage->getMessageKey(), $this->alternativeMessageKeys ) ) { |
|
59 | - return parent::render( $violationMessage ); |
|
57 | + public function render(ViolationMessage $violationMessage) { |
|
58 | + if (!array_key_exists($violationMessage->getMessageKey(), $this->alternativeMessageKeys)) { |
|
59 | + return parent::render($violationMessage); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $arguments = $violationMessage->getArguments(); |
63 | - $multilingualTextArgument = array_pop( $arguments ); |
|
63 | + $multilingualTextArgument = array_pop($arguments); |
|
64 | 64 | $multilingualTextParams = $this->renderMultilingualText( |
65 | 65 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable TODO Ensure this is not an actual issue |
66 | 66 | $multilingualTextArgument['value'], |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | $multilingualTextArgument['role'] |
69 | 69 | ); |
70 | 70 | |
71 | - $paramsLists = [ [] ]; |
|
72 | - foreach ( $arguments as $argument ) { |
|
73 | - $paramsLists[] = $this->renderArgument( $argument ); |
|
71 | + $paramsLists = [[]]; |
|
72 | + foreach ($arguments as $argument) { |
|
73 | + $paramsLists[] = $this->renderArgument($argument); |
|
74 | 74 | } |
75 | - $regularParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
75 | + $regularParams = call_user_func_array('array_merge', $paramsLists); |
|
76 | 76 | |
77 | - if ( $multilingualTextParams === null ) { |
|
77 | + if ($multilingualTextParams === null) { |
|
78 | 78 | return $this->messageLocalizer |
79 | - ->msg( $this->alternativeMessageKeys[$violationMessage->getMessageKey()] ) |
|
80 | - ->params( $regularParams ) |
|
79 | + ->msg($this->alternativeMessageKeys[$violationMessage->getMessageKey()]) |
|
80 | + ->params($regularParams) |
|
81 | 81 | ->escaped(); |
82 | 82 | } else { |
83 | 83 | return $this->messageLocalizer |
84 | - ->msg( $violationMessage->getMessageKey() ) |
|
85 | - ->params( $regularParams ) |
|
86 | - ->params( $multilingualTextParams ) |
|
84 | + ->msg($violationMessage->getMessageKey()) |
|
85 | + ->params($regularParams) |
|
86 | + ->params($multilingualTextParams) |
|
87 | 87 | ->escaped(); |
88 | 88 | } |
89 | 89 | } |
@@ -94,18 +94,18 @@ discard block |
||
94 | 94 | * @return array[]|null list of parameters as accepted by Message::params(), |
95 | 95 | * or null if the text is not available in the user’s language |
96 | 96 | */ |
97 | - protected function renderMultilingualText( MultilingualTextValue $text, $role ) { |
|
97 | + protected function renderMultilingualText(MultilingualTextValue $text, $role) { |
|
98 | 98 | global $wgLang; |
99 | 99 | $languageCodes = $wgLang->getFallbackLanguages(); |
100 | - array_unshift( $languageCodes, $wgLang->getCode() ); |
|
100 | + array_unshift($languageCodes, $wgLang->getCode()); |
|
101 | 101 | |
102 | 102 | $texts = $text->getTexts(); |
103 | - foreach ( $languageCodes as $languageCode ) { |
|
104 | - if ( array_key_exists( $languageCode, $texts ) ) { |
|
105 | - return [ Message::rawParam( $this->addRole( |
|
106 | - htmlspecialchars( $texts[$languageCode]->getText() ), |
|
103 | + foreach ($languageCodes as $languageCode) { |
|
104 | + if (array_key_exists($languageCode, $texts)) { |
|
105 | + return [Message::rawParam($this->addRole( |
|
106 | + htmlspecialchars($texts[$languageCode]->getText()), |
|
107 | 107 | $role |
108 | - ) ) ]; |
|
108 | + ))]; |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param WANObjectCache $cache |
37 | 37 | * @param string $formatVersion The version of the API response format. |
38 | 38 | */ |
39 | - public function __construct( WANObjectCache $cache, $formatVersion ) { |
|
39 | + public function __construct(WANObjectCache $cache, $formatVersion) { |
|
40 | 40 | $this->cache = $cache; |
41 | 41 | $this->formatVersion = $formatVersion; |
42 | 42 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param EntityId $entityId |
46 | 46 | * @return string cache key |
47 | 47 | */ |
48 | - public function makeKey( EntityId $entityId ) { |
|
48 | + public function makeKey(EntityId $entityId) { |
|
49 | 49 | return $this->cache->makeKey( |
50 | 50 | 'WikibaseQualityConstraints', // extension |
51 | 51 | 'checkConstraints', // action |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param mixed|null &$info |
62 | 62 | * @return mixed |
63 | 63 | */ |
64 | - public function get( EntityId $key, &$curTTL = null, array $checkKeys = [], &$info = null ) { |
|
65 | - return $this->cache->get( $this->makeKey( $key ), $curTTL, $checkKeys, $info ); |
|
64 | + public function get(EntityId $key, &$curTTL = null, array $checkKeys = [], &$info = null) { |
|
65 | + return $this->cache->get($this->makeKey($key), $curTTL, $checkKeys, $info); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -72,16 +72,16 @@ discard block |
||
72 | 72 | * @param array $opts |
73 | 73 | * @return bool |
74 | 74 | */ |
75 | - public function set( EntityId $key, $value, $ttl = 0, array $opts = [] ) { |
|
76 | - return $this->cache->set( $this->makeKey( $key ), $value, $ttl, $opts ); |
|
75 | + public function set(EntityId $key, $value, $ttl = 0, array $opts = []) { |
|
76 | + return $this->cache->set($this->makeKey($key), $value, $ttl, $opts); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @param EntityId $key |
81 | 81 | * @return bool |
82 | 82 | */ |
83 | - public function delete( EntityId $key ) { |
|
84 | - return $this->cache->delete( $this->makeKey( $key ) ); |
|
83 | + public function delete(EntityId $key) { |
|
84 | + return $this->cache->delete($this->makeKey($key)); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | } |
@@ -36,189 +36,189 @@ |
||
36 | 36 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker; |
37 | 37 | |
38 | 38 | return [ |
39 | - ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => function ( MediaWikiServices $services ) { |
|
39 | + ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => function(MediaWikiServices $services) { |
|
40 | 40 | return new ConflictsWithChecker( |
41 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
42 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
41 | + ConstraintsServices::getConstraintParameterParser($services), |
|
42 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
43 | 43 | ); |
44 | 44 | }, |
45 | 45 | |
46 | - ConstraintCheckerServices::ITEM_CHECKER => function ( MediaWikiServices $services ) { |
|
46 | + ConstraintCheckerServices::ITEM_CHECKER => function(MediaWikiServices $services) { |
|
47 | 47 | return new ItemChecker( |
48 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
49 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
48 | + ConstraintsServices::getConstraintParameterParser($services), |
|
49 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
50 | 50 | ); |
51 | 51 | }, |
52 | 52 | |
53 | - ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => function ( MediaWikiServices $services ) { |
|
53 | + ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => function(MediaWikiServices $services) { |
|
54 | 54 | return new TargetRequiredClaimChecker( |
55 | - WikibaseServices::getEntityLookup( $services ), |
|
56 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
57 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
55 | + WikibaseServices::getEntityLookup($services), |
|
56 | + ConstraintsServices::getConstraintParameterParser($services), |
|
57 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
58 | 58 | ); |
59 | 59 | }, |
60 | 60 | |
61 | - ConstraintCheckerServices::SYMMETRIC_CHECKER => function ( MediaWikiServices $services ) { |
|
61 | + ConstraintCheckerServices::SYMMETRIC_CHECKER => function(MediaWikiServices $services) { |
|
62 | 62 | return new SymmetricChecker( |
63 | - WikibaseServices::getEntityLookupWithoutCache( $services ), |
|
64 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
63 | + WikibaseServices::getEntityLookupWithoutCache($services), |
|
64 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
65 | 65 | ); |
66 | 66 | }, |
67 | 67 | |
68 | - ConstraintCheckerServices::INVERSE_CHECKER => function ( MediaWikiServices $services ) { |
|
68 | + ConstraintCheckerServices::INVERSE_CHECKER => function(MediaWikiServices $services) { |
|
69 | 69 | return new InverseChecker( |
70 | - WikibaseServices::getEntityLookup( $services ), |
|
71 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
72 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
70 | + WikibaseServices::getEntityLookup($services), |
|
71 | + ConstraintsServices::getConstraintParameterParser($services), |
|
72 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
73 | 73 | ); |
74 | 74 | }, |
75 | 75 | |
76 | - ConstraintCheckerServices::QUALIFIER_CHECKER => function ( MediaWikiServices $services ) { |
|
76 | + ConstraintCheckerServices::QUALIFIER_CHECKER => function(MediaWikiServices $services) { |
|
77 | 77 | return new QualifierChecker(); |
78 | 78 | }, |
79 | 79 | |
80 | - ConstraintCheckerServices::QUALIFIERS_CHECKER => function ( MediaWikiServices $services ) { |
|
80 | + ConstraintCheckerServices::QUALIFIERS_CHECKER => function(MediaWikiServices $services) { |
|
81 | 81 | return new QualifiersChecker( |
82 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
82 | + ConstraintsServices::getConstraintParameterParser($services) |
|
83 | 83 | ); |
84 | 84 | }, |
85 | 85 | |
86 | - ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => function ( MediaWikiServices $services ) { |
|
86 | + ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => function(MediaWikiServices $services) { |
|
87 | 87 | return new MandatoryQualifiersChecker( |
88 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
88 | + ConstraintsServices::getConstraintParameterParser($services) |
|
89 | 89 | ); |
90 | 90 | }, |
91 | 91 | |
92 | - ConstraintCheckerServices::RANGE_CHECKER => function ( MediaWikiServices $services ) { |
|
92 | + ConstraintCheckerServices::RANGE_CHECKER => function(MediaWikiServices $services) { |
|
93 | 93 | return new RangeChecker( |
94 | - WikibaseServices::getPropertyDataTypeLookup( $services ), |
|
95 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
96 | - ConstraintsServices::getRangeCheckerHelper( $services ) |
|
94 | + WikibaseServices::getPropertyDataTypeLookup($services), |
|
95 | + ConstraintsServices::getConstraintParameterParser($services), |
|
96 | + ConstraintsServices::getRangeCheckerHelper($services) |
|
97 | 97 | ); |
98 | 98 | }, |
99 | 99 | |
100 | - ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => function ( MediaWikiServices $services ) { |
|
100 | + ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => function(MediaWikiServices $services) { |
|
101 | 101 | return new DiffWithinRangeChecker( |
102 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
103 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
102 | + ConstraintsServices::getConstraintParameterParser($services), |
|
103 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
104 | 104 | $services->getMainConfig() |
105 | 105 | ); |
106 | 106 | }, |
107 | 107 | |
108 | - ConstraintCheckerServices::TYPE_CHECKER => function ( MediaWikiServices $services ) { |
|
108 | + ConstraintCheckerServices::TYPE_CHECKER => function(MediaWikiServices $services) { |
|
109 | 109 | return new TypeChecker( |
110 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
111 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
110 | + ConstraintsServices::getConstraintParameterParser($services), |
|
111 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
112 | 112 | $services->getMainConfig() |
113 | 113 | ); |
114 | 114 | }, |
115 | 115 | |
116 | - ConstraintCheckerServices::VALUE_TYPE_CHECKER => function ( MediaWikiServices $services ) { |
|
116 | + ConstraintCheckerServices::VALUE_TYPE_CHECKER => function(MediaWikiServices $services) { |
|
117 | 117 | return new ValueTypeChecker( |
118 | - WikibaseServices::getEntityLookup( $services ), |
|
119 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
120 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
118 | + WikibaseServices::getEntityLookup($services), |
|
119 | + ConstraintsServices::getConstraintParameterParser($services), |
|
120 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
121 | 121 | $services->getMainConfig() |
122 | 122 | ); |
123 | 123 | }, |
124 | 124 | |
125 | - ConstraintCheckerServices::SINGLE_VALUE_CHECKER => function ( MediaWikiServices $services ) { |
|
125 | + ConstraintCheckerServices::SINGLE_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
126 | 126 | return new SingleValueChecker( |
127 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
127 | + ConstraintsServices::getConstraintParameterParser($services) |
|
128 | 128 | ); |
129 | 129 | }, |
130 | 130 | |
131 | - ConstraintCheckerServices::MULTI_VALUE_CHECKER => function ( MediaWikiServices $services ) { |
|
131 | + ConstraintCheckerServices::MULTI_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
132 | 132 | return new MultiValueChecker( |
133 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
133 | + ConstraintsServices::getConstraintParameterParser($services) |
|
134 | 134 | ); |
135 | 135 | }, |
136 | 136 | |
137 | - ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => function ( MediaWikiServices $services ) { |
|
137 | + ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
138 | 138 | // TODO return a different, dummy implementation if SPARQL is not available |
139 | 139 | return new UniqueValueChecker( |
140 | - ConstraintsServices::getSparqlHelper( $services ) |
|
140 | + ConstraintsServices::getSparqlHelper($services) |
|
141 | 141 | ); |
142 | 142 | }, |
143 | 143 | |
144 | - ConstraintCheckerServices::FORMAT_CHECKER => function ( MediaWikiServices $services ) { |
|
144 | + ConstraintCheckerServices::FORMAT_CHECKER => function(MediaWikiServices $services) { |
|
145 | 145 | // TODO return a different, dummy implementation if SPARQL is not available |
146 | 146 | return new FormatChecker( |
147 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
147 | + ConstraintsServices::getConstraintParameterParser($services), |
|
148 | 148 | $services->getMainConfig(), |
149 | - ConstraintsServices::getSparqlHelper( $services ) |
|
149 | + ConstraintsServices::getSparqlHelper($services) |
|
150 | 150 | ); |
151 | 151 | }, |
152 | 152 | |
153 | - ConstraintCheckerServices::COMMONS_LINK_CHECKER => function ( MediaWikiServices $services ) { |
|
153 | + ConstraintCheckerServices::COMMONS_LINK_CHECKER => function(MediaWikiServices $services) { |
|
154 | 154 | $pageNameNormalizer = new MediaWikiPageNameNormalizer(); |
155 | 155 | return new CommonsLinkChecker( |
156 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
156 | + ConstraintsServices::getConstraintParameterParser($services), |
|
157 | 157 | $pageNameNormalizer |
158 | 158 | ); |
159 | 159 | }, |
160 | 160 | |
161 | - ConstraintCheckerServices::ONE_OF_CHECKER => function ( MediaWikiServices $services ) { |
|
161 | + ConstraintCheckerServices::ONE_OF_CHECKER => function(MediaWikiServices $services) { |
|
162 | 162 | return new OneOfChecker( |
163 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
163 | + ConstraintsServices::getConstraintParameterParser($services) |
|
164 | 164 | ); |
165 | 165 | }, |
166 | 166 | |
167 | - ConstraintCheckerServices::VALUE_ONLY_CHECKER => function ( MediaWikiServices $services ) { |
|
167 | + ConstraintCheckerServices::VALUE_ONLY_CHECKER => function(MediaWikiServices $services) { |
|
168 | 168 | return new ValueOnlyChecker(); |
169 | 169 | }, |
170 | 170 | |
171 | - ConstraintCheckerServices::REFERENCE_CHECKER => function ( MediaWikiServices $services ) { |
|
171 | + ConstraintCheckerServices::REFERENCE_CHECKER => function(MediaWikiServices $services) { |
|
172 | 172 | return new ReferenceChecker(); |
173 | 173 | }, |
174 | 174 | |
175 | - ConstraintCheckerServices::NO_BOUNDS_CHECKER => function ( MediaWikiServices $services ) { |
|
175 | + ConstraintCheckerServices::NO_BOUNDS_CHECKER => function(MediaWikiServices $services) { |
|
176 | 176 | return new NoBoundsChecker(); |
177 | 177 | }, |
178 | 178 | |
179 | - ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => function ( MediaWikiServices $services ) { |
|
179 | + ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => function(MediaWikiServices $services) { |
|
180 | 180 | return new AllowedUnitsChecker( |
181 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
182 | - WikibaseRepo::getUnitConverter( $services ) |
|
181 | + ConstraintsServices::getConstraintParameterParser($services), |
|
182 | + WikibaseRepo::getUnitConverter($services) |
|
183 | 183 | ); |
184 | 184 | }, |
185 | 185 | |
186 | - ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => function ( MediaWikiServices $services ) { |
|
186 | + ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
187 | 187 | return new SingleBestValueChecker( |
188 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
188 | + ConstraintsServices::getConstraintParameterParser($services) |
|
189 | 189 | ); |
190 | 190 | }, |
191 | 191 | |
192 | - ConstraintCheckerServices::ENTITY_TYPE_CHECKER => function ( MediaWikiServices $services ) { |
|
192 | + ConstraintCheckerServices::ENTITY_TYPE_CHECKER => function(MediaWikiServices $services) { |
|
193 | 193 | return new EntityTypeChecker( |
194 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
194 | + ConstraintsServices::getConstraintParameterParser($services) |
|
195 | 195 | ); |
196 | 196 | }, |
197 | 197 | |
198 | - ConstraintCheckerServices::NONE_OF_CHECKER => function ( MediaWikiServices $services ) { |
|
198 | + ConstraintCheckerServices::NONE_OF_CHECKER => function(MediaWikiServices $services) { |
|
199 | 199 | return new NoneOfChecker( |
200 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
200 | + ConstraintsServices::getConstraintParameterParser($services) |
|
201 | 201 | ); |
202 | 202 | }, |
203 | 203 | |
204 | - ConstraintCheckerServices::INTEGER_CHECKER => function ( MediaWikiServices $services ) { |
|
204 | + ConstraintCheckerServices::INTEGER_CHECKER => function(MediaWikiServices $services) { |
|
205 | 205 | return new IntegerChecker(); |
206 | 206 | }, |
207 | 207 | |
208 | - ConstraintCheckerServices::CITATION_NEEDED_CHECKER => function ( MediaWikiServices $services ) { |
|
208 | + ConstraintCheckerServices::CITATION_NEEDED_CHECKER => function(MediaWikiServices $services) { |
|
209 | 209 | return new CitationNeededChecker(); |
210 | 210 | }, |
211 | 211 | |
212 | - ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => function ( MediaWikiServices $services ) { |
|
212 | + ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => function(MediaWikiServices $services) { |
|
213 | 213 | return new PropertyScopeChecker( |
214 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
214 | + ConstraintsServices::getConstraintParameterParser($services) |
|
215 | 215 | ); |
216 | 216 | }, |
217 | 217 | |
218 | - ConstraintCheckerServices::CONTEMPORARY_CHECKER => function ( MediaWikiServices $services ) { |
|
218 | + ConstraintCheckerServices::CONTEMPORARY_CHECKER => function(MediaWikiServices $services) { |
|
219 | 219 | return new ContemporaryChecker( |
220 | - WikibaseServices::getEntityLookup( $services ), |
|
221 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
220 | + WikibaseServices::getEntityLookup($services), |
|
221 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
222 | 222 | $services->getMainConfig() |
223 | 223 | ); |
224 | 224 | }, |
@@ -28,27 +28,27 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param DatabaseUpdater $updater |
30 | 30 | */ |
31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
32 | - $dir = dirname( __DIR__ ) . '/sql/'; |
|
31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
32 | + $dir = dirname(__DIR__).'/sql/'; |
|
33 | 33 | |
34 | 34 | $updater->addExtensionTable( |
35 | 35 | 'wbqc_constraints', |
36 | - $dir . "/{$updater->getDB()->getType()}/tables-generated.sql" |
|
36 | + $dir."/{$updater->getDB()->getType()}/tables-generated.sql" |
|
37 | 37 | ); |
38 | 38 | $updater->addExtensionField( |
39 | 39 | 'wbqc_constraints', |
40 | 40 | 'constraint_id', |
41 | - $dir . '/patch-wbqc_constraints-constraint_id.sql' |
|
41 | + $dir.'/patch-wbqc_constraints-constraint_id.sql' |
|
42 | 42 | ); |
43 | 43 | $updater->addExtensionIndex( |
44 | 44 | 'wbqc_constraints', |
45 | 45 | 'wbqc_constraints_guid_uniq', |
46 | - $dir . '/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
46 | + $dir.'/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
47 | 47 | ); |
48 | 48 | } |
49 | 49 | |
50 | - public static function onWikibaseChange( Change $change ) { |
|
51 | - if ( !( $change instanceof EntityChange ) ) { |
|
50 | + public static function onWikibaseChange(Change $change) { |
|
51 | + if (!($change instanceof EntityChange)) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
@@ -57,48 +57,48 @@ discard block |
||
57 | 57 | |
58 | 58 | // If jobs are enabled and the results would be stored in some way run a job. |
59 | 59 | if ( |
60 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
61 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
60 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
61 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
62 | 62 | self::isSelectedForJobRunBasedOnPercentage() |
63 | 63 | ) { |
64 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
64 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
65 | 65 | JobQueueGroup::singleton()->lazyPush( |
66 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
66 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
67 | 67 | ); |
68 | 68 | } |
69 | 69 | |
70 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
71 | - self::isConstraintStatementsChange( $config, $change ) |
|
70 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
71 | + self::isConstraintStatementsChange($config, $change) |
|
72 | 72 | ) { |
73 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
73 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
74 | 74 | $metadata = $change->getMetadata(); |
75 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
75 | + if (array_key_exists('rev_id', $metadata)) { |
|
76 | 76 | $params['revisionId'] = $metadata['rev_id']; |
77 | 77 | } |
78 | 78 | JobQueueGroup::singleton()->push( |
79 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
79 | + new JobSpecification('constraintsTableUpdate', $params) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | 84 | private static function isSelectedForJobRunBasedOnPercentage() { |
85 | 85 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
86 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
86 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
87 | 87 | |
88 | - return mt_rand( 1, 100 ) <= $percentage; |
|
88 | + return mt_rand(1, 100) <= $percentage; |
|
89 | 89 | } |
90 | 90 | |
91 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
92 | - if ( !( $change instanceof EntityChange ) || |
|
91 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
92 | + if (!($change instanceof EntityChange) || |
|
93 | 93 | $change->getAction() !== EntityChange::UPDATE || |
94 | - !( $change->getEntityId() instanceof PropertyId ) |
|
94 | + !($change->getEntityId() instanceof PropertyId) |
|
95 | 95 | ) { |
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
99 | 99 | $info = $change->getInfo(); |
100 | 100 | |
101 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
101 | + if (!array_key_exists('compactDiff', $info)) { |
|
102 | 102 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
103 | 103 | // so we only know that the change *might* affect the constraint statements |
104 | 104 | return true; |
@@ -107,43 +107,43 @@ discard block |
||
107 | 107 | /** @var EntityDiffChangedAspects $aspects */ |
108 | 108 | $aspects = $info['compactDiff']; |
109 | 109 | |
110 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
111 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
110 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
111 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
112 | 112 | } |
113 | 113 | |
114 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
114 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
115 | 115 | $entityContentFactory = WikibaseRepo::getEntityContentFactory(); |
116 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
116 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
117 | 117 | $entityIdLookup = WikibaseRepo::getEntityIdLookup(); |
118 | - $entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
119 | - if ( $entityId !== null ) { |
|
118 | + $entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle()); |
|
119 | + if ($entityId !== null) { |
|
120 | 120 | $resultsCache = ResultsCache::getDefaultInstance(); |
121 | - $resultsCache->delete( $entityId ); |
|
121 | + $resultsCache->delete($entityId); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
126 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
127 | 127 | $lookup = WikibaseRepo::getEntityNamespaceLookup(); |
128 | 128 | $title = $out->getTitle(); |
129 | - if ( $title === null ) { |
|
129 | + if ($title === null) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
133 | - if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) { |
|
133 | + if (!$lookup->isNamespaceWithEntities($title->getNamespace())) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
136 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | |
140 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
140 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
141 | 141 | |
142 | - if ( !$out->getUser()->isRegistered() ) { |
|
142 | + if (!$out->getUser()->isRegistered()) { |
|
143 | 143 | return; |
144 | 144 | } |
145 | 145 | |
146 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
146 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | } |
@@ -11,10 +11,10 @@ discard block |
||
11 | 11 | use Wikimedia\Rdbms\ILBFactory; |
12 | 12 | |
13 | 13 | // @codeCoverageIgnoreStart |
14 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
15 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
14 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
15 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
16 | 16 | |
17 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
17 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
18 | 18 | // @codeCoverageIgnoreEnd |
19 | 19 | |
20 | 20 | /** |
@@ -46,57 +46,57 @@ discard block |
||
46 | 46 | |
47 | 47 | public function __construct() { |
48 | 48 | parent::__construct(); |
49 | - $this->newUpdateConstraintsTableJob = function ( $propertyIdSerialization ) { |
|
49 | + $this->newUpdateConstraintsTableJob = function($propertyIdSerialization) { |
|
50 | 50 | return UpdateConstraintsTableJob::newFromGlobalState( |
51 | 51 | Title::newMainPage(), |
52 | - [ 'propertyId' => $propertyIdSerialization ] |
|
52 | + ['propertyId' => $propertyIdSerialization] |
|
53 | 53 | ); |
54 | 54 | }; |
55 | 55 | |
56 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
57 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
58 | - $this->setBatchSize( 10 ); |
|
56 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
57 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
58 | + $this->setBatchSize(10); |
|
59 | 59 | |
60 | 60 | // Wikibase classes are not yet loaded, so setup services in a callback run in execute |
61 | 61 | // that can be overridden in tests. |
62 | - $this->setupServices = function () { |
|
62 | + $this->setupServices = function() { |
|
63 | 63 | $services = MediaWikiServices::getInstance(); |
64 | - $this->propertyInfoLookup = WikibaseRepo::getStore( $services )->getPropertyInfoLookup(); |
|
64 | + $this->propertyInfoLookup = WikibaseRepo::getStore($services)->getPropertyInfoLookup(); |
|
65 | 65 | $this->lbFactory = $services->getDBLoadBalancerFactory(); |
66 | 66 | }; |
67 | 67 | } |
68 | 68 | |
69 | 69 | public function execute() { |
70 | - ( $this->setupServices )(); |
|
71 | - if ( !$this->getConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
72 | - $this->error( 'Constraint statements are not enabled. Aborting.' ); |
|
70 | + ($this->setupServices)(); |
|
71 | + if (!$this->getConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
72 | + $this->error('Constraint statements are not enabled. Aborting.'); |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | 76 | $propertyInfos = $this->propertyInfoLookup->getAllPropertyInfo(); |
77 | - $propertyIds = array_keys( $propertyInfos ); |
|
77 | + $propertyIds = array_keys($propertyInfos); |
|
78 | 78 | |
79 | - foreach ( array_chunk( $propertyIds, $this->getBatchSize() ) as $propertyIdsChunk ) { |
|
80 | - foreach ( $propertyIdsChunk as $propertyIdSerialization ) { |
|
81 | - $this->output( sprintf( |
|
79 | + foreach (array_chunk($propertyIds, $this->getBatchSize()) as $propertyIdsChunk) { |
|
80 | + foreach ($propertyIdsChunk as $propertyIdSerialization) { |
|
81 | + $this->output(sprintf( |
|
82 | 82 | 'Importing constraint statements for % 6s... ', |
83 | 83 | $propertyIdSerialization ), |
84 | 84 | $propertyIdSerialization |
85 | 85 | ); |
86 | - $startTime = microtime( true ); |
|
87 | - $job = call_user_func( $this->newUpdateConstraintsTableJob, $propertyIdSerialization ); |
|
86 | + $startTime = microtime(true); |
|
87 | + $job = call_user_func($this->newUpdateConstraintsTableJob, $propertyIdSerialization); |
|
88 | 88 | $job->run(); |
89 | - $endTime = microtime( true ); |
|
90 | - $millis = ( $endTime - $startTime ) * 1000; |
|
91 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
89 | + $endTime = microtime(true); |
|
90 | + $millis = ($endTime - $startTime) * 1000; |
|
91 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
92 | 92 | } |
93 | 93 | |
94 | - $this->output( 'Waiting for replication... ', 'waitForReplication' ); |
|
95 | - $startTime = microtime( true ); |
|
94 | + $this->output('Waiting for replication... ', 'waitForReplication'); |
|
95 | + $startTime = microtime(true); |
|
96 | 96 | $this->lbFactory->waitForReplication(); |
97 | - $endTime = microtime( true ); |
|
98 | - $millis = ( $endTime - $startTime ) * 1000; |
|
99 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), 'waitForReplication' ); |
|
97 | + $endTime = microtime(true); |
|
98 | + $millis = ($endTime - $startTime) * 1000; |
|
99 | + $this->output(sprintf('done in % 6.2f ms.', $millis), 'waitForReplication'); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | use Wikibase\Repo\WikibaseRepo; |
18 | 18 | |
19 | 19 | // @codeCoverageIgnoreStart |
20 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
21 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
20 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
21 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
22 | 22 | |
23 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
23 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
24 | 24 | // @codeCoverageIgnoreEnd |
25 | 25 | |
26 | 26 | /** |
@@ -59,20 +59,20 @@ discard block |
||
59 | 59 | parent::__construct(); |
60 | 60 | |
61 | 61 | $this->addDescription( |
62 | - 'Import entities needed for constraint checks ' . |
|
62 | + 'Import entities needed for constraint checks '. |
|
63 | 63 | 'from Wikidata into the local repository.' |
64 | 64 | ); |
65 | 65 | $this->addOption( |
66 | 66 | 'config-format', |
67 | - 'The format in which the resulting configuration will be omitted: ' . |
|
68 | - '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' . |
|
67 | + 'The format in which the resulting configuration will be omitted: '. |
|
68 | + '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '. |
|
69 | 69 | 'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.' |
70 | 70 | ); |
71 | 71 | $this->addOption( |
72 | 72 | 'dry-run', |
73 | 73 | 'Don’t actually import entities, just print which ones would be imported.' |
74 | 74 | ); |
75 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
75 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | */ |
81 | 81 | private function setupServices() { |
82 | 82 | $services = MediaWikiServices::getInstance(); |
83 | - $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer( $services ); |
|
84 | - $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer( $services ); |
|
85 | - $this->entityStore = WikibaseRepo::getEntityStore( $services ); |
|
83 | + $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer($services); |
|
84 | + $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer($services); |
|
85 | + $this->entityStore = WikibaseRepo::getEntityStore($services); |
|
86 | 86 | $this->httpRequestFactory = $services->getHttpRequestFactory(); |
87 | - if ( !$this->getOption( 'dry-run', false ) ) { |
|
88 | - $this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' ); |
|
87 | + if (!$this->getOption('dry-run', false)) { |
|
88 | + $this->user = User::newSystemUser('WikibaseQualityConstraints importer'); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -94,21 +94,21 @@ discard block |
||
94 | 94 | |
95 | 95 | $configUpdates = []; |
96 | 96 | |
97 | - $extensionJsonFile = __DIR__ . '/../extension.json'; |
|
98 | - $extensionJsonText = file_get_contents( $extensionJsonFile ); |
|
99 | - $extensionJson = json_decode( $extensionJsonText, /* assoc = */ true ); |
|
97 | + $extensionJsonFile = __DIR__.'/../extension.json'; |
|
98 | + $extensionJsonText = file_get_contents($extensionJsonFile); |
|
99 | + $extensionJson = json_decode($extensionJsonText, /* assoc = */ true); |
|
100 | 100 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
101 | - $wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() ); |
|
101 | + $wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig()); |
|
102 | 102 | |
103 | - foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) { |
|
104 | - $localEntityId = $this->importEntityFromWikidata( $wikidataEntityId ); |
|
103 | + foreach ($wikidataEntityIds as $key => $wikidataEntityId) { |
|
104 | + $localEntityId = $this->importEntityFromWikidata($wikidataEntityId); |
|
105 | 105 | $configUpdates[$key] = [ |
106 | 106 | 'wikidata' => $wikidataEntityId, |
107 | 107 | 'local' => $localEntityId, |
108 | 108 | ]; |
109 | 109 | } |
110 | 110 | |
111 | - $this->outputConfigUpdates( $configUpdates ); |
|
111 | + $this->outputConfigUpdates($configUpdates); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,18 +116,18 @@ discard block |
||
116 | 116 | * @param Config $wikiConfig |
117 | 117 | * @return string[] |
118 | 118 | */ |
119 | - private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) { |
|
119 | + private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) { |
|
120 | 120 | $wikidataEntityIds = []; |
121 | 121 | |
122 | - foreach ( $extensionJsonConfig as $key => $value ) { |
|
123 | - if ( !preg_match( '/Id$/', $key ) ) { |
|
122 | + foreach ($extensionJsonConfig as $key => $value) { |
|
123 | + if (!preg_match('/Id$/', $key)) { |
|
124 | 124 | continue; |
125 | 125 | } |
126 | 126 | |
127 | 127 | $wikidataEntityId = $value['value']; |
128 | - $localEntityId = $wikiConfig->get( $key ); |
|
128 | + $localEntityId = $wikiConfig->get($key); |
|
129 | 129 | |
130 | - if ( $localEntityId === $wikidataEntityId ) { |
|
130 | + if ($localEntityId === $wikidataEntityId) { |
|
131 | 131 | $wikidataEntityIds[$key] = $wikidataEntityId; |
132 | 132 | } |
133 | 133 | } |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | * @param string $wikidataEntityId |
140 | 140 | * @return string local entity ID |
141 | 141 | */ |
142 | - private function importEntityFromWikidata( $wikidataEntityId ) { |
|
142 | + private function importEntityFromWikidata($wikidataEntityId) { |
|
143 | 143 | $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json"; |
144 | - $wikidataEntitiesJson = $this->httpRequestFactory->get( $wikidataEntityUrl, [], __METHOD__ ); |
|
145 | - return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ); |
|
144 | + $wikidataEntitiesJson = $this->httpRequestFactory->get($wikidataEntityUrl, [], __METHOD__); |
|
145 | + return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -150,24 +150,24 @@ discard block |
||
150 | 150 | * @param string $wikidataEntitiesJson |
151 | 151 | * @return string local entity ID |
152 | 152 | */ |
153 | - private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) { |
|
153 | + private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) { |
|
154 | 154 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
155 | - $wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId]; |
|
156 | - $wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray ); |
|
155 | + $wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId]; |
|
156 | + $wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray); |
|
157 | 157 | |
158 | - $wikidataEntity->setId( null ); |
|
158 | + $wikidataEntity->setId(null); |
|
159 | 159 | |
160 | - if ( $wikidataEntity instanceof StatementListProvider ) { |
|
160 | + if ($wikidataEntity instanceof StatementListProvider) { |
|
161 | 161 | $wikidataEntity->getStatements()->clear(); |
162 | 162 | } |
163 | 163 | |
164 | - if ( $wikidataEntity instanceof Item ) { |
|
165 | - $wikidataEntity->setSiteLinkList( new SiteLinkList() ); |
|
164 | + if ($wikidataEntity instanceof Item) { |
|
165 | + $wikidataEntity->setSiteLinkList(new SiteLinkList()); |
|
166 | 166 | } |
167 | 167 | |
168 | - if ( $this->getOption( 'dry-run', false ) ) { |
|
169 | - $wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) ); |
|
170 | - $this->output( $wikidataEntityJson . "\n" ); |
|
168 | + if ($this->getOption('dry-run', false)) { |
|
169 | + $wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity)); |
|
170 | + $this->output($wikidataEntityJson."\n"); |
|
171 | 171 | return "-$wikidataEntityId"; |
172 | 172 | } |
173 | 173 | |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | )->getEntity(); |
181 | 181 | |
182 | 182 | return $localEntity->getId()->getSerialization(); |
183 | - } catch ( StorageException $storageException ) { |
|
184 | - return $this->storageExceptionToEntityId( $storageException ); |
|
183 | + } catch (StorageException $storageException) { |
|
184 | + return $this->storageExceptionToEntityId($storageException); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | - private function storageExceptionToEntityId( StorageException $storageException ) { |
|
188 | + private function storageExceptionToEntityId(StorageException $storageException) { |
|
189 | 189 | $message = $storageException->getMessage(); |
190 | 190 | // example messages: |
191 | 191 | // * Item [[Item:Q475|Q475]] already has label "as references" |
@@ -195,25 +195,25 @@ discard block |
||
195 | 195 | // * Property [[Property:P694|P694]] already has label "instance of" |
196 | 196 | // associated with language code en. |
197 | 197 | $pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/'; |
198 | - if ( preg_match( $pattern, $message, $matches ) ) { |
|
198 | + if (preg_match($pattern, $message, $matches)) { |
|
199 | 199 | return $matches[1]; |
200 | 200 | } else { |
201 | 201 | throw $storageException; |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - private function outputConfigUpdates( array $configUpdates ) { |
|
206 | - $configFormat = $this->getOption( 'config-format', 'globals' ); |
|
207 | - switch ( $configFormat ) { |
|
205 | + private function outputConfigUpdates(array $configUpdates) { |
|
206 | + $configFormat = $this->getOption('config-format', 'globals'); |
|
207 | + switch ($configFormat) { |
|
208 | 208 | case 'globals': |
209 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
209 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
210 | 210 | break; |
211 | 211 | case 'wgConf': |
212 | - $this->outputConfigUpdatesWgConf( $configUpdates ); |
|
212 | + $this->outputConfigUpdatesWgConf($configUpdates); |
|
213 | 213 | break; |
214 | 214 | default: |
215 | - $this->error( "Invalid config format \"$configFormat\", using \"globals\"" ); |
|
216 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
215 | + $this->error("Invalid config format \"$configFormat\", using \"globals\""); |
|
216 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
217 | 217 | break; |
218 | 218 | } |
219 | 219 | } |
@@ -221,22 +221,22 @@ discard block |
||
221 | 221 | /** |
222 | 222 | * @param array[] $configUpdates |
223 | 223 | */ |
224 | - private function outputConfigUpdatesGlobals( array $configUpdates ) { |
|
225 | - foreach ( $configUpdates as $key => $value ) { |
|
226 | - $localValueCode = var_export( $value['local'], true ); |
|
227 | - $this->output( "\$wg$key = $localValueCode;\n" ); |
|
224 | + private function outputConfigUpdatesGlobals(array $configUpdates) { |
|
225 | + foreach ($configUpdates as $key => $value) { |
|
226 | + $localValueCode = var_export($value['local'], true); |
|
227 | + $this->output("\$wg$key = $localValueCode;\n"); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
232 | 232 | * @param array[] $configUpdates |
233 | 233 | */ |
234 | - private function outputConfigUpdatesWgConf( array $configUpdates ) { |
|
235 | - foreach ( $configUpdates as $key => $value ) { |
|
236 | - $keyCode = var_export( "wg$key", true ); |
|
237 | - $wikidataValueCode = var_export( $value['wikidata'], true ); |
|
238 | - $localValueCode = var_export( $value['local'], true ); |
|
239 | - $wikiIdCode = var_export( wfWikiID(), true ); |
|
234 | + private function outputConfigUpdatesWgConf(array $configUpdates) { |
|
235 | + foreach ($configUpdates as $key => $value) { |
|
236 | + $keyCode = var_export("wg$key", true); |
|
237 | + $wikidataValueCode = var_export($value['wikidata'], true); |
|
238 | + $localValueCode = var_export($value['local'], true); |
|
239 | + $wikiIdCode = var_export(wfWikiID(), true); |
|
240 | 240 | $block = <<< EOF |
241 | 241 | $keyCode => [ |
242 | 242 | 'default' => $wikidataValueCode, |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | |
246 | 246 | |
247 | 247 | EOF; |
248 | - $this->output( $block ); |
|
248 | + $this->output($block); |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @codeCoverageIgnore This method is purely declarative. |
80 | 80 | */ |
81 | 81 | public function getDefaultContextTypes() { |
82 | - return [ Context::TYPE_STATEMENT ]; |
|
82 | + return [Context::TYPE_STATEMENT]; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -91,31 +91,31 @@ discard block |
||
91 | 91 | * @return CheckResult |
92 | 92 | * @throws \ConfigException |
93 | 93 | */ |
94 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
95 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
96 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
94 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
95 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
96 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
97 | 97 | } |
98 | 98 | $snak = $context->getSnak(); |
99 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
99 | + if (!$snak instanceof PropertyValueSnak) { |
|
100 | 100 | // nothing to check |
101 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
101 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $dataValue = $snak->getDataValue(); |
105 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
105 | + if (!$dataValue instanceof EntityIdValue) { |
|
106 | 106 | // wrong data type |
107 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
108 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
109 | - ->withDataValueType( 'wikibase-entityid' ); |
|
110 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
107 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
108 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
109 | + ->withDataValueType('wikibase-entityid'); |
|
110 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | $objectId = $dataValue->getEntityId(); |
114 | - $objectItem = $this->entityLookup->getEntity( $objectId ); |
|
115 | - if ( !( $objectItem instanceof StatementListProvider ) ) { |
|
114 | + $objectItem = $this->entityLookup->getEntity($objectId); |
|
115 | + if (!($objectItem instanceof StatementListProvider)) { |
|
116 | 116 | // object was deleted/doesn't exist |
117 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
118 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
117 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
118 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
119 | 119 | } |
120 | 120 | /** @var Statement[] $objectStatements */ |
121 | 121 | $objectStatements = $objectItem->getStatements()->toArray(); |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | $subjectId = $context->getEntity()->getId(); |
124 | 124 | $subjectStatements = $context->getEntity()->getStatements()->toArray(); |
125 | 125 | /** @var String[] $startPropertyIds */ |
126 | - $startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS ); |
|
126 | + $startPropertyIds = $this->config->get(self::CONFIG_VARIABLE_START_PROPERTY_IDS); |
|
127 | 127 | /** @var String[] $endPropertyIds */ |
128 | - $endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS ); |
|
128 | + $endPropertyIds = $this->config->get(self::CONFIG_VARIABLE_END_PROPERTY_IDS); |
|
129 | 129 | $subjectStartValue = $this->getExtremeValue( |
130 | 130 | $startPropertyIds, |
131 | 131 | $subjectStatements, |
@@ -147,15 +147,15 @@ discard block |
||
147 | 147 | 'end' |
148 | 148 | ); |
149 | 149 | if ( |
150 | - $this->rangeCheckerHelper->getComparison( $subjectStartValue, $subjectEndValue ) <= 0 && |
|
151 | - $this->rangeCheckerHelper->getComparison( $objectStartValue, $objectEndValue ) <= 0 && ( |
|
152 | - $this->rangeCheckerHelper->getComparison( $subjectEndValue, $objectStartValue ) < 0 || |
|
153 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectStartValue ) < 0 |
|
150 | + $this->rangeCheckerHelper->getComparison($subjectStartValue, $subjectEndValue) <= 0 && |
|
151 | + $this->rangeCheckerHelper->getComparison($objectStartValue, $objectEndValue) <= 0 && ( |
|
152 | + $this->rangeCheckerHelper->getComparison($subjectEndValue, $objectStartValue) < 0 || |
|
153 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectStartValue) < 0 |
|
154 | 154 | ) |
155 | 155 | ) { |
156 | 156 | if ( |
157 | 157 | $subjectEndValue == null || |
158 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectEndValue ) < 0 |
|
158 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectEndValue) < 0 |
|
159 | 159 | ) { |
160 | 160 | $earlierEntityId = $objectId; |
161 | 161 | $minEndValue = $objectEndValue; |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $message = null; |
179 | 179 | $status = CheckResult::STATUS_COMPLIANCE; |
180 | 180 | } |
181 | - return new CheckResult( $context, $constraint, [], $status, $message ); |
|
181 | + return new CheckResult($context, $constraint, [], $status, $message); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -188,19 +188,19 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @return DataValue|null |
190 | 190 | */ |
191 | - private function getExtremeValue( $extremePropertyIds, $statements, $startOrEnd ) { |
|
192 | - if ( $startOrEnd !== 'start' && $startOrEnd !== 'end' ) { |
|
193 | - throw new \InvalidArgumentException( '$startOrEnd must be \'start\' or \'end\'.' ); |
|
191 | + private function getExtremeValue($extremePropertyIds, $statements, $startOrEnd) { |
|
192 | + if ($startOrEnd !== 'start' && $startOrEnd !== 'end') { |
|
193 | + throw new \InvalidArgumentException('$startOrEnd must be \'start\' or \'end\'.'); |
|
194 | 194 | } |
195 | 195 | $extremeValue = null; |
196 | - foreach ( $extremePropertyIds as $extremePropertyId ) { |
|
197 | - $statementList = new StatementList( ...$statements ); |
|
198 | - $extremeStatements = $statementList->getByPropertyId( new PropertyId( $extremePropertyId ) ); |
|
196 | + foreach ($extremePropertyIds as $extremePropertyId) { |
|
197 | + $statementList = new StatementList(...$statements); |
|
198 | + $extremeStatements = $statementList->getByPropertyId(new PropertyId($extremePropertyId)); |
|
199 | 199 | /** @var Statement $extremeStatement */ |
200 | - foreach ( $extremeStatements as $extremeStatement ) { |
|
201 | - if ( $extremeStatement->getRank() !== Statement::RANK_DEPRECATED ) { |
|
200 | + foreach ($extremeStatements as $extremeStatement) { |
|
201 | + if ($extremeStatement->getRank() !== Statement::RANK_DEPRECATED) { |
|
202 | 202 | $snak = $extremeStatement->getMainSnak(); |
203 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
203 | + if (!$snak instanceof PropertyValueSnak) { |
|
204 | 204 | return null; |
205 | 205 | } else { |
206 | 206 | $comparison = $this->rangeCheckerHelper->getComparison( |
@@ -209,8 +209,8 @@ discard block |
||
209 | 209 | ); |
210 | 210 | if ( |
211 | 211 | $extremeValue === null || |
212 | - ( $startOrEnd === 'start' && $comparison < 0 ) || |
|
213 | - ( $startOrEnd === 'end' && $comparison > 0 ) |
|
212 | + ($startOrEnd === 'start' && $comparison < 0) || |
|
213 | + ($startOrEnd === 'end' && $comparison > 0) |
|
214 | 214 | ) { |
215 | 215 | $extremeValue = $snak->getDataValue(); |
216 | 216 | } |
@@ -240,17 +240,16 @@ discard block |
||
240 | 240 | DataValue $maxStartValue |
241 | 241 | ) { |
242 | 242 | $messageKey = $earlierEntityId === $subjectId ? |
243 | - 'wbqc-violation-message-contemporary-subject-earlier' : |
|
244 | - 'wbqc-violation-message-contemporary-value-earlier'; |
|
245 | - return ( new ViolationMessage( $messageKey ) ) |
|
246 | - ->withEntityId( $subjectId, Role::SUBJECT ) |
|
247 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
248 | - ->withEntityId( $objectId, Role::OBJECT ) |
|
249 | - ->withDataValue( $minEndValue, Role::OBJECT ) |
|
250 | - ->withDataValue( $maxStartValue, Role::OBJECT ); |
|
243 | + 'wbqc-violation-message-contemporary-subject-earlier' : 'wbqc-violation-message-contemporary-value-earlier'; |
|
244 | + return (new ViolationMessage($messageKey)) |
|
245 | + ->withEntityId($subjectId, Role::SUBJECT) |
|
246 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
247 | + ->withEntityId($objectId, Role::OBJECT) |
|
248 | + ->withDataValue($minEndValue, Role::OBJECT) |
|
249 | + ->withDataValue($maxStartValue, Role::OBJECT); |
|
251 | 250 | } |
252 | 251 | |
253 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
252 | + public function checkConstraintParameters(Constraint $constraint) { |
|
254 | 253 | // no parameters |
255 | 254 | return []; |
256 | 255 | } |
@@ -199,73 +199,73 @@ discard block |
||
199 | 199 | $this->defaultUserAgent = $defaultUserAgent; |
200 | 200 | $this->requestFactory = $requestFactory; |
201 | 201 | $this->entityPrefixes = []; |
202 | - foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) { |
|
203 | - $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName ); |
|
202 | + foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) { |
|
203 | + $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName); |
|
204 | 204 | } |
205 | 205 | |
206 | - $this->endpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
207 | - $this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
208 | - $this->instanceOfId = $config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
209 | - $this->subclassOfId = $config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
210 | - $this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
206 | + $this->endpoint = $config->get('WBQualityConstraintsSparqlEndpoint'); |
|
207 | + $this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
208 | + $this->instanceOfId = $config->get('WBQualityConstraintsInstanceOfId'); |
|
209 | + $this->subclassOfId = $config->get('WBQualityConstraintsSubclassOfId'); |
|
210 | + $this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
211 | 211 | $this->timeoutExceptionClasses = $config->get( |
212 | 212 | 'WBQualityConstraintsSparqlTimeoutExceptionClasses' |
213 | 213 | ); |
214 | 214 | $this->sparqlHasWikibaseSupport = $config->get( |
215 | 215 | 'WBQualityConstraintsSparqlHasWikibaseSupport' |
216 | 216 | ); |
217 | - $this->sparqlThrottlingFallbackDuration = (int)$config->get( |
|
217 | + $this->sparqlThrottlingFallbackDuration = (int) $config->get( |
|
218 | 218 | 'WBQualityConstraintsSparqlThrottlingFallbackDuration' |
219 | 219 | ); |
220 | 220 | |
221 | - $this->prefixes = $this->getQueryPrefixes( $rdfVocabulary ); |
|
221 | + $this->prefixes = $this->getQueryPrefixes($rdfVocabulary); |
|
222 | 222 | } |
223 | 223 | |
224 | - private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ) { |
|
224 | + private function getQueryPrefixes(RdfVocabulary $rdfVocabulary) { |
|
225 | 225 | // TODO: it would probably be smarter that RdfVocubulary exposed these prefixes somehow |
226 | 226 | $prefixes = ''; |
227 | - foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) { |
|
227 | + foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) { |
|
228 | 228 | $prefixes .= <<<END |
229 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
229 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
230 | 230 | END; |
231 | 231 | } |
232 | 232 | $prefixes .= <<<END |
233 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
234 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>\n |
|
233 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
234 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>\n |
|
235 | 235 | END; |
236 | 236 | |
237 | - foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) { |
|
237 | + foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) { |
|
238 | 238 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM]; |
239 | 239 | $prefixes .= <<<END |
240 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
240 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
241 | 241 | END; |
242 | 242 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM]; |
243 | 243 | $prefixes .= <<<END |
244 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
244 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
245 | 245 | END; |
246 | 246 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT]; |
247 | 247 | $prefixes .= <<<END |
248 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
248 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
249 | 249 | END; |
250 | 250 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER]; |
251 | 251 | $prefixes .= <<<END |
252 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
252 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
253 | 253 | END; |
254 | 254 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE]; |
255 | 255 | $prefixes .= <<<END |
256 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
256 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
257 | 257 | END; |
258 | 258 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE]; |
259 | 259 | $prefixes .= <<<END |
260 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
260 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
261 | 261 | END; |
262 | 262 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE]; |
263 | 263 | $prefixes .= <<<END |
264 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
264 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
265 | 265 | END; |
266 | 266 | } |
267 | 267 | $prefixes .= <<<END |
268 | -PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>\n |
|
268 | +PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>\n |
|
269 | 269 | END; |
270 | 270 | return $prefixes; |
271 | 271 | } |
@@ -277,21 +277,20 @@ discard block |
||
277 | 277 | * @return CachedBool |
278 | 278 | * @throws SparqlHelperException if the query times out or some other error occurs |
279 | 279 | */ |
280 | - public function hasType( $id, array $classes ) { |
|
280 | + public function hasType($id, array $classes) { |
|
281 | 281 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
282 | 282 | $gearingHint = $this->sparqlHasWikibaseSupport ? |
283 | - ' hint:Prior hint:gearing "forward".' : |
|
284 | - ''; |
|
283 | + ' hint:Prior hint:gearing "forward".' : ''; |
|
285 | 284 | |
286 | 285 | $metadatas = []; |
287 | 286 | |
288 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
289 | - $classesValues = implode( ' ', array_map( |
|
290 | - function ( $class ) { |
|
291 | - return 'wd:' . $class; |
|
287 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
288 | + $classesValues = implode(' ', array_map( |
|
289 | + function($class) { |
|
290 | + return 'wd:'.$class; |
|
292 | 291 | }, |
293 | 292 | $classesChunk |
294 | - ) ); |
|
293 | + )); |
|
295 | 294 | |
296 | 295 | $query = <<<EOF |
297 | 296 | ASK { |
@@ -301,19 +300,19 @@ discard block |
||
301 | 300 | } |
302 | 301 | EOF; |
303 | 302 | |
304 | - $result = $this->runQuery( $query ); |
|
303 | + $result = $this->runQuery($query); |
|
305 | 304 | $metadatas[] = $result->getMetadata(); |
306 | - if ( $result->getArray()['boolean'] ) { |
|
305 | + if ($result->getArray()['boolean']) { |
|
307 | 306 | return new CachedBool( |
308 | 307 | true, |
309 | - Metadata::merge( $metadatas ) |
|
308 | + Metadata::merge($metadatas) |
|
310 | 309 | ); |
311 | 310 | } |
312 | 311 | } |
313 | 312 | |
314 | 313 | return new CachedBool( |
315 | 314 | false, |
316 | - Metadata::merge( $metadatas ) |
|
315 | + Metadata::merge($metadatas) |
|
317 | 316 | ); |
318 | 317 | } |
319 | 318 | |
@@ -329,10 +328,10 @@ discard block |
||
329 | 328 | $ignoreDeprecatedStatements |
330 | 329 | ) { |
331 | 330 | $pid = $statement->getPropertyId()->serialize(); |
332 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
331 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
333 | 332 | |
334 | 333 | $deprecatedFilter = ''; |
335 | - if ( $ignoreDeprecatedStatements ) { |
|
334 | + if ($ignoreDeprecatedStatements) { |
|
336 | 335 | $deprecatedFilter = 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
337 | 336 | } |
338 | 337 | |
@@ -351,9 +350,9 @@ discard block |
||
351 | 350 | LIMIT 10 |
352 | 351 | EOF; |
353 | 352 | |
354 | - $result = $this->runQuery( $query ); |
|
353 | + $result = $this->runQuery($query); |
|
355 | 354 | |
356 | - return $this->getOtherEntities( $result ); |
|
355 | + return $this->getOtherEntities($result); |
|
357 | 356 | } |
358 | 357 | |
359 | 358 | /** |
@@ -378,16 +377,15 @@ discard block |
||
378 | 377 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
379 | 378 | $snak->getPropertyId() |
380 | 379 | ); |
381 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
382 | - if ( $isFullValue ) { |
|
380 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
381 | + if ($isFullValue) { |
|
383 | 382 | $prefix .= 'v'; |
384 | 383 | } |
385 | 384 | $path = $type === Context::TYPE_QUALIFIER ? |
386 | - "$prefix:$pid" : |
|
387 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
385 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
388 | 386 | |
389 | 387 | $deprecatedFilter = ''; |
390 | - if ( $ignoreDeprecatedStatements ) { |
|
388 | + if ($ignoreDeprecatedStatements) { |
|
391 | 389 | $deprecatedFilter = <<< EOF |
392 | 390 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
393 | 391 | EOF; |
@@ -407,9 +405,9 @@ discard block |
||
407 | 405 | LIMIT 10 |
408 | 406 | EOF; |
409 | 407 | |
410 | - $result = $this->runQuery( $query ); |
|
408 | + $result = $this->runQuery($query); |
|
411 | 409 | |
412 | - return $this->getOtherEntities( $result ); |
|
410 | + return $this->getOtherEntities($result); |
|
413 | 411 | } |
414 | 412 | |
415 | 413 | /** |
@@ -419,8 +417,8 @@ discard block |
||
419 | 417 | * |
420 | 418 | * @return string |
421 | 419 | */ |
422 | - private function stringLiteral( $text ) { |
|
423 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
420 | + private function stringLiteral($text) { |
|
421 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
424 | 422 | } |
425 | 423 | |
426 | 424 | /** |
@@ -430,18 +428,18 @@ discard block |
||
430 | 428 | * |
431 | 429 | * @return CachedEntityIds |
432 | 430 | */ |
433 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
434 | - return new CachedEntityIds( array_map( |
|
435 | - function ( $resultBindings ) { |
|
431 | + private function getOtherEntities(CachedQueryResults $results) { |
|
432 | + return new CachedEntityIds(array_map( |
|
433 | + function($resultBindings) { |
|
436 | 434 | $entityIRI = $resultBindings['otherEntity']['value']; |
437 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
438 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
439 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
435 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
436 | + $entityPrefixLength = strlen($entityPrefix); |
|
437 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
440 | 438 | try { |
441 | 439 | return $this->entityIdParser->parse( |
442 | - substr( $entityIRI, $entityPrefixLength ) |
|
440 | + substr($entityIRI, $entityPrefixLength) |
|
443 | 441 | ); |
444 | - } catch ( EntityIdParsingException $e ) { |
|
442 | + } catch (EntityIdParsingException $e) { |
|
445 | 443 | // fall through |
446 | 444 | } |
447 | 445 | } |
@@ -452,7 +450,7 @@ discard block |
||
452 | 450 | return null; |
453 | 451 | }, |
454 | 452 | $results->getArray()['results']['bindings'] |
455 | - ), $results->getMetadata() ); |
|
453 | + ), $results->getMetadata()); |
|
456 | 454 | } |
457 | 455 | |
458 | 456 | // phpcs:disable Generic.Metrics.CyclomaticComplexity,Squiz.WhiteSpace.FunctionSpacing |
@@ -465,50 +463,50 @@ discard block |
||
465 | 463 | * @return array the literal or IRI as a string in SPARQL syntax, |
466 | 464 | * and a boolean indicating whether it refers to a full value node or not |
467 | 465 | */ |
468 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
469 | - switch ( $dataType ) { |
|
466 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
467 | + switch ($dataType) { |
|
470 | 468 | case 'string': |
471 | 469 | case 'external-id': |
472 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
470 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
473 | 471 | case 'commonsMedia': |
474 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
475 | - return [ '<' . $url . '>', false ]; |
|
472 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
473 | + return ['<'.$url.'>', false]; |
|
476 | 474 | case 'geo-shape': |
477 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
478 | - return [ '<' . $url . '>', false ]; |
|
475 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
476 | + return ['<'.$url.'>', false]; |
|
479 | 477 | case 'tabular-data': |
480 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
481 | - return [ '<' . $url . '>', false ]; |
|
478 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
479 | + return ['<'.$url.'>', false]; |
|
482 | 480 | case 'url': |
483 | 481 | $url = $dataValue->getValue(); |
484 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
482 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
485 | 483 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
486 | 484 | // such an URL should never reach us, so just throw |
487 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
485 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
488 | 486 | } |
489 | - return [ '<' . $url . '>', false ]; |
|
487 | + return ['<'.$url.'>', false]; |
|
490 | 488 | case 'wikibase-item': |
491 | 489 | case 'wikibase-property': |
492 | 490 | /** @var EntityIdValue $dataValue */ |
493 | 491 | '@phan-var EntityIdValue $dataValue'; |
494 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
492 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
495 | 493 | case 'monolingualtext': |
496 | 494 | /** @var MonolingualTextValue $dataValue */ |
497 | 495 | '@phan-var MonolingualTextValue $dataValue'; |
498 | 496 | $lang = $dataValue->getLanguageCode(); |
499 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
497 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
500 | 498 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
501 | 499 | // such a language tag should never reach us, so just throw |
502 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
500 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
503 | 501 | } |
504 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
502 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
505 | 503 | case 'globe-coordinate': |
506 | 504 | case 'quantity': |
507 | 505 | case 'time': |
508 | 506 | // @phan-suppress-next-line PhanUndeclaredMethod |
509 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
507 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
510 | 508 | default: |
511 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
509 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
512 | 510 | } |
513 | 511 | } |
514 | 512 | // phpcs:enable |
@@ -521,43 +519,43 @@ discard block |
||
521 | 519 | * @throws SparqlHelperException if the query times out or some other error occurs |
522 | 520 | * @throws ConstraintParameterException if the $regex is invalid |
523 | 521 | */ |
524 | - public function matchesRegularExpression( $text, $regex ) { |
|
522 | + public function matchesRegularExpression($text, $regex) { |
|
525 | 523 | // caching wrapper around matchesRegularExpressionWithSparql |
526 | 524 | |
527 | - $textHash = hash( 'sha256', $text ); |
|
525 | + $textHash = hash('sha256', $text); |
|
528 | 526 | $cacheKey = $this->cache->makeKey( |
529 | 527 | 'WikibaseQualityConstraints', // extension |
530 | 528 | 'regex', // action |
531 | 529 | 'WDQS-Java', // regex flavor |
532 | - hash( 'sha256', $regex ) |
|
530 | + hash('sha256', $regex) |
|
533 | 531 | ); |
534 | 532 | |
535 | 533 | $cacheMapArray = $this->cache->getWithSetCallback( |
536 | 534 | $cacheKey, |
537 | 535 | WANObjectCache::TTL_DAY, |
538 | - function ( $cacheMapArray ) use ( $text, $regex, $textHash ) { |
|
536 | + function($cacheMapArray) use ($text, $regex, $textHash) { |
|
539 | 537 | // Initialize the cache map if not set |
540 | - if ( $cacheMapArray === false ) { |
|
538 | + if ($cacheMapArray === false) { |
|
541 | 539 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
542 | - $this->dataFactory->increment( $key ); |
|
540 | + $this->dataFactory->increment($key); |
|
543 | 541 | return []; |
544 | 542 | } |
545 | 543 | |
546 | 544 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
547 | - $this->dataFactory->increment( $key ); |
|
548 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize ); |
|
549 | - if ( $cacheMap->has( $textHash ) ) { |
|
545 | + $this->dataFactory->increment($key); |
|
546 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize); |
|
547 | + if ($cacheMap->has($textHash)) { |
|
550 | 548 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
551 | - $this->dataFactory->increment( $key ); |
|
552 | - $cacheMap->get( $textHash ); // ping cache |
|
549 | + $this->dataFactory->increment($key); |
|
550 | + $cacheMap->get($textHash); // ping cache |
|
553 | 551 | } else { |
554 | 552 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
555 | - $this->dataFactory->increment( $key ); |
|
553 | + $this->dataFactory->increment($key); |
|
556 | 554 | try { |
557 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
558 | - } catch ( ConstraintParameterException $e ) { |
|
559 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
560 | - } catch ( SparqlHelperException $e ) { |
|
555 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
556 | + } catch (ConstraintParameterException $e) { |
|
557 | + $matches = $this->serializeConstraintParameterException($e); |
|
558 | + } catch (SparqlHelperException $e) { |
|
561 | 559 | // don’t cache this |
562 | 560 | return $cacheMap->toArray(); |
563 | 561 | } |
@@ -581,42 +579,42 @@ discard block |
||
581 | 579 | ] |
582 | 580 | ); |
583 | 581 | |
584 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
582 | + if (isset($cacheMapArray[$textHash])) { |
|
585 | 583 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
586 | - $this->dataFactory->increment( $key ); |
|
584 | + $this->dataFactory->increment($key); |
|
587 | 585 | $matches = $cacheMapArray[$textHash]; |
588 | - if ( is_bool( $matches ) ) { |
|
586 | + if (is_bool($matches)) { |
|
589 | 587 | return $matches; |
590 | - } elseif ( is_array( $matches ) && |
|
591 | - $matches['type'] == ConstraintParameterException::class ) { |
|
592 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
588 | + } elseif (is_array($matches) && |
|
589 | + $matches['type'] == ConstraintParameterException::class) { |
|
590 | + throw $this->deserializeConstraintParameterException($matches); |
|
593 | 591 | } else { |
594 | 592 | throw new MWException( |
595 | - 'Value of unknown type in object cache (' . |
|
596 | - 'cache key: ' . $cacheKey . ', ' . |
|
597 | - 'cache map key: ' . $textHash . ', ' . |
|
598 | - 'value type: ' . gettype( $matches ) . ')' |
|
593 | + 'Value of unknown type in object cache ('. |
|
594 | + 'cache key: '.$cacheKey.', '. |
|
595 | + 'cache map key: '.$textHash.', '. |
|
596 | + 'value type: '.gettype($matches).')' |
|
599 | 597 | ); |
600 | 598 | } |
601 | 599 | } else { |
602 | 600 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
603 | - $this->dataFactory->increment( $key ); |
|
604 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
601 | + $this->dataFactory->increment($key); |
|
602 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
605 | 603 | } |
606 | 604 | } |
607 | 605 | |
608 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
606 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
609 | 607 | return [ |
610 | 608 | 'type' => ConstraintParameterException::class, |
611 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
609 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
612 | 610 | ]; |
613 | 611 | } |
614 | 612 | |
615 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
613 | + private function deserializeConstraintParameterException(array $serialization) { |
|
616 | 614 | $message = $this->violationMessageDeserializer->deserialize( |
617 | 615 | $serialization['violationMessage'] |
618 | 616 | ); |
619 | - return new ConstraintParameterException( $message ); |
|
617 | + return new ConstraintParameterException($message); |
|
620 | 618 | } |
621 | 619 | |
622 | 620 | /** |
@@ -630,25 +628,25 @@ discard block |
||
630 | 628 | * @throws SparqlHelperException if the query times out or some other error occurs |
631 | 629 | * @throws ConstraintParameterException if the $regex is invalid |
632 | 630 | */ |
633 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
634 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
635 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
631 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
632 | + $textStringLiteral = $this->stringLiteral($text); |
|
633 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
636 | 634 | |
637 | 635 | $query = <<<EOF |
638 | 636 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
639 | 637 | EOF; |
640 | 638 | |
641 | - $result = $this->runQuery( $query, false ); |
|
639 | + $result = $this->runQuery($query, false); |
|
642 | 640 | |
643 | 641 | $vars = $result->getArray()['results']['bindings'][0]; |
644 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
642 | + if (array_key_exists('matches', $vars)) { |
|
645 | 643 | // true or false ⇒ regex okay, text matches or not |
646 | 644 | return $vars['matches']['value'] === 'true'; |
647 | 645 | } else { |
648 | 646 | // empty result: regex broken |
649 | 647 | throw new ConstraintParameterException( |
650 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
651 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
648 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
649 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
652 | 650 | ); |
653 | 651 | } |
654 | 652 | } |
@@ -660,14 +658,14 @@ discard block |
||
660 | 658 | * |
661 | 659 | * @return boolean |
662 | 660 | */ |
663 | - public function isTimeout( $responseContent ) { |
|
664 | - $timeoutRegex = implode( '|', array_map( |
|
665 | - function ( $fqn ) { |
|
666 | - return preg_quote( $fqn, '/' ); |
|
661 | + public function isTimeout($responseContent) { |
|
662 | + $timeoutRegex = implode('|', array_map( |
|
663 | + function($fqn) { |
|
664 | + return preg_quote($fqn, '/'); |
|
667 | 665 | }, |
668 | 666 | $this->timeoutExceptionClasses |
669 | - ) ); |
|
670 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
667 | + )); |
|
668 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
671 | 669 | } |
672 | 670 | |
673 | 671 | /** |
@@ -679,17 +677,17 @@ discard block |
||
679 | 677 | * @return int|boolean the max-age (in seconds) |
680 | 678 | * or a plain boolean if no max-age can be determined |
681 | 679 | */ |
682 | - public function getCacheMaxAge( $responseHeaders ) { |
|
680 | + public function getCacheMaxAge($responseHeaders) { |
|
683 | 681 | if ( |
684 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
685 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
682 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
683 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
686 | 684 | ) { |
687 | 685 | $maxage = []; |
688 | 686 | if ( |
689 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
690 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
687 | + array_key_exists('cache-control', $responseHeaders) && |
|
688 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
691 | 689 | ) { |
692 | - return intval( $maxage[1] ); |
|
690 | + return intval($maxage[1]); |
|
693 | 691 | } else { |
694 | 692 | return true; |
695 | 693 | } |
@@ -710,34 +708,34 @@ discard block |
||
710 | 708 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
711 | 709 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
712 | 710 | */ |
713 | - public function getThrottling( MWHttpRequest $request ) { |
|
714 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
715 | - if ( $retryAfterValue === null ) { |
|
711 | + public function getThrottling(MWHttpRequest $request) { |
|
712 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
713 | + if ($retryAfterValue === null) { |
|
716 | 714 | return self::NO_RETRY_AFTER; |
717 | 715 | } |
718 | 716 | |
719 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
720 | - if ( empty( $trimmedRetryAfterValue ) ) { |
|
717 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
718 | + if (empty($trimmedRetryAfterValue)) { |
|
721 | 719 | return self::EMPTY_RETRY_AFTER; |
722 | 720 | } |
723 | 721 | |
724 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
725 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
726 | - if ( $delaySeconds >= 0 ) { |
|
727 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
722 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
723 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
724 | + if ($delaySeconds >= 0) { |
|
725 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
728 | 726 | } |
729 | 727 | } else { |
730 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
731 | - if ( !empty( $return ) ) { |
|
732 | - return new ConvertibleTimestamp( $return ); |
|
728 | + $return = strtotime($trimmedRetryAfterValue); |
|
729 | + if (!empty($return)) { |
|
730 | + return new ConvertibleTimestamp($return); |
|
733 | 731 | } |
734 | 732 | } |
735 | 733 | return self::INVALID_RETRY_AFTER; |
736 | 734 | } |
737 | 735 | |
738 | - private function getTimestampInFuture( DateInterval $delta ) { |
|
736 | + private function getTimestampInFuture(DateInterval $delta) { |
|
739 | 737 | $now = new ConvertibleTimestamp(); |
740 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
738 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
741 | 739 | } |
742 | 740 | |
743 | 741 | /** |
@@ -751,65 +749,64 @@ discard block |
||
751 | 749 | * |
752 | 750 | * @throws SparqlHelperException if the query times out or some other error occurs |
753 | 751 | */ |
754 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
752 | + public function runQuery($query, $needsPrefixes = true) { |
|
755 | 753 | |
756 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
757 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
754 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
755 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
758 | 756 | throw new TooManySparqlRequestsException(); |
759 | 757 | } |
760 | 758 | |
761 | - if ( $this->sparqlHasWikibaseSupport ) { |
|
759 | + if ($this->sparqlHasWikibaseSupport) { |
|
762 | 760 | $needsPrefixes = false; |
763 | 761 | } |
764 | 762 | |
765 | - if ( $needsPrefixes ) { |
|
766 | - $query = $this->prefixes . $query; |
|
763 | + if ($needsPrefixes) { |
|
764 | + $query = $this->prefixes.$query; |
|
767 | 765 | } |
768 | - $query = "#wbqc\n" . $query; |
|
766 | + $query = "#wbqc\n".$query; |
|
769 | 767 | |
770 | - $url = $this->endpoint . '?' . http_build_query( |
|
768 | + $url = $this->endpoint.'?'.http_build_query( |
|
771 | 769 | [ |
772 | 770 | 'query' => $query, |
773 | 771 | 'format' => 'json', |
774 | 772 | 'maxQueryTimeMillis' => $this->maxQueryTimeMillis, |
775 | 773 | ], |
776 | - null, ini_get( 'arg_separator.output' ), |
|
774 | + null, ini_get('arg_separator.output'), |
|
777 | 775 | // encode spaces with %20, not + |
778 | 776 | PHP_QUERY_RFC3986 |
779 | 777 | ); |
780 | 778 | |
781 | 779 | $options = [ |
782 | 780 | 'method' => 'GET', |
783 | - 'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ), |
|
781 | + 'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000), |
|
784 | 782 | 'connectTimeout' => 'default', |
785 | 783 | 'userAgent' => $this->defaultUserAgent, |
786 | 784 | ]; |
787 | - $request = $this->requestFactory->create( $url, $options, __METHOD__ ); |
|
788 | - $startTime = microtime( true ); |
|
785 | + $request = $this->requestFactory->create($url, $options, __METHOD__); |
|
786 | + $startTime = microtime(true); |
|
789 | 787 | $requestStatus = $request->execute(); |
790 | - $endTime = microtime( true ); |
|
788 | + $endTime = microtime(true); |
|
791 | 789 | $this->dataFactory->timing( |
792 | 790 | 'wikibase.quality.constraints.sparql.timing', |
793 | - ( $endTime - $startTime ) * 1000 |
|
791 | + ($endTime - $startTime) * 1000 |
|
794 | 792 | ); |
795 | 793 | |
796 | - $this->guardAgainstTooManyRequestsError( $request ); |
|
794 | + $this->guardAgainstTooManyRequestsError($request); |
|
797 | 795 | |
798 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
799 | - if ( $maxAge ) { |
|
800 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
796 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
797 | + if ($maxAge) { |
|
798 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
801 | 799 | } |
802 | 800 | |
803 | - if ( $requestStatus->isOK() ) { |
|
801 | + if ($requestStatus->isOK()) { |
|
804 | 802 | $json = $request->getContent(); |
805 | - $jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
|
806 | - if ( $jsonStatus->isOK() ) { |
|
803 | + $jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC); |
|
804 | + if ($jsonStatus->isOK()) { |
|
807 | 805 | return new CachedQueryResults( |
808 | 806 | $jsonStatus->getValue(), |
809 | 807 | Metadata::ofCachingMetadata( |
810 | 808 | $maxAge ? |
811 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
812 | - CachingMetadata::fresh() |
|
809 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
813 | 810 | ) |
814 | 811 | ); |
815 | 812 | } else { |
@@ -826,9 +823,9 @@ discard block |
||
826 | 823 | // fall through to general error handling |
827 | 824 | } |
828 | 825 | |
829 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
826 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
830 | 827 | |
831 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
828 | + if ($this->isTimeout($request->getContent())) { |
|
832 | 829 | $this->dataFactory->increment( |
833 | 830 | 'wikibase.quality.constraints.sparql.error.timeout' |
834 | 831 | ); |
@@ -843,29 +840,29 @@ discard block |
||
843 | 840 | * @param MWHttpRequest $request |
844 | 841 | * @throws TooManySparqlRequestsException |
845 | 842 | */ |
846 | - private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void { |
|
847 | - if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) { |
|
843 | + private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void { |
|
844 | + if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) { |
|
848 | 845 | return; |
849 | 846 | } |
850 | 847 | |
851 | 848 | $fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration; |
852 | 849 | |
853 | - if ( $fallbackBlockDuration < 0 ) { |
|
854 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' . |
|
855 | - $fallbackBlockDuration ); |
|
850 | + if ($fallbackBlockDuration < 0) { |
|
851 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
852 | + $fallbackBlockDuration); |
|
856 | 853 | } |
857 | 854 | |
858 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
859 | - $throttlingUntil = $this->getThrottling( $request ); |
|
860 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
861 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
855 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
856 | + $throttlingUntil = $this->getThrottling($request); |
|
857 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
858 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
862 | 859 | $this->throttlingLock->lock( |
863 | 860 | self::EXPIRY_LOCK_ID, |
864 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
861 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
865 | 862 | ); |
866 | 863 | } else { |
867 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
868 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
864 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
865 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
869 | 866 | } |
870 | 867 | throw new TooManySparqlRequestsException(); |
871 | 868 | } |