@@ -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 | ]; |
@@ -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 |
@@ -86,6 +86,6 @@ |
||
86 | 86 | * @param array|null $result |
87 | 87 | * @param array[] &$container |
88 | 88 | */ |
89 | - public function storeCheckResultInArray( array $result = null, array &$container ); |
|
89 | + public function storeCheckResultInArray(array $result = null, array &$container); |
|
90 | 90 | |
91 | 91 | } |
@@ -84,65 +84,64 @@ discard block |
||
84 | 84 | ) { |
85 | 85 | $response = []; |
86 | 86 | $metadatas = []; |
87 | - $statusesFlipped = array_flip( $statuses ); |
|
88 | - foreach ( $entityIds as $entityId ) { |
|
87 | + $statusesFlipped = array_flip($statuses); |
|
88 | + foreach ($entityIds as $entityId) { |
|
89 | 89 | $results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnEntityId( |
90 | 90 | $entityId, |
91 | 91 | $constraintIds, |
92 | - [ $this, 'defaultResults' ] |
|
92 | + [$this, 'defaultResults'] |
|
93 | 93 | ); |
94 | - foreach ( $results as $result ) { |
|
94 | + foreach ($results as $result) { |
|
95 | 95 | $metadatas[] = $result->getMetadata(); |
96 | - if ( $this->statusSelected( $statusesFlipped, $result ) ) { |
|
97 | - $resultArray = $this->checkResultToArray( $result ); |
|
98 | - $result->getContextCursor()->storeCheckResultInArray( $resultArray, $response ); |
|
96 | + if ($this->statusSelected($statusesFlipped, $result)) { |
|
97 | + $resultArray = $this->checkResultToArray($result); |
|
98 | + $result->getContextCursor()->storeCheckResultInArray($resultArray, $response); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
102 | - foreach ( $claimIds as $claimId ) { |
|
102 | + foreach ($claimIds as $claimId) { |
|
103 | 103 | $results = $this->delegatingConstraintChecker->checkAgainstConstraintsOnClaimId( |
104 | 104 | $claimId, |
105 | 105 | $constraintIds, |
106 | - [ $this, 'defaultResults' ] |
|
106 | + [$this, 'defaultResults'] |
|
107 | 107 | ); |
108 | - foreach ( $results as $result ) { |
|
108 | + foreach ($results as $result) { |
|
109 | 109 | $metadatas[] = $result->getMetadata(); |
110 | - if ( $this->statusSelected( $statusesFlipped, $result ) ) { |
|
111 | - $resultArray = $this->checkResultToArray( $result ); |
|
112 | - $result->getContextCursor()->storeCheckResultInArray( $resultArray, $response ); |
|
110 | + if ($this->statusSelected($statusesFlipped, $result)) { |
|
111 | + $resultArray = $this->checkResultToArray($result); |
|
112 | + $result->getContextCursor()->storeCheckResultInArray($resultArray, $response); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | } |
116 | 116 | return new CachedCheckConstraintsResponse( |
117 | 117 | $response, |
118 | - Metadata::merge( $metadatas ) |
|
118 | + Metadata::merge($metadatas) |
|
119 | 119 | ); |
120 | 120 | } |
121 | 121 | |
122 | - public function defaultResults( Context $context ) { |
|
122 | + public function defaultResults(Context $context) { |
|
123 | 123 | return $context->getType() === Context::TYPE_STATEMENT ? |
124 | - [ new NullResult( $context ) ] : |
|
125 | - []; |
|
124 | + [new NullResult($context)] : []; |
|
126 | 125 | } |
127 | 126 | |
128 | - public function statusSelected( array $statusesFlipped, CheckResult $result ) { |
|
129 | - return array_key_exists( $result->getStatus(), $statusesFlipped ) || |
|
127 | + public function statusSelected(array $statusesFlipped, CheckResult $result) { |
|
128 | + return array_key_exists($result->getStatus(), $statusesFlipped) || |
|
130 | 129 | $result instanceof NullResult; |
131 | 130 | } |
132 | 131 | |
133 | - public function checkResultToArray( CheckResult $checkResult ) { |
|
134 | - if ( $checkResult instanceof NullResult ) { |
|
132 | + public function checkResultToArray(CheckResult $checkResult) { |
|
133 | + if ($checkResult instanceof NullResult) { |
|
135 | 134 | return null; |
136 | 135 | } |
137 | 136 | |
138 | 137 | $constraintId = $checkResult->getConstraint()->getConstraintId(); |
139 | 138 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
140 | - $constraintPropertyId = new PropertyId( $checkResult->getContextCursor()->getSnakPropertyId() ); |
|
139 | + $constraintPropertyId = new PropertyId($checkResult->getContextCursor()->getSnakPropertyId()); |
|
141 | 140 | |
142 | - $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
143 | - $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
141 | + $title = $this->entityTitleLookup->getTitleForId($constraintPropertyId); |
|
142 | + $typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId)); |
|
144 | 143 | // TODO link to the statement when possible (T169224) |
145 | - $link = $title->getFullURL() . '#' . $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
144 | + $link = $title->getFullURL().'#'.$this->config->get('WBQualityConstraintsPropertyConstraintId'); |
|
146 | 145 | |
147 | 146 | $constraint = [ |
148 | 147 | 'id' => $constraintId, |
@@ -151,11 +150,11 @@ discard block |
||
151 | 150 | 'link' => $link, |
152 | 151 | 'discussLink' => $title->getTalkPage()->getFullURL(), |
153 | 152 | ]; |
154 | - if ( $this->config->get( 'WBQualityConstraintsIncludeDetailInApi' ) ) { |
|
153 | + if ($this->config->get('WBQualityConstraintsIncludeDetailInApi')) { |
|
155 | 154 | $parameters = $checkResult->getParameters(); |
156 | 155 | $constraint += [ |
157 | 156 | 'detail' => $parameters, |
158 | - 'detailHTML' => $this->constraintParameterRenderer->formatParameters( $parameters ), |
|
157 | + 'detailHTML' => $this->constraintParameterRenderer->formatParameters($parameters), |
|
159 | 158 | ]; |
160 | 159 | } |
161 | 160 | |
@@ -165,14 +164,14 @@ discard block |
||
165 | 164 | 'constraint' => $constraint |
166 | 165 | ]; |
167 | 166 | $message = $checkResult->getMessage(); |
168 | - if ( $message ) { |
|
169 | - $result['message-html'] = $this->violationMessageRenderer->render( $message ); |
|
167 | + if ($message) { |
|
168 | + $result['message-html'] = $this->violationMessageRenderer->render($message); |
|
170 | 169 | } |
171 | - if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) { |
|
170 | + if ($checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT) { |
|
172 | 171 | $result['claim'] = $checkResult->getContextCursor()->getStatementGuid(); |
173 | 172 | } |
174 | 173 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
175 | - if ( $cachingMetadataArray !== null ) { |
|
174 | + if ($cachingMetadataArray !== null) { |
|
176 | 175 | $result['cached'] = $cachingMetadataArray; |
177 | 176 | } |
178 | 177 |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | $status = self::STATUS_TODO, |
123 | 123 | $message = null |
124 | 124 | ) { |
125 | - if ( $contextCursor instanceof Context ) { |
|
125 | + if ($contextCursor instanceof Context) { |
|
126 | 126 | $context = $contextCursor; |
127 | 127 | $this->contextCursor = $context->getCursor(); |
128 | 128 | $this->snakType = $context->getSnak()->getType(); |
129 | 129 | $mainSnak = $context->getSnak(); |
130 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
130 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
131 | 131 | $this->dataValue = $mainSnak->getDataValue(); |
132 | 132 | } else { |
133 | 133 | $this->dataValue = null; |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * @param string $key |
191 | 191 | * @param string $value |
192 | 192 | */ |
193 | - public function addParameter( $key, $value ) { |
|
193 | + public function addParameter($key, $value) { |
|
194 | 194 | $this->parameters[$key][] = $value; |
195 | 195 | } |
196 | 196 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | /** |
205 | 205 | * @param string $status |
206 | 206 | */ |
207 | - public function setStatus( $status ) { |
|
207 | + public function setStatus($status) { |
|
208 | 208 | $this->status = $status; |
209 | 209 | } |
210 | 210 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * @param Metadata $metadata |
220 | 220 | * @return self |
221 | 221 | */ |
222 | - public function withMetadata( Metadata $metadata ) { |
|
222 | + public function withMetadata(Metadata $metadata) { |
|
223 | 223 | $this->metadata = $metadata; |
224 | 224 | return $this; |
225 | 225 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | Statement $statement, |
24 | 24 | Snak $snak |
25 | 25 | ) { |
26 | - parent::__construct( $entity, $snak ); |
|
26 | + parent::__construct($entity, $snak); |
|
27 | 27 | $this->statement = $statement; |
28 | 28 | } |
29 | 29 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | public function getSnakGroup() { |
35 | 35 | $snaks = $this->statement->getQualifiers(); |
36 | - return array_values( $snaks->getArrayCopy() ); |
|
36 | + return array_values($snaks->getArrayCopy()); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | public function getCursor() { |
@@ -20,9 +20,9 @@ discard block |
||
20 | 20 | */ |
21 | 21 | private $statement; |
22 | 22 | |
23 | - public function __construct( EntityDocument $entity, Statement $statement ) { |
|
24 | - Assert::parameterType( StatementListProvider::class, $entity, '$entity' ); |
|
25 | - parent::__construct( $entity, $statement->getMainSnak() ); |
|
23 | + public function __construct(EntityDocument $entity, Statement $statement) { |
|
24 | + Assert::parameterType(StatementListProvider::class, $entity, '$entity'); |
|
25 | + parent::__construct($entity, $statement->getMainSnak()); |
|
26 | 26 | |
27 | 27 | $this->statement = $statement; |
28 | 28 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | /** @var StatementList $statements */ |
44 | 44 | $statements = $this->entity->getStatements(); |
45 | 45 | return $statements |
46 | - ->getByRank( [ Statement::RANK_NORMAL, Statement::RANK_PREFERRED ] ) |
|
46 | + ->getByRank([Statement::RANK_NORMAL, Statement::RANK_PREFERRED]) |
|
47 | 47 | ->getMainSnaks(); |
48 | 48 | } |
49 | 49 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | Reference $reference, |
31 | 31 | Snak $snak |
32 | 32 | ) { |
33 | - parent::__construct( $entity, $snak ); |
|
33 | + parent::__construct($entity, $snak); |
|
34 | 34 | $this->statement = $statement; |
35 | 35 | $this->reference = $reference; |
36 | 36 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | public function getSnakGroup() { |
43 | 43 | $snaks = $this->reference->getSnaks(); |
44 | - return array_values( $snaks->getArrayCopy() ); |
|
44 | + return array_values($snaks->getArrayCopy()); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | public function getCursor() { |
@@ -28,36 +28,36 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param DatabaseUpdater $updater |
30 | 30 | */ |
31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
32 | - $updater->addExtensionTable( 'wbqc_constraints', __DIR__ . '/../sql/create_wbqc_constraints.sql' ); |
|
33 | - $updater->addExtensionField( 'wbqc_constraints', 'constraint_id', __DIR__ . '/../sql/patch-wbqc_constraints-constraint_id.sql' ); |
|
31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
32 | + $updater->addExtensionTable('wbqc_constraints', __DIR__.'/../sql/create_wbqc_constraints.sql'); |
|
33 | + $updater->addExtensionField('wbqc_constraints', 'constraint_id', __DIR__.'/../sql/patch-wbqc_constraints-constraint_id.sql'); |
|
34 | 34 | } |
35 | 35 | |
36 | - public static function onWikibaseChange( Change $change ) { |
|
36 | + public static function onWikibaseChange(Change $change) { |
|
37 | 37 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
38 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
39 | - self::isConstraintStatementsChange( $config, $change ) |
|
38 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
39 | + self::isConstraintStatementsChange($config, $change) |
|
40 | 40 | ) { |
41 | 41 | /** @var EntityChange $change */ |
42 | 42 | $title = Title::newMainPage(); |
43 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
43 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
44 | 44 | JobQueueGroup::singleton()->push( |
45 | - new JobSpecification( 'constraintsTableUpdate', $params, [], $title ) |
|
45 | + new JobSpecification('constraintsTableUpdate', $params, [], $title) |
|
46 | 46 | ); |
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
51 | - if ( !( $change instanceof EntityChange ) || |
|
50 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
51 | + if (!($change instanceof EntityChange) || |
|
52 | 52 | $change->getAction() !== EntityChange::UPDATE || |
53 | - !( $change->getEntityId() instanceof PropertyId ) |
|
53 | + !($change->getEntityId() instanceof PropertyId) |
|
54 | 54 | ) { |
55 | 55 | return false; |
56 | 56 | } |
57 | 57 | |
58 | 58 | $info = $change->getInfo(); |
59 | 59 | |
60 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
60 | + if (!array_key_exists('compactDiff', $info)) { |
|
61 | 61 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
62 | 62 | // so we only know that the change *might* affect the constraint statements |
63 | 63 | return true; |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | /** @var EntityDiffChangedAspects $aspects */ |
67 | 67 | $aspects = $info['compactDiff']; |
68 | 68 | |
69 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
70 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
69 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
70 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
71 | 71 | } |
72 | 72 | |
73 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
73 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
74 | 74 | $repo = WikibaseRepo::getDefaultInstance(); |
75 | 75 | |
76 | 76 | $entityContentFactory = $repo->getEntityContentFactory(); |
77 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
78 | - $entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
77 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
78 | + $entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle()); |
|
79 | 79 | $resultsCache = ResultsCache::getDefaultInstance(); |
80 | - $resultsCache->delete( $entityId ); |
|
80 | + $resultsCache->delete($entityId); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
@@ -86,18 +86,18 @@ discard block |
||
86 | 86 | * @param int $timestamp UTC timestamp (seconds since the Epoch) |
87 | 87 | * @return bool |
88 | 88 | */ |
89 | - public static function isGadgetEnabledForUserName( $userName, $timestamp ) { |
|
89 | + public static function isGadgetEnabledForUserName($userName, $timestamp) { |
|
90 | 90 | $initial = $userName[0]; |
91 | 91 | |
92 | - if ( $initial === 'Z' ) { |
|
92 | + if ($initial === 'Z') { |
|
93 | 93 | $firstWeek = 0; |
94 | - } elseif ( $initial >= 'W' && $initial < 'Z' ) { |
|
94 | + } elseif ($initial >= 'W' && $initial < 'Z') { |
|
95 | 95 | $firstWeek = 1; |
96 | - } elseif ( $initial >= 'T' && $initial < 'W' ) { |
|
96 | + } elseif ($initial >= 'T' && $initial < 'W') { |
|
97 | 97 | $firstWeek = 2; |
98 | - } elseif ( $initial >= 'N' && $initial < 'T' ) { |
|
98 | + } elseif ($initial >= 'N' && $initial < 'T') { |
|
99 | 99 | $firstWeek = 3; |
100 | - } elseif ( $initial >= 'E' && $initial < 'N' ) { |
|
100 | + } elseif ($initial >= 'E' && $initial < 'N') { |
|
101 | 101 | $firstWeek = 4; |
102 | 102 | } else { |
103 | 103 | $firstWeek = 5; |
@@ -115,27 +115,27 @@ discard block |
||
115 | 115 | return $timestamp >= $threshold; |
116 | 116 | } |
117 | 117 | |
118 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
118 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
119 | 119 | $repo = WikibaseRepo::getDefaultInstance(); |
120 | 120 | |
121 | 121 | $lookup = $repo->getEntityNamespaceLookup(); |
122 | 122 | $title = $out->getTitle(); |
123 | - if ( $title === null ) { |
|
123 | + if ($title === null) { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | - if ( !$lookup->isEntityNamespace( $title->getNamespace() ) ) { |
|
127 | + if (!$lookup->isEntityNamespace($title->getNamespace())) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | - if ( !$out->getUser()->isLoggedIn() ) { |
|
130 | + if (!$out->getUser()->isLoggedIn()) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
133 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - if ( self::isGadgetEnabledForUserName( $out->getUser()->getName(), time() ) ) { |
|
138 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
137 | + if (self::isGadgetEnabledForUserName($out->getUser()->getName(), time())) { |
|
138 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 |