@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( function_exists( 'wfLoadExtension' ) ) { |
|
4 | - wfLoadExtension( 'WikibaseQualityConstraints', __DIR__ . '/extension.json' ); |
|
3 | +if (function_exists('wfLoadExtension')) { |
|
4 | + wfLoadExtension('WikibaseQualityConstraints', __DIR__.'/extension.json'); |
|
5 | 5 | // Keep i18n globals so mergeMessageFileList.php doesn't break |
6 | - $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__ . '/i18n'; |
|
7 | - $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__ . '/WikibaseQualityConstraints.alias.php'; |
|
6 | + $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__.'/i18n'; |
|
7 | + $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__.'/WikibaseQualityConstraints.alias.php'; |
|
8 | 8 | /* wfWarn( |
9 | 9 | 'Deprecated PHP entry point used for WikibaseQualityConstraints extension. ' . |
10 | 10 | 'Please use wfLoadExtension instead, ' . |
@@ -12,5 +12,5 @@ discard block |
||
12 | 12 | ); */ |
13 | 13 | return; |
14 | 14 | } else { |
15 | - die( 'This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+' ); |
|
15 | + die('This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+'); |
|
16 | 16 | } |
@@ -10,5 +10,5 @@ |
||
10 | 10 | |
11 | 11 | /** English (English) */ |
12 | 12 | $specialPageAliases['en'] = [ |
13 | - 'ConstraintReport' => [ 'ConstraintReport', 'Constraint Report' ], |
|
13 | + 'ConstraintReport' => ['ConstraintReport', 'Constraint Report'], |
|
14 | 14 | ]; |
@@ -119,8 +119,8 @@ |
||
119 | 119 | * for quantity values, the difference is the numerical difference between the quantities, |
120 | 120 | * after attempting normalization of each side. |
121 | 121 | * |
122 | - * @param TimeValue|QuantityValue|UnboundedQuantityValue $minuend |
|
123 | - * @param TimeValue|QuantityValue|UnboundedQuantityValue $subtrahend |
|
122 | + * @param DataValue $minuend |
|
123 | + * @param DataValue $subtrahend |
|
124 | 124 | * |
125 | 125 | * @throws InvalidArgumentException if the values do not both have the same, supported data value type |
126 | 126 | * @return UnboundedQuantityValue |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | UnitConverter $unitConverter = null |
52 | 52 | ) { |
53 | 53 | $this->config = $config; |
54 | - $this->timeParser = ( new TimeParserFactory() )->getTimeParser(); |
|
54 | + $this->timeParser = (new TimeParserFactory())->getTimeParser(); |
|
55 | 55 | $this->timeCalculator = new TimeValueCalculator(); |
56 | 56 | $this->timeValueComparer = new TimeValueComparer(); |
57 | 57 | $this->unitConverter = $unitConverter; |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | * @param UnboundedQuantityValue $value |
62 | 62 | * @return UnboundedQuantityValue $value converted to standard units if possible, otherwise unchanged $value. |
63 | 63 | */ |
64 | - private function standardize( UnboundedQuantityValue $value ) { |
|
65 | - if ( $this->unitConverter !== null ) { |
|
66 | - $standard = $this->unitConverter->toStandardUnits( $value ); |
|
67 | - if ( $standard !== null ) { |
|
64 | + private function standardize(UnboundedQuantityValue $value) { |
|
65 | + if ($this->unitConverter !== null) { |
|
66 | + $standard = $this->unitConverter->toStandardUnits($value); |
|
67 | + if ($standard !== null) { |
|
68 | 68 | return $standard; |
69 | 69 | } else { |
70 | 70 | return $value; |
@@ -86,29 +86,29 @@ discard block |
||
86 | 86 | * when $lhs is respectively less than, equal to, or greater than $rhs. |
87 | 87 | * (In other words, just like the “spaceship” operator <=>.) |
88 | 88 | */ |
89 | - public function getComparison( DataValue $lhs = null, DataValue $rhs = null ) { |
|
90 | - if ( $lhs === null || $rhs === null ) { |
|
89 | + public function getComparison(DataValue $lhs = null, DataValue $rhs = null) { |
|
90 | + if ($lhs === null || $rhs === null) { |
|
91 | 91 | return 0; |
92 | 92 | } |
93 | 93 | |
94 | - if ( $lhs->getType() !== $rhs->getType() ) { |
|
95 | - throw new InvalidArgumentException( 'Different data value types' ); |
|
94 | + if ($lhs->getType() !== $rhs->getType()) { |
|
95 | + throw new InvalidArgumentException('Different data value types'); |
|
96 | 96 | } |
97 | 97 | |
98 | - switch ( $lhs->getType() ) { |
|
98 | + switch ($lhs->getType()) { |
|
99 | 99 | case 'time': |
100 | 100 | /** @var TimeValue $lhs */ |
101 | 101 | /** @var TimeValue $rhs */ |
102 | - return $this->timeValueComparer->getComparison( $lhs, $rhs ); |
|
102 | + return $this->timeValueComparer->getComparison($lhs, $rhs); |
|
103 | 103 | case 'quantity': |
104 | 104 | /** @var QuantityValue|UnboundedQuantityValue $lhs */ |
105 | 105 | /** @var QuantityValue|UnboundedQuantityValue $rhs */ |
106 | - $lhsStandard = $this->standardize( $lhs ); |
|
107 | - $rhsStandard = $this->standardize( $rhs ); |
|
108 | - return $lhsStandard->getAmount()->compare( $rhsStandard->getAmount() ); |
|
106 | + $lhsStandard = $this->standardize($lhs); |
|
107 | + $rhsStandard = $this->standardize($rhs); |
|
108 | + return $lhsStandard->getAmount()->compare($rhsStandard->getAmount()); |
|
109 | 109 | } |
110 | 110 | |
111 | - throw new InvalidArgumentException( 'Unsupported data value type' ); |
|
111 | + throw new InvalidArgumentException('Unsupported data value type'); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -123,71 +123,71 @@ discard block |
||
123 | 123 | * @throws InvalidArgumentException if the values do not both have the same, supported data value type |
124 | 124 | * @return UnboundedQuantityValue |
125 | 125 | */ |
126 | - public function getDifference( DataValue $minuend, DataValue $subtrahend ) { |
|
127 | - if ( $minuend->getType() === 'time' && $subtrahend->getType() === 'time' ) { |
|
128 | - $minuendSeconds = $this->timeCalculator->getTimestamp( $minuend ); |
|
129 | - $subtrahendSeconds = $this->timeCalculator->getTimestamp( $subtrahend ); |
|
126 | + public function getDifference(DataValue $minuend, DataValue $subtrahend) { |
|
127 | + if ($minuend->getType() === 'time' && $subtrahend->getType() === 'time') { |
|
128 | + $minuendSeconds = $this->timeCalculator->getTimestamp($minuend); |
|
129 | + $subtrahendSeconds = $this->timeCalculator->getTimestamp($subtrahend); |
|
130 | 130 | return UnboundedQuantityValue::newFromNumber( |
131 | 131 | $minuendSeconds - $subtrahendSeconds, |
132 | - $this->config->get( 'WBQualityConstraintsSecondUnit' ) |
|
132 | + $this->config->get('WBQualityConstraintsSecondUnit') |
|
133 | 133 | ); |
134 | 134 | } |
135 | - if ( $minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity' ) { |
|
136 | - $minuendStandard = $this->standardize( $minuend ); |
|
137 | - $subtrahendStandard = $this->standardize( $subtrahend ); |
|
135 | + if ($minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity') { |
|
136 | + $minuendStandard = $this->standardize($minuend); |
|
137 | + $subtrahendStandard = $this->standardize($subtrahend); |
|
138 | 138 | $minuendValue = $minuendStandard->getAmount()->getValueFloat(); |
139 | 139 | $subtrahendValue = $subtrahendStandard->getAmount()->getValueFloat(); |
140 | 140 | $diff = $minuendValue - $subtrahendValue; |
141 | 141 | // we don’t check whether both quantities have the same standard unit – |
142 | 142 | // that’s the job of a different constraint type, Units (T164372) |
143 | - return UnboundedQuantityValue::newFromNumber( $diff, $minuendStandard->getUnit() ); |
|
143 | + return UnboundedQuantityValue::newFromNumber($diff, $minuendStandard->getUnit()); |
|
144 | 144 | } |
145 | 145 | |
146 | - throw new InvalidArgumentException( 'Unsupported or different data value types' ); |
|
146 | + throw new InvalidArgumentException('Unsupported or different data value types'); |
|
147 | 147 | } |
148 | 148 | |
149 | - public function getDifferenceInYears( TimeValue $minuend, TimeValue $subtrahend ) { |
|
150 | - if ( !preg_match( '/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches ) || |
|
151 | - !preg_match( '/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches ) |
|
149 | + public function getDifferenceInYears(TimeValue $minuend, TimeValue $subtrahend) { |
|
150 | + if (!preg_match('/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches) || |
|
151 | + !preg_match('/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches) |
|
152 | 152 | ) { |
153 | - throw new InvalidArgumentException( 'TimeValue::getTime() did not match expected format' ); |
|
153 | + throw new InvalidArgumentException('TimeValue::getTime() did not match expected format'); |
|
154 | 154 | } |
155 | - $minuendYear = (float)$minuendMatches[1]; |
|
156 | - $subtrahendYear = (float)$subtrahendMatches[1]; |
|
155 | + $minuendYear = (float) $minuendMatches[1]; |
|
156 | + $subtrahendYear = (float) $subtrahendMatches[1]; |
|
157 | 157 | $minuendRest = $minuendMatches[2]; |
158 | 158 | $subtrahendRest = $subtrahendMatches[2]; |
159 | 159 | |
160 | 160 | // calculate difference of years |
161 | 161 | $diff = $minuendYear - $subtrahendYear; |
162 | - if ( $minuendYear > 0.0 && $subtrahendYear < 0.0 ) { |
|
162 | + if ($minuendYear > 0.0 && $subtrahendYear < 0.0) { |
|
163 | 163 | $diff -= 1.0; // there is no year 0, remove it from difference |
164 | - } elseif ( $minuendYear < 0.0 && $subtrahendYear > 0.0 ) { |
|
164 | + } elseif ($minuendYear < 0.0 && $subtrahendYear > 0.0) { |
|
165 | 165 | $diff -= -1.0; // there is no year 0, remove it from negative difference |
166 | 166 | } |
167 | 167 | |
168 | 168 | // adjust for date within year by parsing the month-day part within the same year |
169 | - $minuendDateValue = $this->timeParser->parse( '+0000000000001970-' . $minuendRest ); |
|
170 | - $subtrahendDateValue = $this->timeParser->parse( '+0000000000001970-' . $subtrahendRest ); |
|
171 | - $minuendDateSeconds = $this->timeCalculator->getTimestamp( $minuendDateValue ); |
|
172 | - $subtrahendDateSeconds = $this->timeCalculator->getTimestamp( $subtrahendDateValue ); |
|
173 | - if ( $minuendDateSeconds < $subtrahendDateSeconds ) { |
|
169 | + $minuendDateValue = $this->timeParser->parse('+0000000000001970-'.$minuendRest); |
|
170 | + $subtrahendDateValue = $this->timeParser->parse('+0000000000001970-'.$subtrahendRest); |
|
171 | + $minuendDateSeconds = $this->timeCalculator->getTimestamp($minuendDateValue); |
|
172 | + $subtrahendDateSeconds = $this->timeCalculator->getTimestamp($subtrahendDateValue); |
|
173 | + if ($minuendDateSeconds < $subtrahendDateSeconds) { |
|
174 | 174 | // difference in the last year is actually less than one full year |
175 | 175 | // e. g. 1975-03-01 - 1974-09-01 is just six months |
176 | 176 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
177 | 177 | $diff -= 0.5; |
178 | - } elseif ( $minuendDateSeconds > $subtrahendDateSeconds ) { |
|
178 | + } elseif ($minuendDateSeconds > $subtrahendDateSeconds) { |
|
179 | 179 | // difference in the last year is actually more than one full year |
180 | 180 | // e. g. 1975-09-01 - 1974-03-01 is 18 months |
181 | 181 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
182 | 182 | $diff += 0.5; |
183 | 183 | } |
184 | 184 | |
185 | - $unit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
186 | - return UnboundedQuantityValue::newFromNumber( $diff, $unit ); |
|
185 | + $unit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
186 | + return UnboundedQuantityValue::newFromNumber($diff, $unit); |
|
187 | 187 | } |
188 | 188 | |
189 | - public function isFutureTime( TimeValue $timeValue ) { |
|
190 | - return $this->timeValueComparer->isFutureTime( $timeValue ); |
|
189 | + public function isFutureTime(TimeValue $timeValue) { |
|
190 | + return $this->timeValueComparer->isFutureTime($timeValue); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | } |
@@ -162,7 +162,7 @@ |
||
162 | 162 | /** |
163 | 163 | * Returns array of modules that should be added |
164 | 164 | * |
165 | - * @return array |
|
165 | + * @return string[] |
|
166 | 166 | */ |
167 | 167 | private function getModules() { |
168 | 168 | return [ 'SpecialConstraintReportPage' ]; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | Config $config, |
135 | 135 | IBufferingStatsdDataFactory $dataFactory |
136 | 136 | ) { |
137 | - parent::__construct( 'ConstraintReport' ); |
|
137 | + parent::__construct('ConstraintReport'); |
|
138 | 138 | |
139 | 139 | $this->entityLookup = $entityLookup; |
140 | 140 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -143,13 +143,13 @@ discard block |
||
143 | 143 | $language = $this->getLanguage(); |
144 | 144 | |
145 | 145 | $formatterOptions = new FormatterOptions(); |
146 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
146 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
147 | 147 | $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter( |
148 | 148 | SnakFormatter::FORMAT_HTML, |
149 | 149 | $formatterOptions |
150 | 150 | ); |
151 | 151 | |
152 | - $labelLookup = $fallbackLabelDescLookupFactory->newLabelDescriptionLookup( $language ); |
|
152 | + $labelLookup = $fallbackLabelDescLookupFactory->newLabelDescriptionLookup($language); |
|
153 | 153 | |
154 | 154 | $this->entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( |
155 | 155 | $labelLookup |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @return array |
183 | 183 | */ |
184 | 184 | private function getModules() { |
185 | - return [ 'SpecialConstraintReportPage' ]; |
|
185 | + return ['SpecialConstraintReportPage']; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @return string |
201 | 201 | */ |
202 | 202 | public function getDescription() { |
203 | - return $this->msg( 'wbqc-constraintreport' )->escaped(); |
|
203 | + return $this->msg('wbqc-constraintreport')->escaped(); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -212,42 +212,42 @@ discard block |
||
212 | 212 | * @throws EntityIdParsingException |
213 | 213 | * @throws UnexpectedValueException |
214 | 214 | */ |
215 | - public function execute( $subPage ) { |
|
215 | + public function execute($subPage) { |
|
216 | 216 | $out = $this->getOutput(); |
217 | 217 | |
218 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
219 | - if ( $postRequest ) { |
|
220 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
218 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
219 | + if ($postRequest) { |
|
220 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
221 | 221 | return; |
222 | 222 | } |
223 | 223 | |
224 | - $out->addModules( $this->getModules() ); |
|
224 | + $out->addModules($this->getModules()); |
|
225 | 225 | |
226 | 226 | $this->setHeaders(); |
227 | 227 | |
228 | - $out->addHTML( $this->getExplanationText() ); |
|
228 | + $out->addHTML($this->getExplanationText()); |
|
229 | 229 | $this->buildEntityIdForm(); |
230 | 230 | |
231 | - if ( !$subPage ) { |
|
231 | + if (!$subPage) { |
|
232 | 232 | return; |
233 | 233 | } |
234 | 234 | |
235 | - if ( !is_string( $subPage ) ) { |
|
236 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
235 | + if (!is_string($subPage)) { |
|
236 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | try { |
240 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
241 | - } catch ( EntityIdParsingException $e ) { |
|
240 | + $entityId = $this->entityIdParser->parse($subPage); |
|
241 | + } catch (EntityIdParsingException $e) { |
|
242 | 242 | $out->addHTML( |
243 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
243 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
244 | 244 | ); |
245 | 245 | return; |
246 | 246 | } |
247 | 247 | |
248 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
248 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
249 | 249 | $out->addHTML( |
250 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
250 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
251 | 251 | ); |
252 | 252 | return; |
253 | 253 | } |
@@ -255,18 +255,18 @@ discard block |
||
255 | 255 | $this->dataFactory->increment( |
256 | 256 | 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck' |
257 | 257 | ); |
258 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
258 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
259 | 259 | |
260 | - if ( count( $results ) > 0 ) { |
|
260 | + if (count($results) > 0) { |
|
261 | 261 | $out->addHTML( |
262 | - $this->buildResultHeader( $entityId ) |
|
263 | - . $this->buildSummary( $results ) |
|
264 | - . $this->buildResultTable( $entityId, $results ) |
|
262 | + $this->buildResultHeader($entityId) |
|
263 | + . $this->buildSummary($results) |
|
264 | + . $this->buildResultTable($entityId, $results) |
|
265 | 265 | ); |
266 | 266 | } else { |
267 | 267 | $out->addHTML( |
268 | - $this->buildResultHeader( $entityId ) |
|
269 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
268 | + $this->buildResultHeader($entityId) |
|
269 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
270 | 270 | ); |
271 | 271 | } |
272 | 272 | } |
@@ -282,15 +282,15 @@ discard block |
||
282 | 282 | 'name' => 'entityid', |
283 | 283 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
284 | 284 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
285 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped() |
|
285 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped() |
|
286 | 286 | ] |
287 | 287 | ]; |
288 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
289 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
290 | - $htmlForm->setSubmitCallback( function() { |
|
288 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
289 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
290 | + $htmlForm->setSubmitCallback(function() { |
|
291 | 291 | return false; |
292 | 292 | } ); |
293 | - $htmlForm->setMethod( 'post' ); |
|
293 | + $htmlForm->setMethod('post'); |
|
294 | 294 | $htmlForm->show(); |
295 | 295 | } |
296 | 296 | |
@@ -304,16 +304,16 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return string HTML |
306 | 306 | */ |
307 | - private function buildNotice( $messageKey, $error = false ) { |
|
308 | - if ( !is_string( $messageKey ) ) { |
|
309 | - throw new InvalidArgumentException( '$message must be string.' ); |
|
307 | + private function buildNotice($messageKey, $error = false) { |
|
308 | + if (!is_string($messageKey)) { |
|
309 | + throw new InvalidArgumentException('$message must be string.'); |
|
310 | 310 | } |
311 | - if ( !is_bool( $error ) ) { |
|
312 | - throw new InvalidArgumentException( '$error must be bool.' ); |
|
311 | + if (!is_bool($error)) { |
|
312 | + throw new InvalidArgumentException('$error must be bool.'); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | $cssClasses = 'wbqc-constraintreport-notice'; |
316 | - if ( $error ) { |
|
316 | + if ($error) { |
|
317 | 317 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
318 | 318 | } |
319 | 319 | |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | [ |
323 | 323 | 'class' => $cssClasses |
324 | 324 | ], |
325 | - $this->msg( $messageKey )->escaped() |
|
325 | + $this->msg($messageKey)->escaped() |
|
326 | 326 | ); |
327 | 327 | } |
328 | 328 | |
@@ -332,16 +332,16 @@ discard block |
||
332 | 332 | private function getExplanationText() { |
333 | 333 | return Html::rawElement( |
334 | 334 | 'div', |
335 | - [ 'class' => 'wbqc-explanation' ], |
|
335 | + ['class' => 'wbqc-explanation'], |
|
336 | 336 | Html::rawElement( |
337 | 337 | 'p', |
338 | 338 | [], |
339 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
339 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
340 | 340 | ) |
341 | 341 | . Html::rawElement( |
342 | 342 | 'p', |
343 | 343 | [], |
344 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
344 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
345 | 345 | ) |
346 | 346 | ); |
347 | 347 | } |
@@ -352,82 +352,81 @@ discard block |
||
352 | 352 | * |
353 | 353 | * @return string HTML |
354 | 354 | */ |
355 | - private function buildResultTable( EntityId $entityId, array $results ) { |
|
355 | + private function buildResultTable(EntityId $entityId, array $results) { |
|
356 | 356 | // Set table headers |
357 | 357 | $table = new HtmlTableBuilder( |
358 | 358 | [ |
359 | 359 | new HtmlTableHeaderBuilder( |
360 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(), |
|
360 | + $this->msg('wbqc-constraintreport-result-table-header-status')->escaped(), |
|
361 | 361 | true |
362 | 362 | ), |
363 | 363 | new HtmlTableHeaderBuilder( |
364 | - $this->msg( 'wbqc-constraintreport-result-table-header-claim' )->escaped(), |
|
364 | + $this->msg('wbqc-constraintreport-result-table-header-claim')->escaped(), |
|
365 | 365 | true |
366 | 366 | ), |
367 | 367 | new HtmlTableHeaderBuilder( |
368 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(), |
|
368 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(), |
|
369 | 369 | true |
370 | 370 | ) |
371 | 371 | ] |
372 | 372 | ); |
373 | 373 | |
374 | - foreach ( $results as $result ) { |
|
375 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
374 | + foreach ($results as $result) { |
|
375 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | return $table->toHtml(); |
379 | 379 | } |
380 | 380 | |
381 | - private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) { |
|
381 | + private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) { |
|
382 | 382 | // Status column |
383 | 383 | $statusColumn = $this->buildTooltipElement( |
384 | - $this->formatStatus( $result->getStatus() ), |
|
384 | + $this->formatStatus($result->getStatus()), |
|
385 | 385 | $result->getMessage() !== null ? |
386 | - $this->violationMessageRenderer->render( $result->getMessage() ) : |
|
387 | - null, |
|
386 | + $this->violationMessageRenderer->render($result->getMessage()) : null, |
|
388 | 387 | '[?]' |
389 | 388 | ); |
390 | 389 | |
391 | 390 | // Claim column |
392 | 391 | $property = $this->entityIdLabelFormatter->formatEntityId( |
393 | - new PropertyId( $result->getContextCursor()->getSnakPropertyId() ) |
|
392 | + new PropertyId($result->getContextCursor()->getSnakPropertyId()) |
|
394 | 393 | ); |
395 | 394 | $value = null; |
396 | 395 | $snakType = $result->getSnakType(); |
397 | - if ( $snakType === 'value' ) { |
|
396 | + if ($snakType === 'value') { |
|
398 | 397 | $dataValue = $result->getDataValue(); |
399 | - if ( $dataValue !== null ) { |
|
400 | - $value = $this->constraintParameterRenderer->formatValue( $dataValue ); |
|
398 | + if ($dataValue !== null) { |
|
399 | + $value = $this->constraintParameterRenderer->formatValue($dataValue); |
|
401 | 400 | } |
402 | - } elseif ( $snakType !== null ) { |
|
403 | - $value = htmlspecialchars( $snakType ); |
|
401 | + } elseif ($snakType !== null) { |
|
402 | + $value = htmlspecialchars($snakType); |
|
404 | 403 | } |
405 | - if ( $value === null ) { |
|
404 | + if ($value === null) { |
|
406 | 405 | // incomplete CheckResult – this should never happen |
407 | - $value = $this->msg( 'unknown-error' )->escaped(); |
|
406 | + $value = $this->msg('unknown-error')->escaped(); |
|
408 | 407 | } |
409 | 408 | |
410 | 409 | $claimColumn = $this->getClaimLink( |
411 | 410 | $entityId, |
412 | - new PropertyId( $result->getContextCursor()->getSnakPropertyId() ), |
|
413 | - $property . ': ' . $value |
|
411 | + new PropertyId($result->getContextCursor()->getSnakPropertyId()), |
|
412 | + $property.': '.$value |
|
414 | 413 | ); |
415 | 414 | |
416 | 415 | // Constraint column |
417 | 416 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
418 | 417 | try { |
419 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
420 | - } catch ( InvalidArgumentException $e ) { |
|
421 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
418 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
419 | + } catch (InvalidArgumentException $e) { |
|
420 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
422 | 421 | } |
423 | 422 | $constraintLink = $this->getClaimLink( |
424 | - new PropertyId( $result->getContextCursor()->getSnakPropertyId() ), |
|
425 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
423 | + new PropertyId($result->getContextCursor()->getSnakPropertyId()), |
|
424 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
426 | 425 | $constraintTypeLabel |
427 | 426 | ); |
428 | 427 | $constraintColumn = $this->buildExpandableElement( |
429 | 428 | $constraintLink, |
430 | - $this->constraintParameterRenderer->formatParameters( $result->getParameters() ), |
|
429 | + $this->constraintParameterRenderer->formatParameters($result->getParameters()), |
|
431 | 430 | '[...]' |
432 | 431 | ); |
433 | 432 | |
@@ -462,15 +461,15 @@ discard block |
||
462 | 461 | * |
463 | 462 | * @return string HTML |
464 | 463 | */ |
465 | - protected function buildResultHeader( EntityId $entityId ) { |
|
466 | - $entityLink = sprintf( '%s (%s)', |
|
467 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
468 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
464 | + protected function buildResultHeader(EntityId $entityId) { |
|
465 | + $entityLink = sprintf('%s (%s)', |
|
466 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
467 | + htmlspecialchars($entityId->getSerialization())); |
|
469 | 468 | |
470 | 469 | return Html::rawElement( |
471 | 470 | 'h3', |
472 | 471 | [], |
473 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
472 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
474 | 473 | ); |
475 | 474 | } |
476 | 475 | |
@@ -481,24 +480,24 @@ discard block |
||
481 | 480 | * |
482 | 481 | * @return string HTML |
483 | 482 | */ |
484 | - protected function buildSummary( array $results ) { |
|
483 | + protected function buildSummary(array $results) { |
|
485 | 484 | $statuses = []; |
486 | - foreach ( $results as $result ) { |
|
487 | - $status = strtolower( $result->getStatus() ); |
|
488 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
485 | + foreach ($results as $result) { |
|
486 | + $status = strtolower($result->getStatus()); |
|
487 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
489 | 488 | } |
490 | 489 | |
491 | 490 | $statusElements = []; |
492 | - foreach ( $statuses as $status => $count ) { |
|
493 | - if ( $count > 0 ) { |
|
491 | + foreach ($statuses as $status => $count) { |
|
492 | + if ($count > 0) { |
|
494 | 493 | $statusElements[] = |
495 | - $this->formatStatus( $status ) |
|
494 | + $this->formatStatus($status) |
|
496 | 495 | . ': ' |
497 | 496 | . $count; |
498 | 497 | } |
499 | 498 | } |
500 | 499 | |
501 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
500 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
502 | 501 | } |
503 | 502 | |
504 | 503 | /** |
@@ -513,15 +512,15 @@ discard block |
||
513 | 512 | * |
514 | 513 | * @return string HTML |
515 | 514 | */ |
516 | - protected function buildTooltipElement( $content, $tooltipContent, $indicator ) { |
|
517 | - if ( !is_string( $content ) ) { |
|
518 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
515 | + protected function buildTooltipElement($content, $tooltipContent, $indicator) { |
|
516 | + if (!is_string($content)) { |
|
517 | + throw new InvalidArgumentException('$content has to be string.'); |
|
519 | 518 | } |
520 | - if ( $tooltipContent && ( !is_string( $tooltipContent ) ) ) { |
|
521 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
519 | + if ($tooltipContent && (!is_string($tooltipContent))) { |
|
520 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
522 | 521 | } |
523 | 522 | |
524 | - if ( empty( $tooltipContent ) ) { |
|
523 | + if (empty($tooltipContent)) { |
|
525 | 524 | return $content; |
526 | 525 | } |
527 | 526 | |
@@ -538,13 +537,13 @@ discard block |
||
538 | 537 | [ |
539 | 538 | 'class' => 'wbqc-indicator' |
540 | 539 | ], |
541 | - htmlspecialchars( $indicator ) . $tooltip |
|
540 | + htmlspecialchars($indicator).$tooltip |
|
542 | 541 | ); |
543 | 542 | |
544 | 543 | return Html::rawElement( |
545 | 544 | 'span', |
546 | 545 | [], |
547 | - sprintf( '%s %s', $content, $tooltipIndicator ) |
|
546 | + sprintf('%s %s', $content, $tooltipIndicator) |
|
548 | 547 | ); |
549 | 548 | } |
550 | 549 | |
@@ -560,15 +559,15 @@ discard block |
||
560 | 559 | * |
561 | 560 | * @return string HTML |
562 | 561 | */ |
563 | - protected function buildExpandableElement( $content, $expandableContent, $indicator ) { |
|
564 | - if ( !is_string( $content ) ) { |
|
565 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
562 | + protected function buildExpandableElement($content, $expandableContent, $indicator) { |
|
563 | + if (!is_string($content)) { |
|
564 | + throw new InvalidArgumentException('$content has to be string.'); |
|
566 | 565 | } |
567 | - if ( $expandableContent && ( !is_string( $expandableContent ) ) ) { |
|
568 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
566 | + if ($expandableContent && (!is_string($expandableContent))) { |
|
567 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
569 | 568 | } |
570 | 569 | |
571 | - if ( empty( $expandableContent ) ) { |
|
570 | + if (empty($expandableContent)) { |
|
572 | 571 | return $content; |
573 | 572 | } |
574 | 573 | |
@@ -588,7 +587,7 @@ discard block |
||
588 | 587 | $expandableContent |
589 | 588 | ); |
590 | 589 | |
591 | - return sprintf( '%s %s %s', $content, $tooltipIndicator, $expandableContent ); |
|
590 | + return sprintf('%s %s %s', $content, $tooltipIndicator, $expandableContent); |
|
592 | 591 | } |
593 | 592 | |
594 | 593 | /** |
@@ -600,16 +599,16 @@ discard block |
||
600 | 599 | * |
601 | 600 | * @return string HTML |
602 | 601 | */ |
603 | - private function formatStatus( $status ) { |
|
604 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
602 | + private function formatStatus($status) { |
|
603 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
605 | 604 | |
606 | 605 | $formattedStatus = |
607 | 606 | Html::element( |
608 | 607 | 'span', |
609 | 608 | [ |
610 | - 'class' => 'wbqc-status wbqc-status-' . $status |
|
609 | + 'class' => 'wbqc-status wbqc-status-'.$status |
|
611 | 610 | ], |
612 | - $this->msg( $messageName )->text() |
|
611 | + $this->msg($messageName)->text() |
|
613 | 612 | ); |
614 | 613 | |
615 | 614 | return $formattedStatus; |
@@ -625,26 +624,26 @@ discard block |
||
625 | 624 | * |
626 | 625 | * @return string HTML |
627 | 626 | */ |
628 | - protected function formatDataValues( $dataValues, $separator = ', ' ) { |
|
629 | - if ( $dataValues instanceof DataValue ) { |
|
630 | - $dataValues = [ $dataValues ]; |
|
631 | - } elseif ( !is_array( $dataValues ) ) { |
|
632 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
627 | + protected function formatDataValues($dataValues, $separator = ', ') { |
|
628 | + if ($dataValues instanceof DataValue) { |
|
629 | + $dataValues = [$dataValues]; |
|
630 | + } elseif (!is_array($dataValues)) { |
|
631 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
633 | 632 | } |
634 | 633 | |
635 | 634 | $formattedDataValues = []; |
636 | - foreach ( $dataValues as $dataValue ) { |
|
637 | - if ( !( $dataValue instanceof DataValue ) ) { |
|
638 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
635 | + foreach ($dataValues as $dataValue) { |
|
636 | + if (!($dataValue instanceof DataValue)) { |
|
637 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
639 | 638 | } |
640 | - if ( $dataValue instanceof EntityIdValue ) { |
|
641 | - $formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() ); |
|
639 | + if ($dataValue instanceof EntityIdValue) { |
|
640 | + $formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId()); |
|
642 | 641 | } else { |
643 | - $formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue ); |
|
642 | + $formattedDataValues[] = $this->dataValueFormatter->format($dataValue); |
|
644 | 643 | } |
645 | 644 | } |
646 | 645 | |
647 | - return implode( $separator, $formattedDataValues ); |
|
646 | + return implode($separator, $formattedDataValues); |
|
648 | 647 | } |
649 | 648 | |
650 | 649 | /** |
@@ -656,11 +655,11 @@ discard block |
||
656 | 655 | * |
657 | 656 | * @return string HTML |
658 | 657 | */ |
659 | - private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) { |
|
658 | + private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) { |
|
660 | 659 | return Html::rawElement( |
661 | 660 | 'a', |
662 | 661 | [ |
663 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
662 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
664 | 663 | 'target' => '_blank' |
665 | 664 | ], |
666 | 665 | $text |
@@ -675,9 +674,9 @@ discard block |
||
675 | 674 | * |
676 | 675 | * @return string |
677 | 676 | */ |
678 | - private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) { |
|
679 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
680 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
677 | + private function getClaimUrl(EntityId $entityId, PropertyId $propertyId) { |
|
678 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
679 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
681 | 680 | |
682 | 681 | return $entityUrl; |
683 | 682 | } |
@@ -14,6 +14,6 @@ |
||
14 | 14 | * |
15 | 15 | * @return Constraint[] |
16 | 16 | */ |
17 | - public function queryConstraintsForProperty( PropertyId $propertyId ); |
|
17 | + public function queryConstraintsForProperty(PropertyId $propertyId); |
|
18 | 18 | |
19 | 19 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @var ConstraintLookup $lookup The lookup to which all queries are delegated. |
28 | 28 | */ |
29 | - public function __construct( ConstraintLookup $lookup ) { |
|
29 | + public function __construct(ConstraintLookup $lookup) { |
|
30 | 30 | $this->lookup = $lookup; |
31 | 31 | } |
32 | 32 | |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return Constraint[] |
37 | 37 | */ |
38 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
38 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
39 | 39 | $id = $propertyId->getSerialization(); |
40 | - if ( !array_key_exists( $id, $this->cache ) ) { |
|
41 | - $this->cache[$id] = $this->lookup->queryConstraintsForProperty( $propertyId ); |
|
40 | + if (!array_key_exists($id, $this->cache)) { |
|
41 | + $this->cache[$id] = $this->lookup->queryConstraintsForProperty($propertyId); |
|
42 | 42 | } |
43 | 43 | return $this->cache[$id]; |
44 | 44 | } |
@@ -72,7 +72,7 @@ |
||
72 | 72 | * @codeCoverageIgnore |
73 | 73 | */ |
74 | 74 | private function __construct() { |
75 | - throw new LogicException( 'This class should never be instantiated.' ); |
|
75 | + throw new LogicException('This class should never be instantiated.'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @throws ConstraintParameterException if the constraint parameters are invalid |
23 | 23 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
24 | 24 | */ |
25 | - public function checkConstraint( Context $context, Constraint $constraint ); |
|
25 | + public function checkConstraint(Context $context, Constraint $constraint); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Check if the constraint parameters of $constraint are valid. |
@@ -33,6 +33,6 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return ConstraintParameterException[] |
35 | 35 | */ |
36 | - public function checkConstraintParameters( Constraint $constraint ); |
|
36 | + public function checkConstraintParameters(Constraint $constraint); |
|
37 | 37 | |
38 | 38 | } |
@@ -10,7 +10,7 @@ |
||
10 | 10 | class SparqlHelperException extends RuntimeException { |
11 | 11 | |
12 | 12 | public function __construct() { |
13 | - parent::__construct( 'The SPARQL query endpoint returned an error.' ); |
|
13 | + parent::__construct('The SPARQL query endpoint returned an error.'); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | } |