@@ -77,21 +77,21 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return self |
79 | 79 | */ |
80 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
80 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
81 | 81 | $repo = WikibaseRepo::getDefaultInstance(); |
82 | 82 | |
83 | 83 | $language = $repo->getUserLanguage(); |
84 | 84 | $formatterOptions = new FormatterOptions(); |
85 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
85 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
86 | 86 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
87 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
87 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
88 | 88 | |
89 | 89 | $languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory(); |
90 | - $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language ); |
|
90 | + $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language); |
|
91 | 91 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
92 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
92 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
93 | 93 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
94 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
94 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
95 | 95 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
96 | 96 | $titleParser = MediaWikiServices::getInstance()->getTitleParser(); |
97 | 97 | $unitConverter = $repo->getUnitConverter(); |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | $repo->getEntityTitleLookup(), |
125 | 125 | $entityIdLabelFormatter, |
126 | 126 | $constraintParameterRenderer, |
127 | - new ViolationMessageRenderer( $entityIdHtmlLinkFormatter ), |
|
127 | + new ViolationMessageRenderer($entityIdHtmlLinkFormatter), |
|
128 | 128 | $config |
129 | 129 | ); |
130 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
130 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
131 | 131 | $wikiPageEntityMetaDataAccessor = new WikiPageEntityMetaDataLookup( |
132 | 132 | $repo->getEntityNamespaceLookup() |
133 | 133 | ); |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | ResultsCache::getDefaultInstance(), |
139 | 139 | $wikiPageEntityMetaDataAccessor, |
140 | 140 | $entityIdParser, |
141 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
141 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
142 | 142 | [ |
143 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
144 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
145 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
146 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
143 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
144 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
145 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
146 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
147 | 147 | ], |
148 | 148 | $dataFactory |
149 | 149 | ); |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $prefix, |
156 | 156 | $repo->getEntityIdParser(), |
157 | 157 | $repo->getStatementGuidValidator(), |
158 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
158 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
159 | 159 | $resultsBuilder, |
160 | 160 | $dataFactory |
161 | 161 | ); |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | ResultsBuilder $resultsBuilder, |
182 | 182 | IBufferingStatsdDataFactory $dataFactory |
183 | 183 | ) { |
184 | - parent::__construct( $main, $name, $prefix ); |
|
184 | + parent::__construct($main, $name, $prefix); |
|
185 | 185 | $this->entityIdParser = $entityIdParser; |
186 | 186 | $this->statementGuidValidator = $statementGuidValidator; |
187 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
188 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
187 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
188 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
189 | 189 | $this->resultsBuilder = $resultsBuilder; |
190 | 190 | $this->dataFactory = $dataFactory; |
191 | 191 | } |
@@ -200,9 +200,9 @@ discard block |
||
200 | 200 | |
201 | 201 | $params = $this->extractRequestParams(); |
202 | 202 | |
203 | - $this->validateParameters( $params ); |
|
204 | - $entityIds = $this->parseEntityIds( $params ); |
|
205 | - $claimIds = $this->parseClaimIds( $params ); |
|
203 | + $this->validateParameters($params); |
|
204 | + $entityIds = $this->parseEntityIds($params); |
|
205 | + $claimIds = $this->parseClaimIds($params); |
|
206 | 206 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
207 | 207 | $statuses = $params[self::PARAM_STATUS]; |
208 | 208 | |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | )->getArray() |
218 | 218 | ); |
219 | 219 | // ensure that result contains the given entity IDs even if they have no statements |
220 | - foreach ( $entityIds as $entityId ) { |
|
220 | + foreach ($entityIds as $entityId) { |
|
221 | 221 | $this->getResult()->addArrayType( |
222 | - [ $this->getModuleName(), $entityId->getSerialization() ], |
|
222 | + [$this->getModuleName(), $entityId->getSerialization()], |
|
223 | 223 | 'assoc' |
224 | 224 | ); |
225 | 225 | } |
226 | - $this->resultBuilder->markSuccess( 1 ); |
|
226 | + $this->resultBuilder->markSuccess(1); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -231,24 +231,24 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return EntityId[] |
233 | 233 | */ |
234 | - private function parseEntityIds( array $params ) { |
|
234 | + private function parseEntityIds(array $params) { |
|
235 | 235 | $ids = $params[self::PARAM_ID]; |
236 | 236 | |
237 | - if ( $ids === null ) { |
|
237 | + if ($ids === null) { |
|
238 | 238 | return []; |
239 | - } elseif ( $ids === [] ) { |
|
239 | + } elseif ($ids === []) { |
|
240 | 240 | $this->errorReporter->dieError( |
241 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
241 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
242 | 242 | } |
243 | 243 | |
244 | - return array_map( function ( $id ) { |
|
244 | + return array_map(function($id) { |
|
245 | 245 | try { |
246 | - return $this->entityIdParser->parse( $id ); |
|
247 | - } catch ( EntityIdParsingException $e ) { |
|
246 | + return $this->entityIdParser->parse($id); |
|
247 | + } catch (EntityIdParsingException $e) { |
|
248 | 248 | $this->errorReporter->dieError( |
249 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
249 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
250 | 250 | } |
251 | - }, $ids ); |
|
251 | + }, $ids); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -256,35 +256,35 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @return string[] |
258 | 258 | */ |
259 | - private function parseClaimIds( array $params ) { |
|
259 | + private function parseClaimIds(array $params) { |
|
260 | 260 | $ids = $params[self::PARAM_CLAIM_ID]; |
261 | 261 | |
262 | - if ( $ids === null ) { |
|
262 | + if ($ids === null) { |
|
263 | 263 | return []; |
264 | - } elseif ( $ids === [] ) { |
|
264 | + } elseif ($ids === []) { |
|
265 | 265 | $this->errorReporter->dieError( |
266 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
266 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
267 | 267 | } |
268 | 268 | |
269 | - foreach ( $ids as $id ) { |
|
270 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
269 | + foreach ($ids as $id) { |
|
270 | + if (!$this->statementGuidValidator->validate($id)) { |
|
271 | 271 | $this->errorReporter->dieError( |
272 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
272 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
276 | 276 | return $ids; |
277 | 277 | } |
278 | 278 | |
279 | - private function validateParameters( array $params ) { |
|
280 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
281 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
279 | + private function validateParameters(array $params) { |
|
280 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
281 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
282 | 282 | ) { |
283 | 283 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
284 | 284 | $this->errorReporter->dieError( |
285 | 285 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
286 | 286 | } |
287 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
287 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
288 | 288 | $paramId = self::PARAM_ID; |
289 | 289 | $paramClaimId = self::PARAM_CLAIM_ID; |
290 | 290 | $this->errorReporter->dieError( |
@@ -35,45 +35,45 @@ |
||
35 | 35 | $language = null, |
36 | 36 | $format = Message::FORMAT_ESCAPED |
37 | 37 | ) { |
38 | - if ( is_string( $violationMessage ) ) { |
|
38 | + if (is_string($violationMessage)) { |
|
39 | 39 | // TODO remove this once all checkers produce ViolationMessage objects |
40 | 40 | return $violationMessage; |
41 | 41 | } |
42 | - $message = new Message( $violationMessage->getMessageKey(), [], $language ); |
|
43 | - foreach ( $violationMessage->getArguments() as $argument ) { |
|
44 | - $this->renderArgument( $argument, $message ); |
|
42 | + $message = new Message($violationMessage->getMessageKey(), [], $language); |
|
43 | + foreach ($violationMessage->getArguments() as $argument) { |
|
44 | + $this->renderArgument($argument, $message); |
|
45 | 45 | } |
46 | - return $message->toString( $format ); |
|
46 | + return $message->toString($format); |
|
47 | 47 | } |
48 | 48 | |
49 | - private function addRole( $value, $role ) { |
|
50 | - if ( $role === null ) { |
|
49 | + private function addRole($value, $role) { |
|
50 | + if ($role === null) { |
|
51 | 51 | return $value; |
52 | 52 | } |
53 | 53 | |
54 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' . |
|
55 | - $value . |
|
54 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'. |
|
55 | + $value. |
|
56 | 56 | '</span>'; |
57 | 57 | } |
58 | 58 | |
59 | - private function renderArgument( array $argument, Message $message ) { |
|
60 | - switch ( $argument['type'] ) { |
|
59 | + private function renderArgument(array $argument, Message $message) { |
|
60 | + switch ($argument['type']) { |
|
61 | 61 | case ViolationMessage::TYPE_ENTITY_ID: |
62 | - $params = $this->renderEntityId( $argument['value'], $argument['role'] ); |
|
62 | + $params = $this->renderEntityId($argument['value'], $argument['role']); |
|
63 | 63 | break; |
64 | 64 | default: |
65 | 65 | throw new InvalidArgumentException( |
66 | - 'Unknown ViolationMessage argument type ' . $argument['type'] . '!' |
|
66 | + 'Unknown ViolationMessage argument type '.$argument['type'].'!' |
|
67 | 67 | ); |
68 | 68 | } |
69 | - $message->params( $params ); |
|
69 | + $message->params($params); |
|
70 | 70 | } |
71 | 71 | |
72 | - private function renderEntityId( EntityId $entityId, $role ) { |
|
73 | - return Message::rawParam( $this->addRole( |
|
74 | - $this->entityIdFormatter->formatEntityId( $entityId ), |
|
72 | + private function renderEntityId(EntityId $entityId, $role) { |
|
73 | + return Message::rawParam($this->addRole( |
|
74 | + $this->entityIdFormatter->formatEntityId($entityId), |
|
75 | 75 | $role |
76 | - ) ); |
|
76 | + )); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | } |
@@ -46,17 +46,17 @@ discard block |
||
46 | 46 | public function __construct( |
47 | 47 | $messageKey |
48 | 48 | ) { |
49 | - if ( strpos( $messageKey, self::MESSAGE_KEY_PREFIX ) !== 0 ) { |
|
49 | + if (strpos($messageKey, self::MESSAGE_KEY_PREFIX) !== 0) { |
|
50 | 50 | throw new InvalidArgumentException( |
51 | - 'ViolationMessage key ⧼' . |
|
52 | - $messageKey . |
|
53 | - '⧽ should start with "' . |
|
54 | - self::MESSAGE_KEY_PREFIX . |
|
51 | + 'ViolationMessage key ⧼'. |
|
52 | + $messageKey. |
|
53 | + '⧽ should start with "'. |
|
54 | + self::MESSAGE_KEY_PREFIX. |
|
55 | 55 | '".' |
56 | 56 | ); |
57 | 57 | } |
58 | 58 | |
59 | - $this->messageKeySuffix = substr( $messageKey, strlen( self::MESSAGE_KEY_PREFIX ) ); |
|
59 | + $this->messageKeySuffix = substr($messageKey, strlen(self::MESSAGE_KEY_PREFIX)); |
|
60 | 60 | $this->arguments = []; |
61 | 61 | } |
62 | 62 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @return string |
66 | 66 | */ |
67 | 67 | public function getMessageKey() { |
68 | - return self::MESSAGE_KEY_PREFIX . $this->messageKeySuffix; |
|
68 | + return self::MESSAGE_KEY_PREFIX.$this->messageKeySuffix; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @param mixed $value the value, which should match the $type |
84 | 84 | * @return ViolationMessage |
85 | 85 | */ |
86 | - private function withArgument( $type, $role, $value ) { |
|
86 | + private function withArgument($type, $role, $value) { |
|
87 | 87 | $ret = clone $this; |
88 | - $ret->arguments[] = [ 'type' => $type, 'role' => $role, 'value' => $value ]; |
|
88 | + $ret->arguments[] = ['type' => $type, 'role' => $role, 'value' => $value]; |
|
89 | 89 | return $ret; |
90 | 90 | } |
91 | 91 | |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | * @param string|null $role one of the Role::* constants |
98 | 98 | * @return ViolationMessage |
99 | 99 | */ |
100 | - public function withEntityId( EntityId $entityId, $role = null ) { |
|
101 | - return $this->withArgument( self::TYPE_ENTITY_ID, $role, $entityId ); |
|
100 | + public function withEntityId(EntityId $entityId, $role = null) { |
|
101 | + return $this->withArgument(self::TYPE_ENTITY_ID, $role, $entityId); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | } |