@@ -25,36 +25,36 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @return bool |
27 | 27 | */ |
28 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
29 | - $updater->addExtensionTable( 'wbqc_constraints', __DIR__ . '/../sql/create_wbqc_constraints.sql' ); |
|
28 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
29 | + $updater->addExtensionTable('wbqc_constraints', __DIR__.'/../sql/create_wbqc_constraints.sql'); |
|
30 | 30 | return true; |
31 | 31 | } |
32 | 32 | |
33 | - public static function onWikibaseChange( Change $change ) { |
|
33 | + public static function onWikibaseChange(Change $change) { |
|
34 | 34 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
35 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
36 | - self::isConstraintStatementsChange( $config, $change ) |
|
35 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
36 | + self::isConstraintStatementsChange($config, $change) |
|
37 | 37 | ) { |
38 | 38 | /** @var EntityChange $change */ |
39 | 39 | $title = Title::newMainPage(); |
40 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
40 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
41 | 41 | JobQueueGroup::singleton()->push( |
42 | - new JobSpecification( 'constraintsTableUpdate', $params, [], $title ) |
|
42 | + new JobSpecification('constraintsTableUpdate', $params, [], $title) |
|
43 | 43 | ); |
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
48 | - if ( !( $change instanceof EntityChange ) || |
|
47 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
48 | + if (!($change instanceof EntityChange) || |
|
49 | 49 | $change->getAction() !== EntityChange::UPDATE || |
50 | - !( $change->getEntityId() instanceof PropertyId ) |
|
50 | + !($change->getEntityId() instanceof PropertyId) |
|
51 | 51 | ) { |
52 | 52 | return false; |
53 | 53 | } |
54 | 54 | |
55 | 55 | $info = $change->getInfo(); |
56 | 56 | |
57 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
57 | + if (!array_key_exists('compactDiff', $info)) { |
|
58 | 58 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
59 | 59 | // so we only know that the change *might* affect the constraint statements |
60 | 60 | return true; |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | /** @var EntityDiffChangedAspects $aspects */ |
64 | 64 | $aspects = $info['compactDiff']; |
65 | 65 | |
66 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
67 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
66 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
67 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | public static function getDefaultInstance() { |
132 | 132 | static $instance = null; |
133 | 133 | |
134 | - if ( $instance === null ) { |
|
134 | + if ($instance === null) { |
|
135 | 135 | $wikibaseRepo = WikibaseRepo::getDefaultInstance(); |
136 | 136 | $entityIdFormatter = $wikibaseRepo->getEntityIdHtmlLinkFormatterFactory()->getEntityIdFormatter( |
137 | 137 | $wikibaseRepo->getLanguageFallbackLabelDescriptionLookupFactory()->newLabelDescriptionLookup( |
@@ -196,20 +196,20 @@ discard block |
||
196 | 196 | * @return DelegatingConstraintChecker |
197 | 197 | */ |
198 | 198 | public function getConstraintChecker() { |
199 | - if ( $this->delegatingConstraintChecker === null ) { |
|
199 | + if ($this->delegatingConstraintChecker === null) { |
|
200 | 200 | $this->delegatingConstraintChecker = new DelegatingConstraintChecker( |
201 | 201 | $this->lookup, |
202 | 202 | $this->getConstraintCheckerMap(), |
203 | - new CachingConstraintLookup( $this->getConstraintRepository() ), |
|
203 | + new CachingConstraintLookup($this->getConstraintRepository()), |
|
204 | 204 | $this->constraintParameterParser, |
205 | 205 | $this->statementGuidParser, |
206 | 206 | new LoggingHelper( |
207 | 207 | MediaWikiServices::getInstance()->getStatsdDataFactory(), |
208 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
208 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
209 | 209 | $this->config |
210 | 210 | ), |
211 | - $this->config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
212 | - $this->config->get( 'WBQualityConstraintsCheckReferences' ) |
|
211 | + $this->config->get('WBQualityConstraintsCheckQualifiers'), |
|
212 | + $this->config->get('WBQualityConstraintsCheckReferences') |
|
213 | 213 | ); |
214 | 214 | } |
215 | 215 | |
@@ -220,10 +220,10 @@ discard block |
||
220 | 220 | * @return ConstraintChecker[] |
221 | 221 | */ |
222 | 222 | private function getConstraintCheckerMap() { |
223 | - if ( $this->constraintCheckerMap === null ) { |
|
223 | + if ($this->constraintCheckerMap === null) { |
|
224 | 224 | $connectionCheckerHelper = new ConnectionCheckerHelper(); |
225 | - $rangeCheckerHelper = new RangeCheckerHelper( $this->config, $this->unitConverter ); |
|
226 | - if ( $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ) !== '' ) { |
|
225 | + $rangeCheckerHelper = new RangeCheckerHelper($this->config, $this->unitConverter); |
|
226 | + if ($this->config->get('WBQualityConstraintsSparqlEndpoint') !== '') { |
|
227 | 227 | $sparqlHelper = new SparqlHelper( |
228 | 228 | $this->config, |
229 | 229 | $this->rdfVocabulary, |
@@ -242,74 +242,74 @@ discard block |
||
242 | 242 | ); |
243 | 243 | |
244 | 244 | $this->constraintCheckerMap = [ |
245 | - $this->config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
245 | + $this->config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
246 | 246 | => new ConflictsWithChecker( |
247 | 247 | $this->lookup, |
248 | 248 | $this->constraintParameterParser, |
249 | 249 | $connectionCheckerHelper, |
250 | 250 | $this->constraintParameterRenderer |
251 | 251 | ), |
252 | - $this->config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
252 | + $this->config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
253 | 253 | => new ItemChecker( |
254 | 254 | $this->lookup, |
255 | 255 | $this->constraintParameterParser, |
256 | 256 | $connectionCheckerHelper, |
257 | 257 | $this->constraintParameterRenderer |
258 | 258 | ), |
259 | - $this->config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
259 | + $this->config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
260 | 260 | => new TargetRequiredClaimChecker( |
261 | 261 | $this->lookup, |
262 | 262 | $this->constraintParameterParser, |
263 | 263 | $connectionCheckerHelper, |
264 | 264 | $this->constraintParameterRenderer |
265 | 265 | ), |
266 | - $this->config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
266 | + $this->config->get('WBQualityConstraintsSymmetricConstraintId') |
|
267 | 267 | => new SymmetricChecker( |
268 | 268 | $this->lookup, |
269 | 269 | $connectionCheckerHelper, |
270 | 270 | $this->constraintParameterRenderer |
271 | 271 | ), |
272 | - $this->config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
272 | + $this->config->get('WBQualityConstraintsInverseConstraintId') |
|
273 | 273 | => new InverseChecker( |
274 | 274 | $this->lookup, |
275 | 275 | $this->constraintParameterParser, |
276 | 276 | $connectionCheckerHelper, |
277 | 277 | $this->constraintParameterRenderer |
278 | 278 | ), |
279 | - $this->config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
279 | + $this->config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
280 | 280 | => new QualifierChecker(), |
281 | - $this->config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
281 | + $this->config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
282 | 282 | => new QualifiersChecker( |
283 | 283 | $this->constraintParameterParser, |
284 | 284 | $this->constraintParameterRenderer |
285 | 285 | ), |
286 | - $this->config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
286 | + $this->config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
287 | 287 | => new MandatoryQualifiersChecker( |
288 | 288 | $this->constraintParameterParser, |
289 | 289 | $this->constraintParameterRenderer |
290 | 290 | ), |
291 | - $this->config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
291 | + $this->config->get('WBQualityConstraintsRangeConstraintId') |
|
292 | 292 | => new RangeChecker( |
293 | 293 | $this->propertyDataTypeLookup, |
294 | 294 | $this->constraintParameterParser, |
295 | 295 | $rangeCheckerHelper, |
296 | 296 | $this->constraintParameterRenderer |
297 | 297 | ), |
298 | - $this->config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
298 | + $this->config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
299 | 299 | => new DiffWithinRangeChecker( |
300 | 300 | $this->constraintParameterParser, |
301 | 301 | $rangeCheckerHelper, |
302 | 302 | $this->constraintParameterRenderer, |
303 | 303 | $this->config |
304 | 304 | ), |
305 | - $this->config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
305 | + $this->config->get('WBQualityConstraintsTypeConstraintId') |
|
306 | 306 | => new TypeChecker( |
307 | 307 | $this->lookup, |
308 | 308 | $this->constraintParameterParser, |
309 | 309 | $typeCheckerHelper, |
310 | 310 | $this->config |
311 | 311 | ), |
312 | - $this->config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
312 | + $this->config->get('WBQualityConstraintsValueTypeConstraintId') |
|
313 | 313 | => new ValueTypeChecker( |
314 | 314 | $this->lookup, |
315 | 315 | $this->constraintParameterParser, |
@@ -317,36 +317,36 @@ discard block |
||
317 | 317 | $typeCheckerHelper, |
318 | 318 | $this->config |
319 | 319 | ), |
320 | - $this->config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
320 | + $this->config->get('WBQualityConstraintsSingleValueConstraintId') |
|
321 | 321 | => new SingleValueChecker(), |
322 | - $this->config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
322 | + $this->config->get('WBQualityConstraintsMultiValueConstraintId') |
|
323 | 323 | => new MultiValueChecker(), |
324 | - $this->config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
324 | + $this->config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
325 | 325 | => new UniqueValueChecker( |
326 | 326 | $this->constraintParameterRenderer, |
327 | 327 | $sparqlHelper |
328 | 328 | ), |
329 | - $this->config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
329 | + $this->config->get('WBQualityConstraintsFormatConstraintId') |
|
330 | 330 | => new FormatChecker( |
331 | 331 | $this->constraintParameterParser, |
332 | 332 | $this->constraintParameterRenderer, |
333 | 333 | $this->config, |
334 | 334 | $sparqlHelper |
335 | 335 | ), |
336 | - $this->config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
336 | + $this->config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
337 | 337 | => new CommonsLinkChecker( |
338 | 338 | $this->constraintParameterParser, |
339 | 339 | $this->constraintParameterRenderer, |
340 | 340 | $this->titleParser |
341 | 341 | ), |
342 | - $this->config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
342 | + $this->config->get('WBQualityConstraintsOneOfConstraintId') |
|
343 | 343 | => new OneOfChecker( |
344 | 344 | $this->constraintParameterParser, |
345 | 345 | $this->constraintParameterRenderer |
346 | 346 | ), |
347 | - $this->config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
347 | + $this->config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
348 | 348 | => new ValueOnlyChecker(), |
349 | - $this->config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
349 | + $this->config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
350 | 350 | => new ReferenceChecker(), |
351 | 351 | ]; |
352 | 352 | } |
@@ -358,26 +358,26 @@ discard block |
||
358 | 358 | * @return array[] |
359 | 359 | */ |
360 | 360 | public function getConstraintParameterMap() { |
361 | - if ( $this->constraintParameterMap === null ) { |
|
361 | + if ($this->constraintParameterMap === null) { |
|
362 | 362 | $this->constraintParameterMap = [ |
363 | - 'Commons link' => [ 'namespace' ], |
|
364 | - 'Conflicts with' => [ 'property', 'item' ], |
|
365 | - 'Diff within range' => [ 'property', 'minimum_quantity', 'maximum_quantity' ], |
|
366 | - 'Format' => [ 'pattern' ], |
|
367 | - 'Inverse' => [ 'property' ], |
|
368 | - 'Item' => [ 'property', 'item' ], |
|
369 | - 'Mandatory qualifiers' => [ 'property' ], |
|
363 | + 'Commons link' => ['namespace'], |
|
364 | + 'Conflicts with' => ['property', 'item'], |
|
365 | + 'Diff within range' => ['property', 'minimum_quantity', 'maximum_quantity'], |
|
366 | + 'Format' => ['pattern'], |
|
367 | + 'Inverse' => ['property'], |
|
368 | + 'Item' => ['property', 'item'], |
|
369 | + 'Mandatory qualifiers' => ['property'], |
|
370 | 370 | 'Multi value' => [], |
371 | - 'One of' => [ 'item' ], |
|
371 | + 'One of' => ['item'], |
|
372 | 372 | 'Qualifier' => [], |
373 | - 'Qualifiers' => [ 'property' ], |
|
374 | - 'Range' => [ 'minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date' ], |
|
373 | + 'Qualifiers' => ['property'], |
|
374 | + 'Range' => ['minimum_quantity', 'maximum_quantity', 'minimum_date', 'maximum_date'], |
|
375 | 375 | 'Single value' => [], |
376 | 376 | 'Symmetric' => [], |
377 | - 'Target required claim' => [ 'property', 'item' ], |
|
378 | - 'Type' => [ 'class', 'relation' ], |
|
377 | + 'Target required claim' => ['property', 'item'], |
|
378 | + 'Type' => ['class', 'relation'], |
|
379 | 379 | 'Unique value' => [], |
380 | - 'Value type' => [ 'class', 'relation' ] |
|
380 | + 'Value type' => ['class', 'relation'] |
|
381 | 381 | ]; |
382 | 382 | } |
383 | 383 | |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | * @return ConstraintRepository |
389 | 389 | */ |
390 | 390 | public function getConstraintRepository() { |
391 | - if ( $this->constraintRepository === null ) { |
|
391 | + if ($this->constraintRepository === null) { |
|
392 | 392 | $this->constraintRepository = new ConstraintRepository(); |
393 | 393 | } |
394 | 394 |
@@ -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 | } |
@@ -60,20 +60,20 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return string HTML |
62 | 62 | */ |
63 | - public function formatValue( $value ) { |
|
64 | - if ( is_string( $value ) ) { |
|
63 | + public function formatValue($value) { |
|
64 | + if (is_string($value)) { |
|
65 | 65 | // Cases like 'Format' 'pattern' or 'minimum'/'maximum' values, which we have stored as |
66 | 66 | // strings |
67 | - return htmlspecialchars( $value ); |
|
68 | - } elseif ( $value instanceof EntityId ) { |
|
67 | + return htmlspecialchars($value); |
|
68 | + } elseif ($value instanceof EntityId) { |
|
69 | 69 | // Cases like 'Conflicts with' 'property', to which we can link |
70 | - return $this->formatEntityId( $value ); |
|
71 | - } elseif ( $value instanceof ItemIdSnakValue ) { |
|
70 | + return $this->formatEntityId($value); |
|
71 | + } elseif ($value instanceof ItemIdSnakValue) { |
|
72 | 72 | // Cases like EntityId but can also be somevalue or novalue |
73 | - return $this->formatItemIdSnakValue( $value ); |
|
73 | + return $this->formatItemIdSnakValue($value); |
|
74 | 74 | } else { |
75 | 75 | // Cases where we format a DataValue |
76 | - return $this->formatDataValue( $value ); |
|
76 | + return $this->formatDataValue($value); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
@@ -84,23 +84,23 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return string HTML |
86 | 86 | */ |
87 | - public function formatParameters( $parameters ) { |
|
88 | - if ( $parameters === null || count( $parameters ) == 0 ) { |
|
87 | + public function formatParameters($parameters) { |
|
88 | + if ($parameters === null || count($parameters) == 0) { |
|
89 | 89 | return null; |
90 | 90 | } |
91 | 91 | |
92 | - $valueFormatter = function ( $value ) { |
|
93 | - return $this->formatValue( $value ); |
|
92 | + $valueFormatter = function($value) { |
|
93 | + return $this->formatValue($value); |
|
94 | 94 | }; |
95 | 95 | |
96 | 96 | $formattedParameters = []; |
97 | - foreach ( $parameters as $parameterName => $parameterValue ) { |
|
98 | - $formattedParameterValues = implode( ', ', |
|
99 | - $this->limitArrayLength( array_map( $valueFormatter, $parameterValue ) ) ); |
|
100 | - $formattedParameters[] = sprintf( '%s: %s', $parameterName, $formattedParameterValues ); |
|
97 | + foreach ($parameters as $parameterName => $parameterValue) { |
|
98 | + $formattedParameterValues = implode(', ', |
|
99 | + $this->limitArrayLength(array_map($valueFormatter, $parameterValue))); |
|
100 | + $formattedParameters[] = sprintf('%s: %s', $parameterName, $formattedParameterValues); |
|
101 | 101 | } |
102 | 102 | |
103 | - return implode( '; ', $formattedParameters ); |
|
103 | + return implode('; ', $formattedParameters); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return array |
112 | 112 | */ |
113 | - private function limitArrayLength( array $array ) { |
|
114 | - if ( count( $array ) > self::MAX_PARAMETER_ARRAY_LENGTH ) { |
|
115 | - $array = array_slice( $array, 0, self::MAX_PARAMETER_ARRAY_LENGTH ); |
|
116 | - array_push( $array, '...' ); |
|
113 | + private function limitArrayLength(array $array) { |
|
114 | + if (count($array) > self::MAX_PARAMETER_ARRAY_LENGTH) { |
|
115 | + $array = array_slice($array, 0, self::MAX_PARAMETER_ARRAY_LENGTH); |
|
116 | + array_push($array, '...'); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | return $array; |
@@ -126,12 +126,12 @@ discard block |
||
126 | 126 | * @param string $value HTML |
127 | 127 | * @return string HTML |
128 | 128 | */ |
129 | - public static function formatByRole( $role, $value ) { |
|
130 | - if ( $role === null ) { |
|
129 | + public static function formatByRole($role, $value) { |
|
130 | + if ($role === null) { |
|
131 | 131 | return $value; |
132 | 132 | } |
133 | 133 | |
134 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' |
|
134 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">' |
|
135 | 135 | . $value |
136 | 136 | . '</span>'; |
137 | 137 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @param string|null $role one of the Role constants or null |
142 | 142 | * @return string HTML |
143 | 143 | */ |
144 | - public function formatDataValue( DataValue $value, $role = null ) { |
|
145 | - return self::formatByRole( $role, |
|
146 | - $this->dataValueFormatter->format( $value ) ); |
|
144 | + public function formatDataValue(DataValue $value, $role = null) { |
|
145 | + return self::formatByRole($role, |
|
146 | + $this->dataValueFormatter->format($value)); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,9 +151,9 @@ discard block |
||
151 | 151 | * @param string|null $role one of the Role constants or null |
152 | 152 | * @return string HTML |
153 | 153 | */ |
154 | - public function formatEntityId( EntityId $entityId, $role = null ) { |
|
155 | - return self::formatByRole( $role, |
|
156 | - $this->entityIdLabelFormatter->formatEntityId( $entityId ) ); |
|
154 | + public function formatEntityId(EntityId $entityId, $role = null) { |
|
155 | + return self::formatByRole($role, |
|
156 | + $this->entityIdLabelFormatter->formatEntityId($entityId)); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -165,18 +165,18 @@ discard block |
||
165 | 165 | * @param string|null $role one of the Role constants or null |
166 | 166 | * @return string HTML |
167 | 167 | */ |
168 | - public function formatPropertyId( $propertyId, $role = null ) { |
|
169 | - if ( $propertyId instanceof PropertyId ) { |
|
170 | - return $this->formatEntityId( $propertyId, $role ); |
|
171 | - } elseif ( is_string( $propertyId ) ) { |
|
168 | + public function formatPropertyId($propertyId, $role = null) { |
|
169 | + if ($propertyId instanceof PropertyId) { |
|
170 | + return $this->formatEntityId($propertyId, $role); |
|
171 | + } elseif (is_string($propertyId)) { |
|
172 | 172 | try { |
173 | - return $this->formatEntityId( new PropertyId( $propertyId ), $role ); |
|
174 | - } catch ( InvalidArgumentException $e ) { |
|
175 | - return self::formatByRole( $role, |
|
176 | - htmlspecialchars( $propertyId ) ); |
|
173 | + return $this->formatEntityId(new PropertyId($propertyId), $role); |
|
174 | + } catch (InvalidArgumentException $e) { |
|
175 | + return self::formatByRole($role, |
|
176 | + htmlspecialchars($propertyId)); |
|
177 | 177 | } |
178 | 178 | } else { |
179 | - throw new InvalidArgumentException( '$propertyId must be either PropertyId or string' ); |
|
179 | + throw new InvalidArgumentException('$propertyId must be either PropertyId or string'); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
@@ -189,18 +189,18 @@ discard block |
||
189 | 189 | * @param string|null $role one of the Role constants or null |
190 | 190 | * @return string HTML |
191 | 191 | */ |
192 | - public function formatItemId( $itemId, $role = null ) { |
|
193 | - if ( $itemId instanceof ItemId ) { |
|
194 | - return $this->formatEntityId( $itemId, $role ); |
|
195 | - } elseif ( is_string( $itemId ) ) { |
|
192 | + public function formatItemId($itemId, $role = null) { |
|
193 | + if ($itemId instanceof ItemId) { |
|
194 | + return $this->formatEntityId($itemId, $role); |
|
195 | + } elseif (is_string($itemId)) { |
|
196 | 196 | try { |
197 | - return $this->formatEntityId( new ItemId( $itemId ), $role ); |
|
198 | - } catch ( InvalidArgumentException $e ) { |
|
199 | - return self::formatByRole( $role, |
|
200 | - htmlspecialchars( $itemId ) ); |
|
197 | + return $this->formatEntityId(new ItemId($itemId), $role); |
|
198 | + } catch (InvalidArgumentException $e) { |
|
199 | + return self::formatByRole($role, |
|
200 | + htmlspecialchars($itemId)); |
|
201 | 201 | } |
202 | 202 | } else { |
203 | - throw new InvalidArgumentException( '$itemId must be either ItemId or string' ); |
|
203 | + throw new InvalidArgumentException('$itemId must be either ItemId or string'); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
@@ -211,20 +211,20 @@ discard block |
||
211 | 211 | * @param string|null $role one of the Role constants or null |
212 | 212 | * @return string HTML |
213 | 213 | */ |
214 | - public function formatItemIdSnakValue( ItemIdSnakValue $value, $role = null ) { |
|
215 | - switch ( true ) { |
|
214 | + public function formatItemIdSnakValue(ItemIdSnakValue $value, $role = null) { |
|
215 | + switch (true) { |
|
216 | 216 | case $value->isValue(): |
217 | - return $this->formatEntityId( $value->getItemId(), $role ); |
|
217 | + return $this->formatEntityId($value->getItemId(), $role); |
|
218 | 218 | case $value->isSomeValue(): |
219 | - return self::formatByRole( $role, |
|
219 | + return self::formatByRole($role, |
|
220 | 220 | '<span class="wikibase-snakview-variation-somevaluesnak">' |
221 | - . wfMessage( 'wikibase-snakview-snaktypeselector-somevalue' )->escaped() |
|
222 | - . '</span>' ); |
|
221 | + . wfMessage('wikibase-snakview-snaktypeselector-somevalue')->escaped() |
|
222 | + . '</span>'); |
|
223 | 223 | case $value->isNoValue(): |
224 | - return self::formatByRole( $role, |
|
224 | + return self::formatByRole($role, |
|
225 | 225 | '<span class="wikibase-snakview-variation-novaluesnak">' |
226 | - . wfMessage( 'wikibase-snakview-snaktypeselector-novalue' )->escaped() |
|
227 | - . '</span>' ); |
|
226 | + . wfMessage('wikibase-snakview-snaktypeselector-novalue')->escaped() |
|
227 | + . '</span>'); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
@@ -238,15 +238,15 @@ discard block |
||
238 | 238 | * @param string|null $role one of the Role constants or null |
239 | 239 | * @return string[] HTML |
240 | 240 | */ |
241 | - public function formatPropertyIdList( array $propertyIds, $role = null ) { |
|
242 | - if ( empty( $propertyIds ) ) { |
|
243 | - return [ '<ul></ul>' ]; |
|
241 | + public function formatPropertyIdList(array $propertyIds, $role = null) { |
|
242 | + if (empty($propertyIds)) { |
|
243 | + return ['<ul></ul>']; |
|
244 | 244 | } |
245 | - $propertyIds = $this->limitArrayLength( $propertyIds ); |
|
246 | - $formattedPropertyIds = array_map( [ $this, "formatPropertyId" ], $propertyIds, array_fill( 0, count( $propertyIds ), $role ) ); |
|
245 | + $propertyIds = $this->limitArrayLength($propertyIds); |
|
246 | + $formattedPropertyIds = array_map([$this, "formatPropertyId"], $propertyIds, array_fill(0, count($propertyIds), $role)); |
|
247 | 247 | array_unshift( |
248 | 248 | $formattedPropertyIds, |
249 | - '<ul><li>' . implode( '</li><li>', $formattedPropertyIds ) . '</li></ul>' |
|
249 | + '<ul><li>'.implode('</li><li>', $formattedPropertyIds).'</li></ul>' |
|
250 | 250 | ); |
251 | 251 | return $formattedPropertyIds; |
252 | 252 | } |
@@ -261,15 +261,15 @@ discard block |
||
261 | 261 | * @param string|null $role one of the Role constants or null |
262 | 262 | * @return string[] HTML |
263 | 263 | */ |
264 | - public function formatItemIdList( array $itemIds, $role = null ) { |
|
265 | - if ( empty( $itemIds ) ) { |
|
266 | - return [ '<ul></ul>' ]; |
|
264 | + public function formatItemIdList(array $itemIds, $role = null) { |
|
265 | + if (empty($itemIds)) { |
|
266 | + return ['<ul></ul>']; |
|
267 | 267 | } |
268 | - $itemIds = $this->limitArrayLength( $itemIds ); |
|
269 | - $formattedItemIds = array_map( [ $this, "formatItemId" ], $itemIds, array_fill( 0, count( $itemIds ), $role ) ); |
|
268 | + $itemIds = $this->limitArrayLength($itemIds); |
|
269 | + $formattedItemIds = array_map([$this, "formatItemId"], $itemIds, array_fill(0, count($itemIds), $role)); |
|
270 | 270 | array_unshift( |
271 | 271 | $formattedItemIds, |
272 | - '<ul><li>' . implode( '</li><li>', $formattedItemIds ) . '</li></ul>' |
|
272 | + '<ul><li>'.implode('</li><li>', $formattedItemIds).'</li></ul>' |
|
273 | 273 | ); |
274 | 274 | return $formattedItemIds; |
275 | 275 | } |
@@ -284,23 +284,23 @@ discard block |
||
284 | 284 | * @param string|null $role one of the Role constants or null |
285 | 285 | * @return string[] HTML |
286 | 286 | */ |
287 | - public function formatEntityIdList( array $entityIds, $role = null ) { |
|
288 | - if ( empty( $entityIds ) ) { |
|
289 | - return [ '<ul></ul>' ]; |
|
287 | + public function formatEntityIdList(array $entityIds, $role = null) { |
|
288 | + if (empty($entityIds)) { |
|
289 | + return ['<ul></ul>']; |
|
290 | 290 | } |
291 | 291 | $formattedEntityIds = []; |
292 | - foreach ( $entityIds as $entityId ) { |
|
293 | - if ( count( $formattedEntityIds ) >= self::MAX_PARAMETER_ARRAY_LENGTH ) { |
|
292 | + foreach ($entityIds as $entityId) { |
|
293 | + if (count($formattedEntityIds) >= self::MAX_PARAMETER_ARRAY_LENGTH) { |
|
294 | 294 | $formattedEntityIds[] = '...'; |
295 | 295 | break; |
296 | 296 | } |
297 | - if ( $entityId !== null ) { |
|
298 | - $formattedEntityIds[] = $this->formatEntityId( $entityId, $role ); |
|
297 | + if ($entityId !== null) { |
|
298 | + $formattedEntityIds[] = $this->formatEntityId($entityId, $role); |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | array_unshift( |
302 | 302 | $formattedEntityIds, |
303 | - '<ul><li>' . implode( '</li><li>', $formattedEntityIds ) . '</li></ul>' |
|
303 | + '<ul><li>'.implode('</li><li>', $formattedEntityIds).'</li></ul>' |
|
304 | 304 | ); |
305 | 305 | return $formattedEntityIds; |
306 | 306 | } |
@@ -315,24 +315,24 @@ discard block |
||
315 | 315 | * @param string|null $role one of the Role constants or null |
316 | 316 | * @return string[] HTML |
317 | 317 | */ |
318 | - public function formatItemIdSnakValueList( array $values, $role = null ) { |
|
319 | - if ( empty( $values ) ) { |
|
320 | - return [ '<ul></ul>' ]; |
|
318 | + public function formatItemIdSnakValueList(array $values, $role = null) { |
|
319 | + if (empty($values)) { |
|
320 | + return ['<ul></ul>']; |
|
321 | 321 | } |
322 | - $values = $this->limitArrayLength( $values ); |
|
322 | + $values = $this->limitArrayLength($values); |
|
323 | 323 | $formattedValues = array_map( |
324 | - function( $value ) use ( $role ) { |
|
325 | - if ( $value === '...' ) { |
|
324 | + function($value) use ($role) { |
|
325 | + if ($value === '...') { |
|
326 | 326 | return '...'; |
327 | 327 | } else { |
328 | - return $this->formatItemIdSnakValue( $value, $role ); |
|
328 | + return $this->formatItemIdSnakValue($value, $role); |
|
329 | 329 | } |
330 | 330 | }, |
331 | 331 | $values |
332 | 332 | ); |
333 | 333 | array_unshift( |
334 | 334 | $formattedValues, |
335 | - '<ul><li>' . implode( '</li><li>', $formattedValues ) . '</li></ul>' |
|
335 | + '<ul><li>'.implode('</li><li>', $formattedValues).'</li></ul>' |
|
336 | 336 | ); |
337 | 337 | return $formattedValues; |
338 | 338 | } |
@@ -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 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param ItemId $itemId |
45 | 45 | * @return self |
46 | 46 | */ |
47 | - public static function fromItemId( ItemId $itemId ) { |
|
47 | + public static function fromItemId(ItemId $itemId) { |
|
48 | 48 | $ret = new self; |
49 | 49 | $ret->itemId = $itemId; |
50 | 50 | return $ret; |
@@ -80,16 +80,16 @@ discard block |
||
80 | 80 | * @throws InvalidArgumentException |
81 | 81 | * @return self |
82 | 82 | */ |
83 | - public static function fromSnak( Snak $snak ) { |
|
84 | - switch ( true ) { |
|
83 | + public static function fromSnak(Snak $snak) { |
|
84 | + switch (true) { |
|
85 | 85 | case $snak instanceof PropertyValueSnak: |
86 | 86 | if ( |
87 | 87 | $snak->getDataValue() instanceof EntityIdValue && |
88 | 88 | $snak->getDataValue()->getEntityId() instanceof ItemId |
89 | 89 | ) { |
90 | - return self::fromItemId( $snak->getDataValue()->getEntityId() ); |
|
90 | + return self::fromItemId($snak->getDataValue()->getEntityId()); |
|
91 | 91 | } else { |
92 | - throw new InvalidArgumentException( 'Snak must contain item ID value or be a somevalue / novalue snak' ); |
|
92 | + throw new InvalidArgumentException('Snak must contain item ID value or be a somevalue / novalue snak'); |
|
93 | 93 | } |
94 | 94 | case $snak instanceof PropertySomeValueSnak: |
95 | 95 | return self::someValue(); |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @return ItemId |
133 | 133 | */ |
134 | 134 | public function getItemId() { |
135 | - if ( ! $this->isValue() ) { |
|
136 | - throw new DomainException( 'This value does not contain an item ID.' ); |
|
135 | + if (!$this->isValue()) { |
|
136 | + throw new DomainException('This value does not contain an item ID.'); |
|
137 | 137 | } |
138 | 138 | return $this->itemId; |
139 | 139 | } |
@@ -145,13 +145,13 @@ discard block |
||
145 | 145 | * @param Snak $snak |
146 | 146 | * @return bool |
147 | 147 | */ |
148 | - public function matchesSnak( Snak $snak ) { |
|
149 | - switch ( true ) { |
|
148 | + public function matchesSnak(Snak $snak) { |
|
149 | + switch (true) { |
|
150 | 150 | case $snak instanceof PropertyValueSnak: |
151 | 151 | return $this->isValue() && |
152 | 152 | $snak->getDataValue() instanceof EntityIdValue && |
153 | 153 | $snak->getDataValue()->getEntityId() instanceof ItemId && |
154 | - $snak->getDataValue()->getEntityId()->equals( $this->getItemId() ); |
|
154 | + $snak->getDataValue()->getEntityId()->equals($this->getItemId()); |
|
155 | 155 | case $snak instanceof PropertySomeValueSnak: |
156 | 156 | return $this->isSomeValue(); |
157 | 157 | case $snak instanceof PropertyNoValueSnak: |
@@ -35,29 +35,29 @@ discard block |
||
35 | 35 | $propertyId, |
36 | 36 | $statementId |
37 | 37 | ) { |
38 | - if ( !array_key_exists( $entityId, $container ) ) { |
|
38 | + if (!array_key_exists($entityId, $container)) { |
|
39 | 39 | $container[$entityId] = []; |
40 | 40 | } |
41 | 41 | $entityContainer = &$container[$entityId]; |
42 | 42 | |
43 | - if ( !array_key_exists( 'claims', $entityContainer ) ) { |
|
43 | + if (!array_key_exists('claims', $entityContainer)) { |
|
44 | 44 | $entityContainer['claims'] = []; |
45 | 45 | } |
46 | 46 | $claimsContainer = &$entityContainer['claims']; |
47 | 47 | |
48 | - if ( !array_key_exists( $propertyId, $claimsContainer ) ) { |
|
48 | + if (!array_key_exists($propertyId, $claimsContainer)) { |
|
49 | 49 | $claimsContainer[$propertyId] = []; |
50 | 50 | } |
51 | 51 | $propertyContainer = &$claimsContainer[$propertyId]; |
52 | 52 | |
53 | - foreach ( $propertyContainer as &$statement ) { |
|
54 | - if ( $statement['id'] === $statementId ) { |
|
53 | + foreach ($propertyContainer as &$statement) { |
|
54 | + if ($statement['id'] === $statementId) { |
|
55 | 55 | $statementArray = &$statement; |
56 | 56 | break; |
57 | 57 | } |
58 | 58 | } |
59 | - if ( !isset( $statementArray ) ) { |
|
60 | - $statementArray = [ 'id' => $statementId ]; |
|
59 | + if (!isset($statementArray)) { |
|
60 | + $statementArray = ['id' => $statementId]; |
|
61 | 61 | $propertyContainer[] = &$statementArray; |
62 | 62 | } |
63 | 63 | |
@@ -72,15 +72,15 @@ discard block |
||
72 | 72 | * @param array &$container |
73 | 73 | * @return array |
74 | 74 | */ |
75 | - abstract protected function &getMainArray( array &$container ); |
|
75 | + abstract protected function &getMainArray(array &$container); |
|
76 | 76 | |
77 | - public function storeCheckResultInArray( $result, array &$container ) { |
|
78 | - $mainArray = &$this->getMainArray( $container ); |
|
79 | - if ( !array_key_exists( 'results', $mainArray ) ) { |
|
77 | + public function storeCheckResultInArray($result, array &$container) { |
|
78 | + $mainArray = &$this->getMainArray($container); |
|
79 | + if (!array_key_exists('results', $mainArray)) { |
|
80 | 80 | $mainArray['results'] = []; |
81 | 81 | } |
82 | 82 | |
83 | - if ( $result !== null ) { |
|
83 | + if ($result !== null) { |
|
84 | 84 | $mainArray['results'][] = $result; |
85 | 85 | } |
86 | 86 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | EntityDocument $entity, |
24 | 24 | Statement $statement |
25 | 25 | ) { |
26 | - parent::__construct( $entity, $statement->getMainSnak() ); |
|
26 | + parent::__construct($entity, $statement->getMainSnak()); |
|
27 | 27 | $this->statement = $statement; |
28 | 28 | } |
29 | 29 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | return $this->statement; |
40 | 40 | } |
41 | 41 | |
42 | - protected function &getMainArray( array &$container ) { |
|
42 | + protected function &getMainArray(array &$container) { |
|
43 | 43 | $statementArray = &$this->getStatementArray( |
44 | 44 | $container, |
45 | 45 | $this->entity->getId()->getSerialization(), |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | $this->statement->getGuid() |
48 | 48 | ); |
49 | 49 | |
50 | - if ( !array_key_exists( 'mainsnak', $statementArray ) ) { |
|
51 | - $statementArray['mainsnak'] = [ 'hash' => $this->statement->getMainSnak()->getHash() ]; |
|
50 | + if (!array_key_exists('mainsnak', $statementArray)) { |
|
51 | + $statementArray['mainsnak'] = ['hash' => $this->statement->getMainSnak()->getHash()]; |
|
52 | 52 | } |
53 | 53 | $mainsnakArray = &$statementArray['mainsnak']; |
54 | 54 |
@@ -86,6 +86,6 @@ |
||
86 | 86 | * @param array|null $result |
87 | 87 | * @param array &$container |
88 | 88 | */ |
89 | - public function storeCheckResultInArray( $result, array &$container ); |
|
89 | + public function storeCheckResultInArray($result, array &$container); |
|
90 | 90 | |
91 | 91 | } |