@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Message; |
6 | 6 | |
@@ -70,15 +70,15 @@ discard block |
||
70 | 70 | $this->maxListLength = $maxListLength; |
71 | 71 | } |
72 | 72 | |
73 | - public function render( ViolationMessage $violationMessage ): string { |
|
73 | + public function render(ViolationMessage $violationMessage): string { |
|
74 | 74 | $messageKey = $violationMessage->getMessageKey(); |
75 | - $paramsLists = [ [] ]; |
|
76 | - foreach ( $violationMessage->getArguments() as $argument ) { |
|
77 | - $params = $this->renderArgument( $argument ); |
|
75 | + $paramsLists = [[]]; |
|
76 | + foreach ($violationMessage->getArguments() as $argument) { |
|
77 | + $params = $this->renderArgument($argument); |
|
78 | 78 | $paramsLists[] = $params; |
79 | 79 | } |
80 | - $allParams = array_merge( ...$paramsLists ); |
|
81 | - return $this->messageLocalizer->msg( $messageKey, ...$allParams )->escaped(); |
|
80 | + $allParams = array_merge(...$paramsLists); |
|
81 | + return $this->messageLocalizer->msg($messageKey, ...$allParams)->escaped(); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | * @param string|null $role one of the Role::* constants |
87 | 87 | * @return string HTML |
88 | 88 | */ |
89 | - protected function addRole( string $value, ?string $role ): string { |
|
90 | - if ( $role === null ) { |
|
89 | + protected function addRole(string $value, ?string $role): string { |
|
90 | + if ($role === null) { |
|
91 | 91 | return $value; |
92 | 92 | } |
93 | 93 | |
94 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' . |
|
95 | - $value . |
|
94 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'. |
|
95 | + $value. |
|
96 | 96 | '</span>'; |
97 | 97 | } |
98 | 98 | |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | * @param string $key message key |
101 | 101 | * @return string HTML |
102 | 102 | */ |
103 | - protected function msgEscaped( string $key ): string { |
|
104 | - return $this->messageLocalizer->msg( $key )->escaped(); |
|
103 | + protected function msgEscaped(string $key): string { |
|
104 | + return $this->messageLocalizer->msg($key)->escaped(); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @param array $argument |
109 | 109 | * @return MessageParam[] params (for Message::params) |
110 | 110 | */ |
111 | - protected function renderArgument( array $argument ): array { |
|
111 | + protected function renderArgument(array $argument): array { |
|
112 | 112 | $methods = [ |
113 | 113 | ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId', |
114 | 114 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList', |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | $value = $argument['value']; |
130 | 130 | $role = $argument['role']; |
131 | 131 | |
132 | - if ( array_key_exists( $type, $methods ) ) { |
|
132 | + if (array_key_exists($type, $methods)) { |
|
133 | 133 | $method = $methods[$type]; |
134 | - $params = $this->$method( $value, $role ); |
|
134 | + $params = $this->$method($value, $role); |
|
135 | 135 | } else { |
136 | 136 | throw new InvalidArgumentException( |
137 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
137 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
138 | 138 | ); |
139 | 139 | } |
140 | 140 | |
@@ -148,34 +148,34 @@ discard block |
||
148 | 148 | * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ]) |
149 | 149 | * @return MessageParam[] list of parameters as accepted by Message::params() |
150 | 150 | */ |
151 | - private function renderList( array $list, ?string $role, callable $render ): array { |
|
152 | - if ( $list === [] ) { |
|
151 | + private function renderList(array $list, ?string $role, callable $render): array { |
|
152 | + if ($list === []) { |
|
153 | 153 | return [ |
154 | - Message::numParam( 0 ), |
|
155 | - Message::rawParam( '<ul></ul>' ), |
|
154 | + Message::numParam(0), |
|
155 | + Message::rawParam('<ul></ul>'), |
|
156 | 156 | ]; |
157 | 157 | } |
158 | 158 | |
159 | - $truncated = count( $list ) > $this->maxListLength; |
|
160 | - if ( $truncated ) { |
|
161 | - $list = array_slice( $list, 0, $this->maxListLength ); |
|
159 | + $truncated = count($list) > $this->maxListLength; |
|
160 | + if ($truncated) { |
|
161 | + $list = array_slice($list, 0, $this->maxListLength); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | $renderedParamsLists = array_map( |
165 | 165 | $render, |
166 | 166 | $list, |
167 | - array_fill( 0, count( $list ), $role ) |
|
167 | + array_fill(0, count($list), $role) |
|
168 | 168 | ); |
169 | - $renderedParams = array_column( $renderedParamsLists, 0 ); |
|
170 | - $renderedElements = array_map( static fn ( MessageParam $p ) => $p->getValue(), $renderedParams ); |
|
171 | - if ( $truncated ) { |
|
172 | - $renderedElements[] = $this->msgEscaped( 'ellipsis' ); |
|
169 | + $renderedParams = array_column($renderedParamsLists, 0); |
|
170 | + $renderedElements = array_map(static fn (MessageParam $p) => $p->getValue(), $renderedParams); |
|
171 | + if ($truncated) { |
|
172 | + $renderedElements[] = $this->msgEscaped('ellipsis'); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | return [ |
176 | - Message::numParam( count( $list ) ), |
|
176 | + Message::numParam(count($list)), |
|
177 | 177 | Message::rawParam( |
178 | - '<ul><li>' . implode( '</li><li>', $renderedElements ) . '</li></ul>' |
|
178 | + '<ul><li>'.implode('</li><li>', $renderedElements).'</li></ul>' |
|
179 | 179 | ), |
180 | 180 | ...$renderedParams, |
181 | 181 | ]; |
@@ -186,11 +186,11 @@ discard block |
||
186 | 186 | * @param string|null $role one of the Role::* constants |
187 | 187 | * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
188 | 188 | */ |
189 | - private function renderEntityId( EntityId $entityId, ?string $role ): array { |
|
190 | - return [ Message::rawParam( $this->addRole( |
|
191 | - $this->entityIdFormatter->formatEntityId( $entityId ), |
|
189 | + private function renderEntityId(EntityId $entityId, ?string $role): array { |
|
190 | + return [Message::rawParam($this->addRole( |
|
191 | + $this->entityIdFormatter->formatEntityId($entityId), |
|
192 | 192 | $role |
193 | - ) ) ]; |
|
193 | + ))]; |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -198,8 +198,8 @@ discard block |
||
198 | 198 | * @param string|null $role one of the Role::* constants |
199 | 199 | * @return MessageParam[] list of parameters as accepted by Message::params() |
200 | 200 | */ |
201 | - private function renderEntityIdList( array $entityIdList, ?string $role ): array { |
|
202 | - return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] ); |
|
201 | + private function renderEntityIdList(array $entityIdList, ?string $role): array { |
|
202 | + return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -207,24 +207,24 @@ discard block |
||
207 | 207 | * @param string|null $role one of the Role::* constants |
208 | 208 | * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
209 | 209 | */ |
210 | - private function renderItemIdSnakValue( ItemIdSnakValue $value, ?string $role ): array { |
|
211 | - switch ( true ) { |
|
210 | + private function renderItemIdSnakValue(ItemIdSnakValue $value, ?string $role): array { |
|
211 | + switch (true) { |
|
212 | 212 | case $value->isValue(): |
213 | - return $this->renderEntityId( $value->getItemId(), $role ); |
|
213 | + return $this->renderEntityId($value->getItemId(), $role); |
|
214 | 214 | case $value->isSomeValue(): |
215 | - return [ Message::rawParam( $this->addRole( |
|
216 | - '<span class="wikibase-snakview-variation-somevaluesnak">' . |
|
217 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-somevalue' ) . |
|
215 | + return [Message::rawParam($this->addRole( |
|
216 | + '<span class="wikibase-snakview-variation-somevaluesnak">'. |
|
217 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-somevalue'). |
|
218 | 218 | '</span>', |
219 | 219 | $role |
220 | - ) ) ]; |
|
220 | + ))]; |
|
221 | 221 | case $value->isNoValue(): |
222 | - return [ Message::rawParam( $this->addRole( |
|
223 | - '<span class="wikibase-snakview-variation-novaluesnak">' . |
|
224 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-novalue' ) . |
|
222 | + return [Message::rawParam($this->addRole( |
|
223 | + '<span class="wikibase-snakview-variation-novaluesnak">'. |
|
224 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-novalue'). |
|
225 | 225 | '</span>', |
226 | 226 | $role |
227 | - ) ) ]; |
|
227 | + ))]; |
|
228 | 228 | default: |
229 | 229 | // @codeCoverageIgnoreStart |
230 | 230 | throw new LogicException( |
@@ -239,8 +239,8 @@ discard block |
||
239 | 239 | * @param string|null $role one of the Role::* constants |
240 | 240 | * @return MessageParam[] list of parameters as accepted by Message::params() |
241 | 241 | */ |
242 | - private function renderItemIdSnakValueList( array $valueList, ?string $role ): array { |
|
243 | - return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] ); |
|
242 | + private function renderItemIdSnakValueList(array $valueList, ?string $role): array { |
|
243 | + return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | * @param string|null $role one of the Role::* constants |
249 | 249 | * @return MessageParam[] list of parameters as accepted by Message::params() |
250 | 250 | */ |
251 | - private function renderDataValue( DataValue $dataValue, ?string $role ): array { |
|
252 | - return [ Message::rawParam( $this->addRole( |
|
253 | - $this->dataValueFormatter->format( $dataValue ), |
|
251 | + private function renderDataValue(DataValue $dataValue, ?string $role): array { |
|
252 | + return [Message::rawParam($this->addRole( |
|
253 | + $this->dataValueFormatter->format($dataValue), |
|
254 | 254 | $role |
255 | - ) ) ]; |
|
255 | + ))]; |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @param string|null $role one of the Role::* constants |
261 | 261 | * @return MessageParam[] list of parameters as accepted by Message::params() |
262 | 262 | */ |
263 | - private function renderDataValueType( string $dataValueType, ?string $role ): array { |
|
263 | + private function renderDataValueType(string $dataValueType, ?string $role): array { |
|
264 | 264 | $messageKeys = [ |
265 | 265 | 'string' => 'datatypes-type-string', |
266 | 266 | 'monolingualtext' => 'datatypes-type-monolingualtext', |
@@ -269,15 +269,15 @@ discard block |
||
269 | 269 | 'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid', |
270 | 270 | ]; |
271 | 271 | |
272 | - if ( array_key_exists( $dataValueType, $messageKeys ) ) { |
|
273 | - return [ Message::rawParam( $this->addRole( |
|
274 | - $this->msgEscaped( $messageKeys[$dataValueType] ), |
|
272 | + if (array_key_exists($dataValueType, $messageKeys)) { |
|
273 | + return [Message::rawParam($this->addRole( |
|
274 | + $this->msgEscaped($messageKeys[$dataValueType]), |
|
275 | 275 | $role |
276 | - ) ) ]; |
|
276 | + ))]; |
|
277 | 277 | } else { |
278 | 278 | // @codeCoverageIgnoreStart |
279 | 279 | throw new LogicException( |
280 | - 'Unknown data value type ' . $dataValueType |
|
280 | + 'Unknown data value type '.$dataValueType |
|
281 | 281 | ); |
282 | 282 | // @codeCoverageIgnoreEnd |
283 | 283 | } |
@@ -288,11 +288,11 @@ discard block |
||
288 | 288 | * @param string|null $role one of the Role::* constants |
289 | 289 | * @return MessageParam[] list of parameters as accepted by Message::params() |
290 | 290 | */ |
291 | - private function renderInlineCode( string $code, ?string $role ): array { |
|
292 | - return [ Message::rawParam( $this->addRole( |
|
293 | - '<code>' . htmlspecialchars( $code ) . '</code>', |
|
291 | + private function renderInlineCode(string $code, ?string $role): array { |
|
292 | + return [Message::rawParam($this->addRole( |
|
293 | + '<code>'.htmlspecialchars($code).'</code>', |
|
294 | 294 | $role |
295 | - ) ) ]; |
|
295 | + ))]; |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -300,8 +300,8 @@ discard block |
||
300 | 300 | * @param string|null $role one of the Role::* constants |
301 | 301 | * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
302 | 302 | */ |
303 | - private function renderConstraintScope( string $scope, ?string $role ): array { |
|
304 | - switch ( $scope ) { |
|
303 | + private function renderConstraintScope(string $scope, ?string $role): array { |
|
304 | + switch ($scope) { |
|
305 | 305 | case Context::TYPE_STATEMENT: |
306 | 306 | $itemId = $this->config->get( |
307 | 307 | 'WBQualityConstraintsConstraintCheckedOnMainValueId' |
@@ -321,10 +321,10 @@ discard block |
||
321 | 321 | // callers should never let this happen, but if it does happen, |
322 | 322 | // showing “unknown value” seems reasonable |
323 | 323 | // @codeCoverageIgnoreStart |
324 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
324 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
325 | 325 | // @codeCoverageIgnoreEnd |
326 | 326 | } |
327 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
327 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -332,8 +332,8 @@ discard block |
||
332 | 332 | * @param string|null $role one of the Role::* constants |
333 | 333 | * @return MessageParam[] list of parameters as accepted by Message::params() |
334 | 334 | */ |
335 | - private function renderConstraintScopeList( array $scopeList, ?string $role ): array { |
|
336 | - return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] ); |
|
335 | + private function renderConstraintScopeList(array $scopeList, ?string $role): array { |
|
336 | + return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -341,25 +341,25 @@ discard block |
||
341 | 341 | * @param string|null $role one of the Role::* constants |
342 | 342 | * @return MessageParam[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
343 | 343 | */ |
344 | - private function renderPropertyScope( string $scope, ?string $role ): array { |
|
345 | - switch ( $scope ) { |
|
344 | + private function renderPropertyScope(string $scope, ?string $role): array { |
|
345 | + switch ($scope) { |
|
346 | 346 | case Context::TYPE_STATEMENT: |
347 | - $itemId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
347 | + $itemId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
348 | 348 | break; |
349 | 349 | case Context::TYPE_QUALIFIER: |
350 | - $itemId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
350 | + $itemId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
351 | 351 | break; |
352 | 352 | case Context::TYPE_REFERENCE: |
353 | - $itemId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
353 | + $itemId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
354 | 354 | break; |
355 | 355 | default: |
356 | 356 | // callers should never let this happen, but if it does happen, |
357 | 357 | // showing “unknown value” seems reasonable |
358 | 358 | // @codeCoverageIgnoreStart |
359 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
359 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
360 | 360 | // @codeCoverageIgnoreEnd |
361 | 361 | } |
362 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
362 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -367,8 +367,8 @@ discard block |
||
367 | 367 | * @param string|null $role one of the Role::* constants |
368 | 368 | * @return MessageParam[] list of parameters as accepted by Message::params() |
369 | 369 | */ |
370 | - private function renderPropertyScopeList( array $scopeList, ?string $role ): array { |
|
371 | - return $this->renderList( $scopeList, $role, [ $this, 'renderPropertyScope' ] ); |
|
370 | + private function renderPropertyScopeList(array $scopeList, ?string $role): array { |
|
371 | + return $this->renderList($scopeList, $role, [$this, 'renderPropertyScope']); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -377,14 +377,14 @@ discard block |
||
377 | 377 | * @return MessageParam[] list of parameters as accepted by Message::params() |
378 | 378 | * @suppress PhanUnusedPrivateMethodParameter |
379 | 379 | */ |
380 | - private function renderLanguage( string $languageCode, ?string $role ): array { |
|
380 | + private function renderLanguage(string $languageCode, ?string $role): array { |
|
381 | 381 | return [ |
382 | 382 | // ::renderList (through ::renderLanguageList) requires 'raw' parameter |
383 | 383 | // so we effectively build Message::plaintextParam here |
384 | - Message::rawParam( htmlspecialchars( |
|
385 | - $this->languageNameUtils->getLanguageName( $languageCode, $this->userLanguageCode ) |
|
386 | - ) ), |
|
387 | - Message::plaintextParam( $languageCode ), |
|
384 | + Message::rawParam(htmlspecialchars( |
|
385 | + $this->languageNameUtils->getLanguageName($languageCode, $this->userLanguageCode) |
|
386 | + )), |
|
387 | + Message::plaintextParam($languageCode), |
|
388 | 388 | ]; |
389 | 389 | } |
390 | 390 | |
@@ -393,8 +393,8 @@ discard block |
||
393 | 393 | * @param string|null $role one of the Role::* constants |
394 | 394 | * @return MessageParam[] list of parameters as accepted by Message::params() |
395 | 395 | */ |
396 | - private function renderLanguageList( array $languageCodes, ?string $role ): array { |
|
397 | - return $this->renderList( $languageCodes, $role, [ $this, 'renderLanguage' ] ); |
|
396 | + private function renderLanguageList(array $languageCodes, ?string $role): array { |
|
397 | + return $this->renderList($languageCodes, $role, [$this, 'renderLanguage']); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\Specials; |
6 | 6 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | Config $config, |
92 | 92 | StatsFactory $statsFactory |
93 | 93 | ) { |
94 | - parent::__construct( 'ConstraintReport' ); |
|
94 | + parent::__construct('ConstraintReport'); |
|
95 | 95 | |
96 | 96 | $this->entityLookup = $entityLookup; |
97 | 97 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | |
112 | 112 | $this->violationMessageRenderer = $violationMessageRendererFactory->getViolationMessageRenderer( |
113 | 113 | $language, |
114 | - $languageFallbackChainFactory->newFromLanguage( $language ), |
|
114 | + $languageFallbackChainFactory->newFromLanguage($language), |
|
115 | 115 | $this->getContext() |
116 | 116 | ); |
117 | 117 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @inheritDoc |
146 | 146 | */ |
147 | 147 | public function getDescription() { |
148 | - return $this->msg( 'wbqc-constraintreport' ); |
|
148 | + return $this->msg('wbqc-constraintreport'); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -157,72 +157,72 @@ discard block |
||
157 | 157 | * @throws EntityIdParsingException |
158 | 158 | * @throws UnexpectedValueException |
159 | 159 | */ |
160 | - public function execute( $subPage ) { |
|
160 | + public function execute($subPage) { |
|
161 | 161 | $out = $this->getOutput(); |
162 | 162 | |
163 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
164 | - if ( $postRequest ) { |
|
163 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
164 | + if ($postRequest) { |
|
165 | 165 | try { |
166 | - $entityId = $this->entityIdParser->parse( $postRequest ); |
|
167 | - $out->redirect( $this->getPageTitle( $entityId->getSerialization() )->getLocalURL() ); |
|
166 | + $entityId = $this->entityIdParser->parse($postRequest); |
|
167 | + $out->redirect($this->getPageTitle($entityId->getSerialization())->getLocalURL()); |
|
168 | 168 | return; |
169 | - } catch ( EntityIdParsingException ) { |
|
169 | + } catch (EntityIdParsingException) { |
|
170 | 170 | // fall through, error is shown later |
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
174 | 174 | $out->enableOOUI(); |
175 | - $out->addModules( $this->getModules() ); |
|
175 | + $out->addModules($this->getModules()); |
|
176 | 176 | |
177 | 177 | $this->setHeaders(); |
178 | 178 | |
179 | - $out->addHTML( $this->getExplanationText() ); |
|
179 | + $out->addHTML($this->getExplanationText()); |
|
180 | 180 | $this->buildEntityIdForm(); |
181 | 181 | |
182 | - if ( $postRequest ) { |
|
182 | + if ($postRequest) { |
|
183 | 183 | // must be an invalid entity ID (otherwise we would have redirected and returned above) |
184 | 184 | $out->addHTML( |
185 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
185 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
186 | 186 | ); |
187 | 187 | return; |
188 | 188 | } |
189 | 189 | |
190 | - if ( !$subPage ) { |
|
190 | + if (!$subPage) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | 193 | |
194 | 194 | try { |
195 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
196 | - } catch ( EntityIdParsingException ) { |
|
195 | + $entityId = $this->entityIdParser->parse($subPage); |
|
196 | + } catch (EntityIdParsingException) { |
|
197 | 197 | $out->addHTML( |
198 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
198 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
199 | 199 | ); |
200 | 200 | return; |
201 | 201 | } |
202 | 202 | |
203 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
203 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
204 | 204 | $out->addHTML( |
205 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
205 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
206 | 206 | ); |
207 | 207 | return; |
208 | 208 | } |
209 | 209 | |
210 | 210 | $baseKey = 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck'; |
211 | - $metric = $this->statsFactory->getCounter( 'special_constraint_report_execute_check_total' ); |
|
212 | - $metric->copyToStatsdAt( $baseKey )->increment(); |
|
213 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
211 | + $metric = $this->statsFactory->getCounter('special_constraint_report_execute_check_total'); |
|
212 | + $metric->copyToStatsdAt($baseKey)->increment(); |
|
213 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
214 | 214 | |
215 | - if ( !$results ) { |
|
216 | - $out->addHTML( $this->buildResultHeader( $entityId ) . |
|
217 | - $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
215 | + if (!$results) { |
|
216 | + $out->addHTML($this->buildResultHeader($entityId). |
|
217 | + $this->buildNotice('wbqc-constraintreport-empty-result') |
|
218 | 218 | ); |
219 | 219 | return; |
220 | 220 | } |
221 | 221 | |
222 | 222 | $out->addHTML( |
223 | - $this->buildResultHeader( $entityId ) |
|
224 | - . $this->buildSummary( $results ) |
|
225 | - . $this->buildResultTable( $entityId, $results ) |
|
223 | + $this->buildResultHeader($entityId) |
|
224 | + . $this->buildSummary($results) |
|
225 | + . $this->buildResultTable($entityId, $results) |
|
226 | 226 | ); |
227 | 227 | } |
228 | 228 | |
@@ -237,15 +237,15 @@ discard block |
||
237 | 237 | 'name' => 'entityid', |
238 | 238 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
239 | 239 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
240 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->text(), |
|
240 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->text(), |
|
241 | 241 | 'required' => true, |
242 | 242 | ], |
243 | 243 | ]; |
244 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), |
|
244 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), |
|
245 | 245 | 'wbqc-constraintreport-form' |
246 | 246 | ); |
247 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->text() ); |
|
248 | - $htmlForm->setSubmitCallback( static fn () => false ); |
|
247 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->text()); |
|
248 | + $htmlForm->setSubmitCallback(static fn () => false); |
|
249 | 249 | $htmlForm->show(); |
250 | 250 | } |
251 | 251 | |
@@ -259,16 +259,16 @@ discard block |
||
259 | 259 | * |
260 | 260 | * @return string HTML |
261 | 261 | */ |
262 | - private function buildNotice( string $messageKey, bool $error = false ): string { |
|
263 | - $cssClasses = [ 'wbqc-constraintreport-notice' ]; |
|
264 | - if ( $error ) { |
|
262 | + private function buildNotice(string $messageKey, bool $error = false): string { |
|
263 | + $cssClasses = ['wbqc-constraintreport-notice']; |
|
264 | + if ($error) { |
|
265 | 265 | $cssClasses[] = ' wbqc-constraintreport-notice-error'; |
266 | 266 | } |
267 | 267 | |
268 | 268 | return Html::element( |
269 | 269 | 'p', |
270 | - [ 'class' => $cssClasses ], |
|
271 | - $this->msg( $messageKey )->text() |
|
270 | + ['class' => $cssClasses], |
|
271 | + $this->msg($messageKey)->text() |
|
272 | 272 | ); |
273 | 273 | } |
274 | 274 | |
@@ -278,16 +278,16 @@ discard block |
||
278 | 278 | private function getExplanationText(): string { |
279 | 279 | return Html::rawElement( |
280 | 280 | 'div', |
281 | - [ 'class' => 'wbqc-explanation' ], |
|
281 | + ['class' => 'wbqc-explanation'], |
|
282 | 282 | Html::element( |
283 | 283 | 'p', |
284 | 284 | [], |
285 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->text() |
|
285 | + $this->msg('wbqc-constraintreport-explanation-part-one')->text() |
|
286 | 286 | ) |
287 | 287 | . Html::element( |
288 | 288 | 'p', |
289 | 289 | [], |
290 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->text() |
|
290 | + $this->msg('wbqc-constraintreport-explanation-part-two')->text() |
|
291 | 291 | ) |
292 | 292 | ); |
293 | 293 | } |
@@ -298,31 +298,31 @@ discard block |
||
298 | 298 | * |
299 | 299 | * @return string HTML |
300 | 300 | */ |
301 | - private function buildResultTable( EntityId $entityId, array $results ): string { |
|
301 | + private function buildResultTable(EntityId $entityId, array $results): string { |
|
302 | 302 | // Set table headers |
303 | 303 | $table = new HtmlTableBuilder( |
304 | 304 | [ |
305 | 305 | new HtmlTableHeaderBuilder( |
306 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->text(), |
|
306 | + $this->msg('wbqc-constraintreport-result-table-header-status')->text(), |
|
307 | 307 | true |
308 | 308 | ), |
309 | 309 | new HtmlTableHeaderBuilder( |
310 | - $this->msg( 'wbqc-constraintreport-result-table-header-property' )->text(), |
|
310 | + $this->msg('wbqc-constraintreport-result-table-header-property')->text(), |
|
311 | 311 | true |
312 | 312 | ), |
313 | 313 | new HtmlTableHeaderBuilder( |
314 | - $this->msg( 'wbqc-constraintreport-result-table-header-message' )->text(), |
|
314 | + $this->msg('wbqc-constraintreport-result-table-header-message')->text(), |
|
315 | 315 | true |
316 | 316 | ), |
317 | 317 | new HtmlTableHeaderBuilder( |
318 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->text(), |
|
318 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->text(), |
|
319 | 319 | true |
320 | 320 | ), |
321 | 321 | ] |
322 | 322 | ); |
323 | 323 | |
324 | - foreach ( $results as $result ) { |
|
325 | - $this->appendToResultTable( $table, $entityId, $result ); |
|
324 | + foreach ($results as $result) { |
|
325 | + $this->appendToResultTable($table, $entityId, $result); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | return $table->toHtml(); |
@@ -334,35 +334,35 @@ discard block |
||
334 | 334 | CheckResult $result |
335 | 335 | ): void { |
336 | 336 | $message = $result->getMessage(); |
337 | - if ( !$message ) { |
|
337 | + if (!$message) { |
|
338 | 338 | // no row for this result |
339 | 339 | return; |
340 | 340 | } |
341 | 341 | |
342 | 342 | // Status column |
343 | - $statusColumn = $this->formatStatus( $result->getStatus() ); |
|
343 | + $statusColumn = $this->formatStatus($result->getStatus()); |
|
344 | 344 | |
345 | 345 | // Property column |
346 | - $propertyId = new NumericPropertyId( $result->getContextCursor()->getSnakPropertyId() ); |
|
346 | + $propertyId = new NumericPropertyId($result->getContextCursor()->getSnakPropertyId()); |
|
347 | 347 | $propertyColumn = $this->getClaimLink( |
348 | 348 | $entityId, |
349 | 349 | $propertyId, |
350 | - $this->entityIdLabelFormatter->formatEntityId( $propertyId ) |
|
350 | + $this->entityIdLabelFormatter->formatEntityId($propertyId) |
|
351 | 351 | ); |
352 | 352 | |
353 | 353 | // Message column |
354 | - $messageColumn = $this->violationMessageRenderer->render( $message ); |
|
354 | + $messageColumn = $this->violationMessageRenderer->render($message); |
|
355 | 355 | |
356 | 356 | // Constraint column |
357 | 357 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
358 | 358 | try { |
359 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
360 | - } catch ( InvalidArgumentException ) { |
|
361 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
359 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
360 | + } catch (InvalidArgumentException) { |
|
361 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
362 | 362 | } |
363 | 363 | $constraintColumn = $this->getClaimLink( |
364 | 364 | $propertyId, |
365 | - new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
365 | + new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
366 | 366 | $constraintTypeLabel |
367 | 367 | ); |
368 | 368 | |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | $table->appendRow( |
371 | 371 | [ |
372 | 372 | new HtmlTableCellBuilder( |
373 | - new HtmlArmor( $statusColumn ) |
|
373 | + new HtmlArmor($statusColumn) |
|
374 | 374 | ), |
375 | 375 | new HtmlTableCellBuilder( |
376 | - new HtmlArmor( $propertyColumn ) |
|
376 | + new HtmlArmor($propertyColumn) |
|
377 | 377 | ), |
378 | 378 | new HtmlTableCellBuilder( |
379 | - new HtmlArmor( $messageColumn ) |
|
379 | + new HtmlArmor($messageColumn) |
|
380 | 380 | ), |
381 | 381 | new HtmlTableCellBuilder( |
382 | - new HtmlArmor( $constraintColumn ) |
|
382 | + new HtmlArmor($constraintColumn) |
|
383 | 383 | ), |
384 | 384 | ] |
385 | 385 | ); |
@@ -392,15 +392,15 @@ discard block |
||
392 | 392 | * |
393 | 393 | * @return string HTML |
394 | 394 | */ |
395 | - protected function buildResultHeader( EntityId $entityId ): string { |
|
395 | + protected function buildResultHeader(EntityId $entityId): string { |
|
396 | 396 | return Html::rawElement( |
397 | 397 | 'h3', |
398 | 398 | [], |
399 | - $this->msg( 'wbqc-constraintreport-result-headline' )->escaped() . |
|
400 | - $this->msg( 'word-separator' )->escaped() . |
|
401 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ) . |
|
402 | - $this->msg( 'word-separator' )->escaped() . |
|
403 | - $this->msg( 'parentheses', $entityId->getSerialization() )->escaped() |
|
399 | + $this->msg('wbqc-constraintreport-result-headline')->escaped(). |
|
400 | + $this->msg('word-separator')->escaped(). |
|
401 | + $this->entityIdLinkFormatter->formatEntityId($entityId). |
|
402 | + $this->msg('word-separator')->escaped(). |
|
403 | + $this->msg('parentheses', $entityId->getSerialization())->escaped() |
|
404 | 404 | ); |
405 | 405 | } |
406 | 406 | |
@@ -411,23 +411,23 @@ discard block |
||
411 | 411 | * |
412 | 412 | * @return string HTML |
413 | 413 | */ |
414 | - protected function buildSummary( array $results ): string { |
|
414 | + protected function buildSummary(array $results): string { |
|
415 | 415 | $statuses = []; |
416 | - foreach ( $results as $result ) { |
|
417 | - $status = strtolower( $result->getStatus() ); |
|
416 | + foreach ($results as $result) { |
|
417 | + $status = strtolower($result->getStatus()); |
|
418 | 418 | $statuses[$status] ??= 0; |
419 | 419 | $statuses[$status]++; |
420 | 420 | } |
421 | 421 | |
422 | 422 | $statusElements = []; |
423 | - foreach ( $statuses as $status => $count ) { |
|
424 | - $statusElements[] = $this->formatStatus( $status ) . |
|
425 | - $this->msg( 'colon-separator' )->escaped() . |
|
426 | - htmlspecialchars( $this->getLanguage()->formatNum( $count ) ); |
|
423 | + foreach ($statuses as $status => $count) { |
|
424 | + $statusElements[] = $this->formatStatus($status). |
|
425 | + $this->msg('colon-separator')->escaped(). |
|
426 | + htmlspecialchars($this->getLanguage()->formatNum($count)); |
|
427 | 427 | } |
428 | 428 | |
429 | - return Html::rawElement( 'p', [], |
|
430 | - implode( $this->msg( 'comma-separator' )->escaped(), $statusElements ) |
|
429 | + return Html::rawElement('p', [], |
|
430 | + implode($this->msg('comma-separator')->escaped(), $statusElements) |
|
431 | 431 | ); |
432 | 432 | } |
433 | 433 | |
@@ -440,8 +440,8 @@ discard block |
||
440 | 440 | * |
441 | 441 | * @return string HTML |
442 | 442 | */ |
443 | - private function formatStatus( string $status ): string { |
|
444 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
443 | + private function formatStatus(string $status): string { |
|
444 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
445 | 445 | $statusIcons = [ |
446 | 446 | CheckResult::STATUS_SUGGESTION => [ |
447 | 447 | 'icon' => 'suggestion-constraint-violation', |
@@ -458,21 +458,21 @@ discard block |
||
458 | 458 | ], |
459 | 459 | ]; |
460 | 460 | |
461 | - if ( array_key_exists( $status, $statusIcons ) ) { |
|
462 | - $iconHtml = new IconWidget( $statusIcons[$status] ) . |
|
463 | - $this->msg( 'word-separator' )->escaped(); |
|
461 | + if (array_key_exists($status, $statusIcons)) { |
|
462 | + $iconHtml = new IconWidget($statusIcons[$status]). |
|
463 | + $this->msg('word-separator')->escaped(); |
|
464 | 464 | } else { |
465 | 465 | $iconHtml = ''; |
466 | 466 | } |
467 | 467 | |
468 | - $labelWidget = new LabelWidget( [ 'label' => $this->msg( $messageName )->text() ] ); |
|
468 | + $labelWidget = new LabelWidget(['label' => $this->msg($messageName)->text()]); |
|
469 | 469 | |
470 | 470 | return Html::rawElement( |
471 | 471 | 'span', |
472 | 472 | [ |
473 | - 'class' => 'wbqc-status wbqc-status-' . $status, |
|
473 | + 'class' => 'wbqc-status wbqc-status-'.$status, |
|
474 | 474 | ], |
475 | - $iconHtml . $labelWidget |
|
475 | + $iconHtml.$labelWidget |
|
476 | 476 | ); |
477 | 477 | } |
478 | 478 | |
@@ -490,10 +490,10 @@ discard block |
||
490 | 490 | NumericPropertyId $propertyId, |
491 | 491 | string $text |
492 | 492 | ): string { |
493 | - $title = clone $this->entityTitleLookup->getTitleForId( $entityId ); |
|
494 | - $title->setFragment( $propertyId->getSerialization() ); |
|
493 | + $title = clone $this->entityTitleLookup->getTitleForId($entityId); |
|
494 | + $title->setFragment($propertyId->getSerialization()); |
|
495 | 495 | |
496 | - return Html::rawElement( 'a', |
|
496 | + return Html::rawElement('a', |
|
497 | 497 | [ |
498 | 498 | 'href' => $title->getLinkURL(), |
499 | 499 | 'target' => '_blank', |