@@ -81,28 +81,28 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return self |
83 | 83 | */ |
84 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
84 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
85 | 85 | $repo = WikibaseRepo::getDefaultInstance(); |
86 | 86 | |
87 | 87 | $language = $repo->getUserLanguage(); |
88 | 88 | $formatterOptions = new FormatterOptions(); |
89 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
89 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
90 | 90 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
91 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
91 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
92 | 92 | |
93 | 93 | $languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory(); |
94 | - $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language ); |
|
94 | + $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language); |
|
95 | 95 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
96 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
96 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
97 | 97 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
98 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
98 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
99 | 99 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
100 | 100 | $titleParser = MediaWikiServices::getInstance()->getTitleParser(); |
101 | 101 | $unitConverter = $repo->getUnitConverter(); |
102 | 102 | $dataFactory = MediaWikiServices::getInstance()->getStatsdDataFactory(); |
103 | 103 | $loggingHelper = new LoggingHelper( |
104 | 104 | $dataFactory, |
105 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
105 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
106 | 106 | $config |
107 | 107 | ); |
108 | 108 | $constraintParameterRenderer = new ConstraintParameterRenderer( |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | $repo->getEntityTitleLookup(), |
139 | 139 | $entityIdLabelFormatter, |
140 | 140 | $constraintParameterRenderer, |
141 | - new MultilingualTextViolationMessageRenderer( $entityIdHtmlLinkFormatter, $valueFormatter, $config ), |
|
141 | + new MultilingualTextViolationMessageRenderer($entityIdHtmlLinkFormatter, $valueFormatter, $config), |
|
142 | 142 | $config |
143 | 143 | ); |
144 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
144 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
145 | 145 | $wikiPageEntityMetaDataAccessor = new WikiPageEntityMetaDataLookup( |
146 | 146 | $repo->getEntityNamespaceLookup() |
147 | 147 | ); |
@@ -152,14 +152,14 @@ discard block |
||
152 | 152 | ResultsCache::getDefaultInstance(), |
153 | 153 | $wikiPageEntityMetaDataAccessor, |
154 | 154 | $entityIdParser, |
155 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
155 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
156 | 156 | [ |
157 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
158 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
159 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
160 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
157 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
158 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
159 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
160 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
161 | 161 | ], |
162 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
162 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
163 | 163 | $loggingHelper |
164 | 164 | ); |
165 | 165 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $prefix, |
171 | 171 | $repo->getEntityIdParser(), |
172 | 172 | $repo->getStatementGuidValidator(), |
173 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
173 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
174 | 174 | $resultsBuilder, |
175 | 175 | $dataFactory |
176 | 176 | ); |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | ResultsBuilder $resultsBuilder, |
197 | 197 | IBufferingStatsdDataFactory $dataFactory |
198 | 198 | ) { |
199 | - parent::__construct( $main, $name, $prefix ); |
|
199 | + parent::__construct($main, $name, $prefix); |
|
200 | 200 | $this->entityIdParser = $entityIdParser; |
201 | 201 | $this->statementGuidValidator = $statementGuidValidator; |
202 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
203 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
202 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
203 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
204 | 204 | $this->resultsBuilder = $resultsBuilder; |
205 | 205 | $this->dataFactory = $dataFactory; |
206 | 206 | } |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | |
216 | 216 | $params = $this->extractRequestParams(); |
217 | 217 | |
218 | - $this->validateParameters( $params ); |
|
219 | - $entityIds = $this->parseEntityIds( $params ); |
|
220 | - $claimIds = $this->parseClaimIds( $params ); |
|
218 | + $this->validateParameters($params); |
|
219 | + $entityIds = $this->parseEntityIds($params); |
|
220 | + $claimIds = $this->parseClaimIds($params); |
|
221 | 221 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
222 | 222 | $statuses = $params[self::PARAM_STATUS]; |
223 | 223 | |
@@ -232,13 +232,13 @@ discard block |
||
232 | 232 | )->getArray() |
233 | 233 | ); |
234 | 234 | // ensure that result contains the given entity IDs even if they have no statements |
235 | - foreach ( $entityIds as $entityId ) { |
|
235 | + foreach ($entityIds as $entityId) { |
|
236 | 236 | $this->getResult()->addArrayType( |
237 | - [ $this->getModuleName(), $entityId->getSerialization() ], |
|
237 | + [$this->getModuleName(), $entityId->getSerialization()], |
|
238 | 238 | 'assoc' |
239 | 239 | ); |
240 | 240 | } |
241 | - $this->resultBuilder->markSuccess( 1 ); |
|
241 | + $this->resultBuilder->markSuccess(1); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -246,24 +246,24 @@ discard block |
||
246 | 246 | * |
247 | 247 | * @return EntityId[] |
248 | 248 | */ |
249 | - private function parseEntityIds( array $params ) { |
|
249 | + private function parseEntityIds(array $params) { |
|
250 | 250 | $ids = $params[self::PARAM_ID]; |
251 | 251 | |
252 | - if ( $ids === null ) { |
|
252 | + if ($ids === null) { |
|
253 | 253 | return []; |
254 | - } elseif ( $ids === [] ) { |
|
254 | + } elseif ($ids === []) { |
|
255 | 255 | $this->errorReporter->dieError( |
256 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
256 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
257 | 257 | } |
258 | 258 | |
259 | - return array_map( function ( $id ) { |
|
259 | + return array_map(function($id) { |
|
260 | 260 | try { |
261 | - return $this->entityIdParser->parse( $id ); |
|
262 | - } catch ( EntityIdParsingException $e ) { |
|
261 | + return $this->entityIdParser->parse($id); |
|
262 | + } catch (EntityIdParsingException $e) { |
|
263 | 263 | $this->errorReporter->dieError( |
264 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
264 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
265 | 265 | } |
266 | - }, $ids ); |
|
266 | + }, $ids); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -271,35 +271,35 @@ discard block |
||
271 | 271 | * |
272 | 272 | * @return string[] |
273 | 273 | */ |
274 | - private function parseClaimIds( array $params ) { |
|
274 | + private function parseClaimIds(array $params) { |
|
275 | 275 | $ids = $params[self::PARAM_CLAIM_ID]; |
276 | 276 | |
277 | - if ( $ids === null ) { |
|
277 | + if ($ids === null) { |
|
278 | 278 | return []; |
279 | - } elseif ( $ids === [] ) { |
|
279 | + } elseif ($ids === []) { |
|
280 | 280 | $this->errorReporter->dieError( |
281 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
281 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
282 | 282 | } |
283 | 283 | |
284 | - foreach ( $ids as $id ) { |
|
285 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
284 | + foreach ($ids as $id) { |
|
285 | + if (!$this->statementGuidValidator->validate($id)) { |
|
286 | 286 | $this->errorReporter->dieError( |
287 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
287 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | |
291 | 291 | return $ids; |
292 | 292 | } |
293 | 293 | |
294 | - private function validateParameters( array $params ) { |
|
295 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
296 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
294 | + private function validateParameters(array $params) { |
|
295 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
296 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
297 | 297 | ) { |
298 | 298 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
299 | 299 | $this->errorReporter->dieError( |
300 | 300 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
301 | 301 | } |
302 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
302 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
303 | 303 | $paramId = self::PARAM_ID; |
304 | 304 | $paramClaimId = self::PARAM_CLAIM_ID; |
305 | 305 | $this->errorReporter->dieError( |
@@ -340,11 +340,11 @@ discard block |
||
340 | 340 | ], |
341 | 341 | ApiBase::PARAM_ISMULTI => true, |
342 | 342 | ApiBase::PARAM_ALL => true, |
343 | - ApiBase::PARAM_DFLT => implode( '|', [ |
|
343 | + ApiBase::PARAM_DFLT => implode('|', [ |
|
344 | 344 | CheckResult::STATUS_VIOLATION, |
345 | 345 | CheckResult::STATUS_WARNING, |
346 | 346 | CheckResult::STATUS_BAD_PARAMETERS, |
347 | - ] ), |
|
347 | + ]), |
|
348 | 348 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
349 | 349 | ], |
350 | 350 | ]; |
@@ -151,28 +151,28 @@ discard block |
||
151 | 151 | ) { |
152 | 152 | $results = []; |
153 | 153 | $metadatas = []; |
154 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
154 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
155 | 155 | $storedEntityIds = []; |
156 | - foreach ( $entityIds as $entityId ) { |
|
157 | - $storedResults = $this->getStoredResults( $entityId ); |
|
158 | - if ( $storedResults !== null ) { |
|
159 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
156 | + foreach ($entityIds as $entityId) { |
|
157 | + $storedResults = $this->getStoredResults($entityId); |
|
158 | + if ($storedResults !== null) { |
|
159 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
160 | 160 | $results += $storedResults->getArray(); |
161 | 161 | $metadatas[] = $storedResults->getMetadata(); |
162 | 162 | $storedEntityIds[] = $entityId; |
163 | 163 | } |
164 | 164 | } |
165 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
165 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
166 | 166 | } |
167 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
168 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
169 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
167 | + if ($entityIds !== [] || $claimIds !== []) { |
|
168 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
169 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
170 | 170 | $results += $response->getArray(); |
171 | 171 | $metadatas[] = $response->getMetadata(); |
172 | 172 | } |
173 | 173 | return new CachedCheckConstraintsResponse( |
174 | 174 | $results, |
175 | - Metadata::merge( $metadatas ) |
|
175 | + Metadata::merge($metadatas) |
|
176 | 176 | ); |
177 | 177 | } |
178 | 178 | |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | array $constraintIds = null, |
202 | 202 | array $statuses |
203 | 203 | ) { |
204 | - if ( $claimIds !== [] ) { |
|
204 | + if ($claimIds !== []) { |
|
205 | 205 | return false; |
206 | 206 | } |
207 | - if ( $constraintIds !== null ) { |
|
207 | + if ($constraintIds !== null) { |
|
208 | 208 | return false; |
209 | 209 | } |
210 | - if ( $statuses != $this->cachedStatuses ) { |
|
210 | + if ($statuses != $this->cachedStatuses) { |
|
211 | 211 | return false; |
212 | 212 | } |
213 | 213 | return true; |
@@ -226,14 +226,14 @@ discard block |
||
226 | 226 | array $constraintIds = null, |
227 | 227 | array $statuses |
228 | 228 | ) { |
229 | - $results = $this->resultsBuilder->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
229 | + $results = $this->resultsBuilder->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
230 | 230 | |
231 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
232 | - foreach ( $entityIds as $entityId ) { |
|
231 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
232 | + foreach ($entityIds as $entityId) { |
|
233 | 233 | $latestRevisionIds = $this->getLatestRevisionIds( |
234 | 234 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
235 | 235 | ); |
236 | - if ( $latestRevisionIds === null ) { |
|
236 | + if ($latestRevisionIds === null) { |
|
237 | 237 | continue; |
238 | 238 | } |
239 | 239 | $value = [ |
@@ -241,10 +241,10 @@ discard block |
||
241 | 241 | 'latestRevisionIds' => $latestRevisionIds, |
242 | 242 | ]; |
243 | 243 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
244 | - if ( $futureTime !== null ) { |
|
244 | + if ($futureTime !== null) { |
|
245 | 245 | $value['futureTime'] = $futureTime->getArrayValue(); |
246 | 246 | } |
247 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
247 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
@@ -276,10 +276,10 @@ discard block |
||
276 | 276 | array $constraintIds = null, |
277 | 277 | array $statuses |
278 | 278 | ) { |
279 | - if ( $constraintIds !== null ) { |
|
279 | + if ($constraintIds !== null) { |
|
280 | 280 | return false; |
281 | 281 | } |
282 | - if ( $statuses != $this->cachedStatuses ) { |
|
282 | + if ($statuses != $this->cachedStatuses) { |
|
283 | 283 | return false; |
284 | 284 | } |
285 | 285 | return true; |
@@ -292,45 +292,44 @@ discard block |
||
292 | 292 | public function getStoredResults( |
293 | 293 | EntityId $entityId |
294 | 294 | ) { |
295 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
296 | - $now = call_user_func( $this->microtime, true ); |
|
295 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
296 | + $now = call_user_func($this->microtime, true); |
|
297 | 297 | |
298 | - if ( $value === false ) { |
|
298 | + if ($value === false) { |
|
299 | 299 | return null; |
300 | 300 | } |
301 | 301 | |
302 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
302 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
303 | 303 | |
304 | 304 | $dependedEntityIds = array_map( |
305 | - [ $this->entityIdParser, "parse" ], |
|
306 | - array_keys( $value['latestRevisionIds'] ) |
|
305 | + [$this->entityIdParser, "parse"], |
|
306 | + array_keys($value['latestRevisionIds']) |
|
307 | 307 | ); |
308 | 308 | |
309 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
309 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
310 | 310 | return null; |
311 | 311 | } |
312 | 312 | |
313 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
314 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
315 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
313 | + if (array_key_exists('futureTime', $value)) { |
|
314 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
315 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
316 | 316 | return null; |
317 | 317 | } |
318 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
318 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
319 | 319 | } else { |
320 | 320 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
321 | 321 | } |
322 | 322 | |
323 | 323 | $cachingMetadata = $ageInSeconds > 0 ? |
324 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
325 | - CachingMetadata::fresh(); |
|
324 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
326 | 325 | |
327 | - if ( is_array( $value['results'] ) ) { |
|
328 | - array_walk( $value['results'], [ $this, 'updateCachingMetadata' ], $cachingMetadata ); |
|
326 | + if (is_array($value['results'])) { |
|
327 | + array_walk($value['results'], [$this, 'updateCachingMetadata'], $cachingMetadata); |
|
329 | 328 | } |
330 | 329 | |
331 | 330 | return new CachedCheckConstraintsResponse( |
332 | - [ $entityId->getSerialization() => $value['results'] ], |
|
333 | - $this->mergeStoredMetadata( $cachingMetadata, $dependedEntityIds, $futureTimeDependencyMetadata ) |
|
331 | + [$entityId->getSerialization() => $value['results']], |
|
332 | + $this->mergeStoredMetadata($cachingMetadata, $dependedEntityIds, $futureTimeDependencyMetadata) |
|
334 | 333 | ); |
335 | 334 | } |
336 | 335 | |
@@ -345,19 +344,19 @@ discard block |
||
345 | 344 | array $dependedEntityIds, |
346 | 345 | DependencyMetadata $futureTimeDependencyMetadata = null |
347 | 346 | ) { |
348 | - return Metadata::merge( [ |
|
349 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
350 | - Metadata::ofDependencyMetadata( array_reduce( |
|
347 | + return Metadata::merge([ |
|
348 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
349 | + Metadata::ofDependencyMetadata(array_reduce( |
|
351 | 350 | $dependedEntityIds, |
352 | - function( DependencyMetadata $metadata, EntityId $entityId ) { |
|
353 | - return DependencyMetadata::merge( [ |
|
351 | + function(DependencyMetadata $metadata, EntityId $entityId) { |
|
352 | + return DependencyMetadata::merge([ |
|
354 | 353 | $metadata, |
355 | - DependencyMetadata::ofEntityId( $entityId ) |
|
356 | - ] ); |
|
354 | + DependencyMetadata::ofEntityId($entityId) |
|
355 | + ]); |
|
357 | 356 | }, |
358 | 357 | $futureTimeDependencyMetadata |
359 | - ) ) |
|
360 | - ] ); |
|
358 | + )) |
|
359 | + ]); |
|
361 | 360 | } |
362 | 361 | |
363 | 362 | /** |
@@ -365,14 +364,14 @@ discard block |
||
365 | 364 | * @return int[]|null array from entity ID serializations to revision ID, |
366 | 365 | * or null to indicate that not all revision IDs could be loaded |
367 | 366 | */ |
368 | - private function getLatestRevisionIds( array $entityIds ) { |
|
369 | - if ( $entityIds === [] ) { |
|
367 | + private function getLatestRevisionIds(array $entityIds) { |
|
368 | + if ($entityIds === []) { |
|
370 | 369 | $this->loggingHelper->logEmptyDependencyMetadata(); |
371 | 370 | return []; |
372 | 371 | } |
373 | - if ( count( $entityIds ) >= $this->maxRevisionIds ) { |
|
372 | + if (count($entityIds) >= $this->maxRevisionIds) { |
|
374 | 373 | // one of those entities will probably be edited soon, so might as well skip caching |
375 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
374 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
376 | 375 | return null; |
377 | 376 | } |
378 | 377 | |
@@ -380,11 +379,11 @@ discard block |
||
380 | 379 | $entityIds, |
381 | 380 | EntityRevisionLookup::LATEST_FROM_REPLICA |
382 | 381 | ); |
383 | - if ( $this->hasFalseElements( $revisionInformations ) ) { |
|
382 | + if ($this->hasFalseElements($revisionInformations)) { |
|
384 | 383 | return null; |
385 | 384 | } |
386 | 385 | $latestRevisionIds = []; |
387 | - foreach ( $revisionInformations as $serialization => $revisionInformation ) { |
|
386 | + foreach ($revisionInformations as $serialization => $revisionInformation) { |
|
388 | 387 | $latestRevisionIds[$serialization] = $revisionInformation->page_latest; |
389 | 388 | } |
390 | 389 | return $latestRevisionIds; |
@@ -394,31 +393,31 @@ discard block |
||
394 | 393 | * @param array $array |
395 | 394 | * @return bool |
396 | 395 | */ |
397 | - private function hasFalseElements( array $array ) { |
|
398 | - return in_array( false, $array, true ); |
|
396 | + private function hasFalseElements(array $array) { |
|
397 | + return in_array(false, $array, true); |
|
399 | 398 | } |
400 | 399 | |
401 | - public function updateCachingMetadata( &$element, $key, CachingMetadata $cachingMetadata ) { |
|
402 | - if ( $key === 'cached' ) { |
|
403 | - $element = CachingMetadata::merge( [ |
|
400 | + public function updateCachingMetadata(&$element, $key, CachingMetadata $cachingMetadata) { |
|
401 | + if ($key === 'cached') { |
|
402 | + $element = CachingMetadata::merge([ |
|
404 | 403 | $cachingMetadata, |
405 | - CachingMetadata::ofArray( $element ), |
|
406 | - ] )->toArray(); |
|
404 | + CachingMetadata::ofArray($element), |
|
405 | + ])->toArray(); |
|
407 | 406 | } |
408 | 407 | if ( |
409 | - is_array( $element ) && |
|
410 | - array_key_exists( 'constraint', $element ) && |
|
411 | - in_array( $element['constraint']['type'], $this->possiblyStaleConstraintTypes, true ) |
|
408 | + is_array($element) && |
|
409 | + array_key_exists('constraint', $element) && |
|
410 | + in_array($element['constraint']['type'], $this->possiblyStaleConstraintTypes, true) |
|
412 | 411 | ) { |
413 | - $element['cached'] = CachingMetadata::merge( [ |
|
412 | + $element['cached'] = CachingMetadata::merge([ |
|
414 | 413 | $cachingMetadata, |
415 | 414 | CachingMetadata::ofArray( |
416 | - array_key_exists( 'cached', $element ) ? $element['cached'] : null |
|
415 | + array_key_exists('cached', $element) ? $element['cached'] : null |
|
417 | 416 | ), |
418 | - ] )->toArray(); |
|
417 | + ])->toArray(); |
|
419 | 418 | } |
420 | - if ( is_array( $element ) ) { |
|
421 | - array_walk( $element, [ $this, __FUNCTION__ ], $cachingMetadata ); |
|
419 | + if (is_array($element)) { |
|
420 | + array_walk($element, [$this, __FUNCTION__], $cachingMetadata); |
|
422 | 421 | } |
423 | 422 | } |
424 | 423 | |
@@ -427,7 +426,7 @@ discard block |
||
427 | 426 | * |
428 | 427 | * @param callable $microtime |
429 | 428 | */ |
430 | - public function setMicrotimeFunction( callable $microtime ) { |
|
429 | + public function setMicrotimeFunction(callable $microtime) { |
|
431 | 430 | $this->microtime = $microtime; |
432 | 431 | } |
433 | 432 |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | $this->dataFactory = $dataFactory; |
48 | 48 | $this->logger = $logger; |
49 | 49 | $this->constraintCheckDurationLimits = [ |
50 | - 'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ), |
|
51 | - 'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ), |
|
50 | + 'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'), |
|
51 | + 'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'), |
|
52 | 52 | ]; |
53 | 53 | } |
54 | 54 | |
@@ -74,46 +74,46 @@ discard block |
||
74 | 74 | $durationSeconds, |
75 | 75 | $method |
76 | 76 | ) { |
77 | - $constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 ); |
|
77 | + $constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1); |
|
78 | 78 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
79 | 79 | |
80 | 80 | $this->dataFactory->timing( |
81 | - 'wikibase.quality.constraints.check.timing.' . |
|
82 | - $constraintTypeItemId . '-' . |
|
81 | + 'wikibase.quality.constraints.check.timing.'. |
|
82 | + $constraintTypeItemId.'-'. |
|
83 | 83 | $constraintCheckerClassShortName, |
84 | 84 | $durationSeconds * 1000 |
85 | 85 | ); |
86 | 86 | |
87 | 87 | // find the longest limit (and associated log level) that the duration exceeds |
88 | - foreach ( $this->constraintCheckDurationLimits as $level => $limit ) { |
|
88 | + foreach ($this->constraintCheckDurationLimits as $level => $limit) { |
|
89 | 89 | if ( |
90 | 90 | // duration exceeds this limit |
91 | - isset( $limit ) && $durationSeconds > $limit && |
|
91 | + isset($limit) && $durationSeconds > $limit && |
|
92 | 92 | // this limit is longer than previous longest limit |
93 | - ( !isset( $limitSeconds ) || $limit > $limitSeconds ) |
|
93 | + (!isset($limitSeconds) || $limit > $limitSeconds) |
|
94 | 94 | ) { |
95 | 95 | $limitSeconds = $limit; |
96 | 96 | $logLevel = $level; |
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | - if ( !isset( $limitSeconds ) ) { |
|
100 | + if (!isset($limitSeconds)) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
103 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
104 | 104 | // TODO log less details but still log something |
105 | 105 | return; |
106 | 106 | } |
107 | 107 | |
108 | 108 | $resultMessage = $result->getMessage(); |
109 | - if ( $resultMessage instanceof ViolationMessage ) { |
|
109 | + if ($resultMessage instanceof ViolationMessage) { |
|
110 | 110 | $resultMessage = $resultMessage->getMessageKey(); |
111 | 111 | } |
112 | 112 | |
113 | 113 | $this->logger->log( |
114 | 114 | $logLevel, |
115 | - 'Constraint check with {constraintCheckerClassShortName} ' . |
|
116 | - 'took longer than {limitSeconds} second(s) ' . |
|
115 | + 'Constraint check with {constraintCheckerClassShortName} '. |
|
116 | + 'took longer than {limitSeconds} second(s) '. |
|
117 | 117 | '(duration: {durationSeconds} seconds).', |
118 | 118 | [ |
119 | 119 | 'method' => $method, |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @param EntityId $entityId |
142 | 142 | */ |
143 | - public function logCheckConstraintsCacheHit( EntityId $entityId ) { |
|
143 | + public function logCheckConstraintsCacheHit(EntityId $entityId) { |
|
144 | 144 | $this->dataFactory->increment( |
145 | 145 | 'wikibase.quality.constraints.cache.entity.hit' |
146 | 146 | ); |
@@ -151,10 +151,10 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @param EntityId[] $entityIds |
153 | 153 | */ |
154 | - public function logCheckConstraintsCacheMisses( array $entityIds ) { |
|
154 | + public function logCheckConstraintsCacheMisses(array $entityIds) { |
|
155 | 155 | $this->dataFactory->updateCount( |
156 | 156 | 'wikibase.quality.constraints.cache.entity.miss', |
157 | - count( $entityIds ) |
|
157 | + count($entityIds) |
|
158 | 158 | ); |
159 | 159 | } |
160 | 160 | |
@@ -181,16 +181,16 @@ discard block |
||
181 | 181 | * @param EntityId[] $entityIds |
182 | 182 | * @param int $maxRevisionIds |
183 | 183 | */ |
184 | - public function logHugeDependencyMetadata( array $entityIds, $maxRevisionIds ) { |
|
184 | + public function logHugeDependencyMetadata(array $entityIds, $maxRevisionIds) { |
|
185 | 185 | $this->logger->log( |
186 | 186 | 'warning', |
187 | - 'Dependency metadata for constraint check result has huge set of entity IDs ' . |
|
188 | - '(count ' . count( $entityIds ) . ', limit ' . $maxRevisionIds . '); ' . |
|
187 | + 'Dependency metadata for constraint check result has huge set of entity IDs '. |
|
188 | + '(count '.count($entityIds).', limit '.$maxRevisionIds.'); '. |
|
189 | 189 | 'caching disabled for this check result.', |
190 | 190 | [ |
191 | 191 | 'loggingMethod' => __METHOD__, |
192 | 192 | 'entityIds' => array_map( |
193 | - function ( EntityId $entityId ) { |
|
193 | + function(EntityId $entityId) { |
|
194 | 194 | return $entityId->getSerialization(); |
195 | 195 | }, |
196 | 196 | $entityIds |