@@ -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\Context; |
6 | 6 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | Statement $statement, |
26 | 26 | Snak $snak |
27 | 27 | ) { |
28 | - parent::__construct( $entity, $snak ); |
|
28 | + parent::__construct($entity, $snak); |
|
29 | 29 | $this->statement = $statement; |
30 | 30 | } |
31 | 31 | |
@@ -33,16 +33,16 @@ discard block |
||
33 | 33 | return self::TYPE_QUALIFIER; |
34 | 34 | } |
35 | 35 | |
36 | - public function getSnakGroup( string $groupingMode, array $separators = [] ): array { |
|
36 | + public function getSnakGroup(string $groupingMode, array $separators = []): array { |
|
37 | 37 | $snaks = $this->statement->getQualifiers(); |
38 | - return array_values( $snaks->getArrayCopy() ); |
|
38 | + return array_values($snaks->getArrayCopy()); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | public function getCursor(): ContextCursor { |
42 | 42 | return new QualifierContextCursor( |
43 | 43 | $this->entity->getId()->getSerialization(), |
44 | 44 | $this->statement->getPropertyId()->getSerialization(), |
45 | - $this->getStatementGuid( $this->statement ), |
|
45 | + $this->getStatementGuid($this->statement), |
|
46 | 46 | $this->snak->getHash(), |
47 | 47 | $this->snak->getPropertyId()->getSerialization() |
48 | 48 | ); |
@@ -76,20 +76,20 @@ discard block |
||
76 | 76 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
77 | 77 | * @return CheckResult |
78 | 78 | */ |
79 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
80 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
81 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
79 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
80 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
81 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
82 | 82 | } |
83 | 83 | $parameters = []; |
84 | 84 | |
85 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
85 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
86 | 86 | |
87 | 87 | $separators = $this->constraintParameterParser->parseSeparatorsParameter( |
88 | 88 | $constraint->getConstraintParameters() |
89 | 89 | ); |
90 | 90 | $parameters['separator'] = $separators; |
91 | 91 | |
92 | - if ( $context->getType() === 'statement' ) { |
|
92 | + if ($context->getType() === 'statement') { |
|
93 | 93 | $statement = $context->getSnakStatement(); |
94 | 94 | '@phan-var Statement $statement'; |
95 | 95 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | ); |
99 | 99 | } else { |
100 | 100 | $snak = $context->getSnak(); |
101 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
101 | + if (!$snak instanceof PropertyValueSnak) { |
|
102 | 102 | // nothing to check |
103 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
103 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
104 | 104 | } |
105 | 105 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
106 | 106 | $context->getEntity()->getId(), |
@@ -113,32 +113,32 @@ discard block |
||
113 | 113 | $otherEntities = $result->getArray(); |
114 | 114 | $metadata = $result->getMetadata(); |
115 | 115 | |
116 | - if ( $otherEntities === [] ) { |
|
116 | + if ($otherEntities === []) { |
|
117 | 117 | $status = CheckResult::STATUS_COMPLIANCE; |
118 | 118 | $message = null; |
119 | 119 | } else { |
120 | - $otherEntities = array_values( array_filter( $otherEntities ) ); // remove nulls |
|
120 | + $otherEntities = array_values(array_filter($otherEntities)); // remove nulls |
|
121 | 121 | $status = CheckResult::STATUS_VIOLATION; |
122 | - $message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) ) |
|
123 | - ->withEntityIdList( $otherEntities, Role::SUBJECT ); |
|
122 | + $message = (new ViolationMessage('wbqc-violation-message-unique-value')) |
|
123 | + ->withEntityIdList($otherEntities, Role::SUBJECT); |
|
124 | 124 | } |
125 | 125 | } else { |
126 | 126 | $status = CheckResult::STATUS_TODO; |
127 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
128 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
127 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
128 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
129 | 129 | $metadata = Metadata::blank(); |
130 | 130 | } |
131 | 131 | |
132 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
133 | - ->withMetadata( $metadata ); |
|
132 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
133 | + ->withMetadata($metadata); |
|
134 | 134 | } |
135 | 135 | |
136 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
136 | + public function checkConstraintParameters(Constraint $constraint) { |
|
137 | 137 | $constraintParameters = $constraint->getConstraintParameters(); |
138 | 138 | $exceptions = []; |
139 | 139 | try { |
140 | - $this->constraintParameterParser->parseSeparatorsParameter( $constraintParameters ); |
|
141 | - } catch ( ConstraintParameterException $e ) { |
|
140 | + $this->constraintParameterParser->parseSeparatorsParameter($constraintParameters); |
|
141 | + } catch (ConstraintParameterException $e) { |
|
142 | 142 | $exceptions[] = $e; |
143 | 143 | } |
144 | 144 | return $exceptions; |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @throws InvalidArgumentException |
43 | 43 | */ |
44 | - public function __construct( $content, $isSortable = false, $isRawContent = false ) { |
|
45 | - Assert::parameterType( 'string', $content, '$content' ); |
|
46 | - Assert::parameterType( 'boolean', $isSortable, '$isSortable' ); |
|
47 | - Assert::parameterType( 'boolean', $isRawContent, '$isRawContent' ); |
|
44 | + public function __construct($content, $isSortable = false, $isRawContent = false) { |
|
45 | + Assert::parameterType('string', $content, '$content'); |
|
46 | + Assert::parameterType('boolean', $isSortable, '$isSortable'); |
|
47 | + Assert::parameterType('boolean', $isRawContent, '$isRawContent'); |
|
48 | 48 | |
49 | 49 | $this->content = $content; |
50 | 50 | $this->isSortable = $isSortable; |
@@ -71,19 +71,19 @@ discard block |
||
71 | 71 | * @return string HTML |
72 | 72 | */ |
73 | 73 | public function toHtml() { |
74 | - $attributes = [ 'role' => 'columnheader button' ]; |
|
74 | + $attributes = ['role' => 'columnheader button']; |
|
75 | 75 | |
76 | - if ( !$this->isSortable ) { |
|
76 | + if (!$this->isSortable) { |
|
77 | 77 | $attributes['class'] = 'unsortable'; |
78 | 78 | } |
79 | 79 | |
80 | - if ( !$this->isRawContent ) { |
|
81 | - $content = htmlspecialchars( $this->content ); |
|
80 | + if (!$this->isRawContent) { |
|
81 | + $content = htmlspecialchars($this->content); |
|
82 | 82 | } else { |
83 | 83 | $content = $this->content; |
84 | 84 | } |
85 | 85 | |
86 | - return Html::rawElement( 'th', $attributes, $content ); |
|
86 | + return Html::rawElement('th', $attributes, $content); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | } |
@@ -71,20 +71,20 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string HTML |
73 | 73 | */ |
74 | - public function formatValue( $value ) { |
|
75 | - if ( is_string( $value ) ) { |
|
74 | + public function formatValue($value) { |
|
75 | + if (is_string($value)) { |
|
76 | 76 | // Cases like 'Format' 'pattern' or 'minimum'/'maximum' values, which we have stored as |
77 | 77 | // strings |
78 | - return htmlspecialchars( $value ); |
|
79 | - } elseif ( $value instanceof EntityId ) { |
|
78 | + return htmlspecialchars($value); |
|
79 | + } elseif ($value instanceof EntityId) { |
|
80 | 80 | // Cases like 'Conflicts with' 'property', to which we can link |
81 | - return $this->formatEntityId( $value ); |
|
82 | - } elseif ( $value instanceof ItemIdSnakValue ) { |
|
81 | + return $this->formatEntityId($value); |
|
82 | + } elseif ($value instanceof ItemIdSnakValue) { |
|
83 | 83 | // Cases like EntityId but can also be somevalue or novalue |
84 | - return $this->formatItemIdSnakValue( $value ); |
|
84 | + return $this->formatItemIdSnakValue($value); |
|
85 | 85 | } else { |
86 | 86 | // Cases where we format a DataValue |
87 | - return $this->formatDataValue( $value ); |
|
87 | + return $this->formatDataValue($value); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -95,19 +95,19 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return string|null HTML |
97 | 97 | */ |
98 | - public function formatParameters( $parameters ) { |
|
99 | - if ( $parameters === null || $parameters === [] ) { |
|
98 | + public function formatParameters($parameters) { |
|
99 | + if ($parameters === null || $parameters === []) { |
|
100 | 100 | return null; |
101 | 101 | } |
102 | 102 | |
103 | 103 | $formattedParameters = []; |
104 | - foreach ( $parameters as $parameterName => $parameterValue ) { |
|
105 | - $formattedParameterValues = implode( ', ', |
|
106 | - $this->limitArrayLength( array_map( [ $this, 'formatValue' ], $parameterValue ) ) ); |
|
107 | - $formattedParameters[] = sprintf( '%s: %s', $parameterName, $formattedParameterValues ); |
|
104 | + foreach ($parameters as $parameterName => $parameterValue) { |
|
105 | + $formattedParameterValues = implode(', ', |
|
106 | + $this->limitArrayLength(array_map([$this, 'formatValue'], $parameterValue))); |
|
107 | + $formattedParameters[] = sprintf('%s: %s', $parameterName, $formattedParameterValues); |
|
108 | 108 | } |
109 | 109 | |
110 | - return implode( '; ', $formattedParameters ); |
|
110 | + return implode('; ', $formattedParameters); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -117,10 +117,10 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return string[] |
119 | 119 | */ |
120 | - private function limitArrayLength( array $array ) { |
|
121 | - if ( count( $array ) > self::MAX_PARAMETER_ARRAY_LENGTH ) { |
|
122 | - $array = array_slice( $array, 0, self::MAX_PARAMETER_ARRAY_LENGTH ); |
|
123 | - array_push( $array, '...' ); |
|
120 | + private function limitArrayLength(array $array) { |
|
121 | + if (count($array) > self::MAX_PARAMETER_ARRAY_LENGTH) { |
|
122 | + $array = array_slice($array, 0, self::MAX_PARAMETER_ARRAY_LENGTH); |
|
123 | + array_push($array, '...'); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | return $array; |
@@ -130,16 +130,16 @@ discard block |
||
130 | 130 | * @param DataValue $value |
131 | 131 | * @return string HTML |
132 | 132 | */ |
133 | - public function formatDataValue( DataValue $value ) { |
|
134 | - return $this->dataValueFormatter->format( $value ); |
|
133 | + public function formatDataValue(DataValue $value) { |
|
134 | + return $this->dataValueFormatter->format($value); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
138 | 138 | * @param EntityId $entityId |
139 | 139 | * @return string HTML |
140 | 140 | */ |
141 | - public function formatEntityId( EntityId $entityId ) { |
|
142 | - return $this->entityIdLabelFormatter->formatEntityId( $entityId ); |
|
141 | + public function formatEntityId(EntityId $entityId) { |
|
142 | + return $this->entityIdLabelFormatter->formatEntityId($entityId); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -148,17 +148,17 @@ discard block |
||
148 | 148 | * @param ItemIdSnakValue $value |
149 | 149 | * @return string HTML |
150 | 150 | */ |
151 | - public function formatItemIdSnakValue( ItemIdSnakValue $value ) { |
|
152 | - switch ( true ) { |
|
151 | + public function formatItemIdSnakValue(ItemIdSnakValue $value) { |
|
152 | + switch (true) { |
|
153 | 153 | case $value->isValue(): |
154 | - return $this->formatEntityId( $value->getItemId() ); |
|
154 | + return $this->formatEntityId($value->getItemId()); |
|
155 | 155 | case $value->isSomeValue(): |
156 | 156 | return $this->messageLocalizer |
157 | - ->msg( 'wikibase-snakview-snaktypeselector-somevalue' ) |
|
157 | + ->msg('wikibase-snakview-snaktypeselector-somevalue') |
|
158 | 158 | ->escaped(); |
159 | 159 | case $value->isNoValue(): |
160 | 160 | return $this->messageLocalizer |
161 | - ->msg( 'wikibase-snakview-snaktypeselector-novalue' ) |
|
161 | + ->msg('wikibase-snakview-snaktypeselector-novalue') |
|
162 | 162 | ->escaped(); |
163 | 163 | } |
164 | 164 | } |
@@ -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\Context; |
6 | 6 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | protected Snak $snak; |
23 | 23 | |
24 | - public function __construct( StatementListProvidingEntity $entity, Snak $snak ) { |
|
24 | + public function __construct(StatementListProvidingEntity $entity, Snak $snak) { |
|
25 | 25 | $this->entity = $entity; |
26 | 26 | $this->snak = $snak; |
27 | 27 | } |
@@ -47,15 +47,15 @@ discard block |
||
47 | 47 | // unimplemented: getCursor |
48 | 48 | |
49 | 49 | /** Helper function for {@link getCursor()} implementations. */ |
50 | - protected function getStatementGuid( Statement $statement ): string { |
|
50 | + protected function getStatementGuid(Statement $statement): string { |
|
51 | 51 | $guid = $statement->getGuid(); |
52 | - if ( $guid === null ) { |
|
53 | - if ( defined( 'MW_PHPUNIT_TEST' ) ) { |
|
52 | + if ($guid === null) { |
|
53 | + if (defined('MW_PHPUNIT_TEST')) { |
|
54 | 54 | // let unit tests get away with not specifying a statement GUID: |
55 | 55 | // much more convenient to fake it here than to add one to all tests |
56 | 56 | return 'Q0$DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF'; |
57 | 57 | } else { |
58 | - throw new InvalidArgumentException( 'Statement for Context must have a GUID' ); |
|
58 | + throw new InvalidArgumentException('Statement for Context must have a GUID'); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | return $guid; |
@@ -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\Context; |
6 | 6 | |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | |
22 | 22 | private Statement $statement; |
23 | 23 | |
24 | - public function __construct( StatementListProvidingEntity $entity, Statement $statement ) { |
|
25 | - parent::__construct( $entity, $statement->getMainSnak() ); |
|
24 | + public function __construct(StatementListProvidingEntity $entity, Statement $statement) { |
|
25 | + parent::__construct($entity, $statement->getMainSnak()); |
|
26 | 26 | |
27 | 27 | $this->statement = $statement; |
28 | 28 | } |
@@ -39,21 +39,21 @@ discard block |
||
39 | 39 | return $this->statement; |
40 | 40 | } |
41 | 41 | |
42 | - public function getSnakGroup( string $groupingMode, array $separators = [] ): array { |
|
42 | + public function getSnakGroup(string $groupingMode, array $separators = []): array { |
|
43 | 43 | /** @var StatementList $statements */ |
44 | 44 | $statements = $this->entity->getStatements(); |
45 | - switch ( $groupingMode ) { |
|
45 | + switch ($groupingMode) { |
|
46 | 46 | case Context::GROUP_NON_DEPRECATED: |
47 | - $statements = $statements->getByRank( [ |
|
47 | + $statements = $statements->getByRank([ |
|
48 | 48 | Statement::RANK_NORMAL, |
49 | 49 | Statement::RANK_PREFERRED, |
50 | - ] ); |
|
50 | + ]); |
|
51 | 51 | break; |
52 | 52 | case Context::GROUP_BEST_RANK: |
53 | - $statements = $this->getBestStatementsPerPropertyId( $statements ); |
|
53 | + $statements = $this->getBestStatementsPerPropertyId($statements); |
|
54 | 54 | break; |
55 | 55 | default: |
56 | - throw new LogicException( 'Unknown $groupingMode ' . $groupingMode ); |
|
56 | + throw new LogicException('Unknown $groupingMode '.$groupingMode); |
|
57 | 57 | } |
58 | 58 | return $this->getStatementsWithSameQualifiersForProperties( |
59 | 59 | $this->statement, |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | )->getMainSnaks(); |
63 | 63 | } |
64 | 64 | |
65 | - private function getBestStatementsPerPropertyId( StatementList $statements ): StatementList { |
|
65 | + private function getBestStatementsPerPropertyId(StatementList $statements): StatementList { |
|
66 | 66 | $allBestStatements = new StatementList(); |
67 | - foreach ( $statements->getPropertyIds() as $propertyId ) { |
|
68 | - $bestStatements = $statements->getByPropertyId( $propertyId ) |
|
67 | + foreach ($statements->getPropertyIds() as $propertyId) { |
|
68 | + $bestStatements = $statements->getByPropertyId($propertyId) |
|
69 | 69 | ->getBestStatements(); |
70 | - foreach ( $bestStatements as $bestStatement ) { |
|
71 | - $allBestStatements->addStatement( $bestStatement ); |
|
70 | + foreach ($bestStatements as $bestStatement) { |
|
71 | + $allBestStatements->addStatement($bestStatement); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | return $allBestStatements; |
@@ -90,20 +90,20 @@ discard block |
||
90 | 90 | array $qualifierPropertyIds |
91 | 91 | ): StatementList { |
92 | 92 | $similarStatements = new StatementList(); |
93 | - foreach ( $allStatements as $statement ) { |
|
94 | - if ( $statement === $currentStatement ) { |
|
93 | + foreach ($allStatements as $statement) { |
|
94 | + if ($statement === $currentStatement) { |
|
95 | 95 | // if the statement has an “unknown value” qualifier, |
96 | 96 | // it might be considered different from itself, |
97 | 97 | // so add it explicitly to ensure it’s always included |
98 | - $similarStatements->addStatement( $statement ); |
|
98 | + $similarStatements->addStatement($statement); |
|
99 | 99 | continue; |
100 | 100 | } |
101 | - foreach ( $qualifierPropertyIds as $qualifierPropertyId ) { |
|
102 | - if ( !$this->haveSameQualifiers( $currentStatement, $statement, $qualifierPropertyId ) ) { |
|
101 | + foreach ($qualifierPropertyIds as $qualifierPropertyId) { |
|
102 | + if (!$this->haveSameQualifiers($currentStatement, $statement, $qualifierPropertyId)) { |
|
103 | 103 | continue 2; |
104 | 104 | } |
105 | 105 | } |
106 | - $similarStatements->addStatement( $statement ); |
|
106 | + $similarStatements->addStatement($statement); |
|
107 | 107 | } |
108 | 108 | return $similarStatements; |
109 | 109 | } |
@@ -112,19 +112,19 @@ discard block |
||
112 | 112 | * Tests whether two statements have the same qualifiers with a certain property ID. |
113 | 113 | * “unknown value” qualifiers are considered different from each other. |
114 | 114 | */ |
115 | - private function haveSameQualifiers( Statement $s1, Statement $s2, PropertyId $propertyId ): bool { |
|
116 | - $q1 = $this->getSnaksWithPropertyId( $s1->getQualifiers(), $propertyId ); |
|
117 | - $q2 = $this->getSnaksWithPropertyId( $s2->getQualifiers(), $propertyId ); |
|
115 | + private function haveSameQualifiers(Statement $s1, Statement $s2, PropertyId $propertyId): bool { |
|
116 | + $q1 = $this->getSnaksWithPropertyId($s1->getQualifiers(), $propertyId); |
|
117 | + $q2 = $this->getSnaksWithPropertyId($s2->getQualifiers(), $propertyId); |
|
118 | 118 | |
119 | - if ( $q1->count() !== $q2->count() ) { |
|
119 | + if ($q1->count() !== $q2->count()) { |
|
120 | 120 | return false; |
121 | 121 | } |
122 | 122 | |
123 | - foreach ( $q1 as $qualifier ) { |
|
124 | - switch ( $qualifier->getType() ) { |
|
123 | + foreach ($q1 as $qualifier) { |
|
124 | + switch ($qualifier->getType()) { |
|
125 | 125 | case 'value': |
126 | 126 | case 'novalue': |
127 | - if ( !$q2->hasSnak( $qualifier ) ) { |
|
127 | + if (!$q2->hasSnak($qualifier)) { |
|
128 | 128 | return false; |
129 | 129 | } |
130 | 130 | break; |
@@ -142,12 +142,12 @@ discard block |
||
142 | 142 | /** |
143 | 143 | * Returns the snaks of the given snak list with the specified property ID. |
144 | 144 | */ |
145 | - private function getSnaksWithPropertyId( SnakList $allSnaks, PropertyId $propertyId ): SnakList { |
|
145 | + private function getSnaksWithPropertyId(SnakList $allSnaks, PropertyId $propertyId): SnakList { |
|
146 | 146 | $snaks = new SnakList(); |
147 | 147 | /** @var Snak $snak */ |
148 | - foreach ( $allSnaks as $snak ) { |
|
149 | - if ( $snak->getPropertyId()->equals( $propertyId ) ) { |
|
150 | - $snaks->addSnak( $snak ); |
|
148 | + foreach ($allSnaks as $snak) { |
|
149 | + if ($snak->getPropertyId()->equals($propertyId)) { |
|
150 | + $snaks->addSnak($snak); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | return $snaks; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | return new MainSnakContextCursor( |
158 | 158 | $this->entity->getId()->getSerialization(), |
159 | 159 | $this->statement->getPropertyId()->getSerialization(), |
160 | - $this->getStatementGuid( $this->statement ), |
|
160 | + $this->getStatementGuid($this->statement), |
|
161 | 161 | $this->statement->getMainSnak()->getHash() |
162 | 162 | ); |
163 | 163 | } |
@@ -40,93 +40,93 @@ |
||
40 | 40 | public const EXPIRY_LOCK = 'WBQC_ExpiryLock'; |
41 | 41 | public const VIOLATION_MESSAGE_RENDERER_FACTORY = 'WBQC_ViolationMessageRendererFactory'; |
42 | 42 | |
43 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
44 | - if ( $services === null ) { |
|
43 | + private static function getService(?MediaWikiServices $services, $name) { |
|
44 | + if ($services === null) { |
|
45 | 45 | $services = MediaWikiServices::getInstance(); |
46 | 46 | } |
47 | - return $services->getService( $name ); |
|
47 | + return $services->getService($name); |
|
48 | 48 | } |
49 | 49 | |
50 | - public static function getLoggingHelper( MediaWikiServices $services = null ): LoggingHelper { |
|
51 | - return self::getService( $services, self::LOGGING_HELPER ); |
|
50 | + public static function getLoggingHelper(MediaWikiServices $services = null): LoggingHelper { |
|
51 | + return self::getService($services, self::LOGGING_HELPER); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | public static function getConstraintStore( |
55 | 55 | MediaWikiServices $services = null |
56 | 56 | ): ConstraintStore { |
57 | - return self::getService( $services, self::CONSTRAINT_STORE ); |
|
57 | + return self::getService($services, self::CONSTRAINT_STORE); |
|
58 | 58 | } |
59 | 59 | |
60 | - public static function getConstraintLookup( MediaWikiServices $services = null ): ConstraintLookup { |
|
61 | - return self::getService( $services, self::CONSTRAINT_LOOKUP ); |
|
60 | + public static function getConstraintLookup(MediaWikiServices $services = null): ConstraintLookup { |
|
61 | + return self::getService($services, self::CONSTRAINT_LOOKUP); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | public static function getCheckResultSerializer( |
65 | 65 | MediaWikiServices $services = null |
66 | 66 | ): CheckResultSerializer { |
67 | - return self::getService( $services, self::CHECK_RESULT_SERIALIZER ); |
|
67 | + return self::getService($services, self::CHECK_RESULT_SERIALIZER); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | public static function getCheckResultDeserializer( |
71 | 71 | MediaWikiServices $services = null |
72 | 72 | ): CheckResultDeserializer { |
73 | - return self::getService( $services, self::CHECK_RESULT_DESERIALIZER ); |
|
73 | + return self::getService($services, self::CHECK_RESULT_DESERIALIZER); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | public static function getViolationMessageSerializer( |
77 | 77 | MediaWikiServices $services = null |
78 | 78 | ): ViolationMessageSerializer { |
79 | - return self::getService( $services, self::VIOLATION_MESSAGE_SERIALIZER ); |
|
79 | + return self::getService($services, self::VIOLATION_MESSAGE_SERIALIZER); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | public static function getViolationMessageDeserializer( |
83 | 83 | MediaWikiServices $services = null |
84 | 84 | ): ViolationMessageDeserializer { |
85 | - return self::getService( $services, self::VIOLATION_MESSAGE_DESERIALIZER ); |
|
85 | + return self::getService($services, self::VIOLATION_MESSAGE_DESERIALIZER); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | public static function getConstraintParameterParser( |
89 | 89 | MediaWikiServices $services = null |
90 | 90 | ): ConstraintParameterParser { |
91 | - return self::getService( $services, self::CONSTRAINT_PARAMETER_PARSER ); |
|
91 | + return self::getService($services, self::CONSTRAINT_PARAMETER_PARSER); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | public static function getConnectionCheckerHelper( |
95 | 95 | MediaWikiServices $services = null |
96 | 96 | ): ConnectionCheckerHelper { |
97 | - return self::getService( $services, self::CONNECTION_CHECKER_HELPER ); |
|
97 | + return self::getService($services, self::CONNECTION_CHECKER_HELPER); |
|
98 | 98 | } |
99 | 99 | |
100 | - public static function getRangeCheckerHelper( MediaWikiServices $services = null ): RangeCheckerHelper { |
|
101 | - return self::getService( $services, self::RANGE_CHECKER_HELPER ); |
|
100 | + public static function getRangeCheckerHelper(MediaWikiServices $services = null): RangeCheckerHelper { |
|
101 | + return self::getService($services, self::RANGE_CHECKER_HELPER); |
|
102 | 102 | } |
103 | 103 | |
104 | - public static function getSparqlHelper( MediaWikiServices $services = null ): SparqlHelper { |
|
105 | - return self::getService( $services, self::SPARQL_HELPER ); |
|
104 | + public static function getSparqlHelper(MediaWikiServices $services = null): SparqlHelper { |
|
105 | + return self::getService($services, self::SPARQL_HELPER); |
|
106 | 106 | } |
107 | 107 | |
108 | - public static function getTypeCheckerHelper( MediaWikiServices $services = null ): TypeCheckerHelper { |
|
109 | - return self::getService( $services, self::TYPE_CHECKER_HELPER ); |
|
108 | + public static function getTypeCheckerHelper(MediaWikiServices $services = null): TypeCheckerHelper { |
|
109 | + return self::getService($services, self::TYPE_CHECKER_HELPER); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | public static function getDelegatingConstraintChecker( |
113 | 113 | MediaWikiServices $services = null |
114 | 114 | ): DelegatingConstraintChecker { |
115 | - return self::getService( $services, self::DELEGATING_CONSTRAINT_CHECKER ); |
|
115 | + return self::getService($services, self::DELEGATING_CONSTRAINT_CHECKER); |
|
116 | 116 | } |
117 | 117 | |
118 | - public static function getResultsSource( MediaWikiServices $services = null ): ResultsSource { |
|
119 | - return self::getService( $services, self::RESULTS_SOURCE ); |
|
118 | + public static function getResultsSource(MediaWikiServices $services = null): ResultsSource { |
|
119 | + return self::getService($services, self::RESULTS_SOURCE); |
|
120 | 120 | } |
121 | 121 | |
122 | - public static function getExpiryLock( MediaWikiServices $services = null ): ExpiryLock { |
|
123 | - return self::getService( $services, self::EXPIRY_LOCK ); |
|
122 | + public static function getExpiryLock(MediaWikiServices $services = null): ExpiryLock { |
|
123 | + return self::getService($services, self::EXPIRY_LOCK); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | public static function getViolationMessageRendererFactory( |
127 | 127 | MediaWikiServices $services = null |
128 | 128 | ): ViolationMessageRendererFactory { |
129 | - return self::getService( $services, self::VIOLATION_MESSAGE_RENDERER_FACTORY ); |
|
129 | + return self::getService($services, self::VIOLATION_MESSAGE_RENDERER_FACTORY); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | } |
@@ -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 | |
@@ -62,17 +62,17 @@ discard block |
||
62 | 62 | $this->maxListLength = $maxListLength; |
63 | 63 | } |
64 | 64 | |
65 | - public function render( ViolationMessage $violationMessage ): string { |
|
65 | + public function render(ViolationMessage $violationMessage): string { |
|
66 | 66 | $messageKey = $violationMessage->getMessageKey(); |
67 | - $paramsLists = [ [] ]; |
|
68 | - foreach ( $violationMessage->getArguments() as $argument ) { |
|
69 | - $params = $this->renderArgument( $argument ); |
|
67 | + $paramsLists = [[]]; |
|
68 | + foreach ($violationMessage->getArguments() as $argument) { |
|
69 | + $params = $this->renderArgument($argument); |
|
70 | 70 | $paramsLists[] = $params; |
71 | 71 | } |
72 | - $allParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
72 | + $allParams = call_user_func_array('array_merge', $paramsLists); |
|
73 | 73 | return $this->messageLocalizer |
74 | - ->msg( $messageKey ) |
|
75 | - ->params( $allParams ) |
|
74 | + ->msg($messageKey) |
|
75 | + ->params($allParams) |
|
76 | 76 | ->escaped(); |
77 | 77 | } |
78 | 78 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | * @param string|null $role one of the Role::* constants |
82 | 82 | * @return string HTML |
83 | 83 | */ |
84 | - protected function addRole( string $value, ?string $role ): string { |
|
85 | - if ( $role === null ) { |
|
84 | + protected function addRole(string $value, ?string $role): string { |
|
85 | + if ($role === null) { |
|
86 | 86 | return $value; |
87 | 87 | } |
88 | 88 | |
89 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' . |
|
90 | - $value . |
|
89 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'. |
|
90 | + $value. |
|
91 | 91 | '</span>'; |
92 | 92 | } |
93 | 93 | |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | * @param string $key message key |
96 | 96 | * @return string HTML |
97 | 97 | */ |
98 | - protected function msgEscaped( string $key ): string { |
|
99 | - return $this->messageLocalizer->msg( $key )->escaped(); |
|
98 | + protected function msgEscaped(string $key): string { |
|
99 | + return $this->messageLocalizer->msg($key)->escaped(); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | 103 | * @param array $argument |
104 | 104 | * @return array[] params (for Message::params) |
105 | 105 | */ |
106 | - protected function renderArgument( array $argument ): array { |
|
106 | + protected function renderArgument(array $argument): array { |
|
107 | 107 | $methods = [ |
108 | 108 | ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId', |
109 | 109 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList', |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | $value = $argument['value']; |
125 | 125 | $role = $argument['role']; |
126 | 126 | |
127 | - if ( array_key_exists( $type, $methods ) ) { |
|
127 | + if (array_key_exists($type, $methods)) { |
|
128 | 128 | $method = $methods[$type]; |
129 | - $params = $this->$method( $value, $role ); |
|
129 | + $params = $this->$method($value, $role); |
|
130 | 130 | } else { |
131 | 131 | throw new InvalidArgumentException( |
132 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
132 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
133 | 133 | ); |
134 | 134 | } |
135 | 135 | |
@@ -143,36 +143,36 @@ discard block |
||
143 | 143 | * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ]) |
144 | 144 | * @return array[] list of parameters as accepted by Message::params() |
145 | 145 | */ |
146 | - private function renderList( array $list, ?string $role, callable $render ): array { |
|
147 | - if ( $list === [] ) { |
|
146 | + private function renderList(array $list, ?string $role, callable $render): array { |
|
147 | + if ($list === []) { |
|
148 | 148 | return [ |
149 | - Message::numParam( 0 ), |
|
150 | - Message::rawParam( '<ul></ul>' ), |
|
149 | + Message::numParam(0), |
|
150 | + Message::rawParam('<ul></ul>'), |
|
151 | 151 | ]; |
152 | 152 | } |
153 | 153 | |
154 | - if ( count( $list ) > $this->maxListLength ) { |
|
155 | - $list = array_slice( $list, 0, $this->maxListLength ); |
|
154 | + if (count($list) > $this->maxListLength) { |
|
155 | + $list = array_slice($list, 0, $this->maxListLength); |
|
156 | 156 | $truncated = true; |
157 | 157 | } |
158 | 158 | |
159 | 159 | $renderedParamsLists = array_map( |
160 | 160 | $render, |
161 | 161 | $list, |
162 | - array_fill( 0, count( $list ), $role ) |
|
162 | + array_fill(0, count($list), $role) |
|
163 | 163 | ); |
164 | - $renderedParams = array_column( $renderedParamsLists, 0 ); |
|
165 | - $renderedElements = array_column( $renderedParams, 'raw' ); |
|
166 | - if ( isset( $truncated ) ) { |
|
167 | - $renderedElements[] = $this->msgEscaped( 'ellipsis' ); |
|
164 | + $renderedParams = array_column($renderedParamsLists, 0); |
|
165 | + $renderedElements = array_column($renderedParams, 'raw'); |
|
166 | + if (isset($truncated)) { |
|
167 | + $renderedElements[] = $this->msgEscaped('ellipsis'); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | return array_merge( |
171 | 171 | [ |
172 | - Message::numParam( count( $list ) ), |
|
172 | + Message::numParam(count($list)), |
|
173 | 173 | Message::rawParam( |
174 | - '<ul><li>' . |
|
175 | - implode( '</li><li>', $renderedElements ) . |
|
174 | + '<ul><li>'. |
|
175 | + implode('</li><li>', $renderedElements). |
|
176 | 176 | '</li></ul>' |
177 | 177 | ), |
178 | 178 | ], |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | * @param string|null $role one of the Role::* constants |
186 | 186 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
187 | 187 | */ |
188 | - private function renderEntityId( EntityId $entityId, ?string $role ): array { |
|
189 | - return [ Message::rawParam( $this->addRole( |
|
190 | - $this->entityIdFormatter->formatEntityId( $entityId ), |
|
188 | + private function renderEntityId(EntityId $entityId, ?string $role): array { |
|
189 | + return [Message::rawParam($this->addRole( |
|
190 | + $this->entityIdFormatter->formatEntityId($entityId), |
|
191 | 191 | $role |
192 | - ) ) ]; |
|
192 | + ))]; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * @param string|null $role one of the Role::* constants |
198 | 198 | * @return array[] list of parameters as accepted by Message::params() |
199 | 199 | */ |
200 | - private function renderEntityIdList( array $entityIdList, ?string $role ): array { |
|
201 | - return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] ); |
|
200 | + private function renderEntityIdList(array $entityIdList, ?string $role): array { |
|
201 | + return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -206,24 +206,24 @@ discard block |
||
206 | 206 | * @param string|null $role one of the Role::* constants |
207 | 207 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
208 | 208 | */ |
209 | - private function renderItemIdSnakValue( ItemIdSnakValue $value, ?string $role ): array { |
|
210 | - switch ( true ) { |
|
209 | + private function renderItemIdSnakValue(ItemIdSnakValue $value, ?string $role): array { |
|
210 | + switch (true) { |
|
211 | 211 | case $value->isValue(): |
212 | - return $this->renderEntityId( $value->getItemId(), $role ); |
|
212 | + return $this->renderEntityId($value->getItemId(), $role); |
|
213 | 213 | case $value->isSomeValue(): |
214 | - return [ Message::rawParam( $this->addRole( |
|
215 | - '<span class="wikibase-snakview-variation-somevaluesnak">' . |
|
216 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-somevalue' ) . |
|
214 | + return [Message::rawParam($this->addRole( |
|
215 | + '<span class="wikibase-snakview-variation-somevaluesnak">'. |
|
216 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-somevalue'). |
|
217 | 217 | '</span>', |
218 | 218 | $role |
219 | - ) ) ]; |
|
219 | + ))]; |
|
220 | 220 | case $value->isNoValue(): |
221 | - return [ Message::rawParam( $this->addRole( |
|
222 | - '<span class="wikibase-snakview-variation-novaluesnak">' . |
|
223 | - $this->msgEscaped( 'wikibase-snakview-snaktypeselector-novalue' ) . |
|
221 | + return [Message::rawParam($this->addRole( |
|
222 | + '<span class="wikibase-snakview-variation-novaluesnak">'. |
|
223 | + $this->msgEscaped('wikibase-snakview-snaktypeselector-novalue'). |
|
224 | 224 | '</span>', |
225 | 225 | $role |
226 | - ) ) ]; |
|
226 | + ))]; |
|
227 | 227 | default: |
228 | 228 | // @codeCoverageIgnoreStart |
229 | 229 | throw new LogicException( |
@@ -238,8 +238,8 @@ discard block |
||
238 | 238 | * @param string|null $role one of the Role::* constants |
239 | 239 | * @return array[] list of parameters as accepted by Message::params() |
240 | 240 | */ |
241 | - private function renderItemIdSnakValueList( array $valueList, ?string $role ): array { |
|
242 | - return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] ); |
|
241 | + private function renderItemIdSnakValueList(array $valueList, ?string $role): array { |
|
242 | + return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -247,11 +247,11 @@ discard block |
||
247 | 247 | * @param string|null $role one of the Role::* constants |
248 | 248 | * @return array[] list of parameters as accepted by Message::params() |
249 | 249 | */ |
250 | - private function renderDataValue( DataValue $dataValue, ?string $role ): array { |
|
251 | - return [ Message::rawParam( $this->addRole( |
|
252 | - $this->dataValueFormatter->format( $dataValue ), |
|
250 | + private function renderDataValue(DataValue $dataValue, ?string $role): array { |
|
251 | + return [Message::rawParam($this->addRole( |
|
252 | + $this->dataValueFormatter->format($dataValue), |
|
253 | 253 | $role |
254 | - ) ) ]; |
|
254 | + ))]; |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * @param string|null $role one of the Role::* constants |
260 | 260 | * @return array[] list of parameters as accepted by Message::params() |
261 | 261 | */ |
262 | - private function renderDataValueType( string $dataValueType, ?string $role ): array { |
|
262 | + private function renderDataValueType(string $dataValueType, ?string $role): array { |
|
263 | 263 | $messageKeys = [ |
264 | 264 | 'string' => 'datatypes-type-string', |
265 | 265 | 'monolingualtext' => 'datatypes-type-monolingualtext', |
@@ -268,15 +268,15 @@ discard block |
||
268 | 268 | 'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid', |
269 | 269 | ]; |
270 | 270 | |
271 | - if ( array_key_exists( $dataValueType, $messageKeys ) ) { |
|
272 | - return [ Message::rawParam( $this->addRole( |
|
273 | - $this->msgEscaped( $messageKeys[$dataValueType] ), |
|
271 | + if (array_key_exists($dataValueType, $messageKeys)) { |
|
272 | + return [Message::rawParam($this->addRole( |
|
273 | + $this->msgEscaped($messageKeys[$dataValueType]), |
|
274 | 274 | $role |
275 | - ) ) ]; |
|
275 | + ))]; |
|
276 | 276 | } else { |
277 | 277 | // @codeCoverageIgnoreStart |
278 | 278 | throw new LogicException( |
279 | - 'Unknown data value type ' . $dataValueType |
|
279 | + 'Unknown data value type '.$dataValueType |
|
280 | 280 | ); |
281 | 281 | // @codeCoverageIgnoreEnd |
282 | 282 | } |
@@ -287,11 +287,11 @@ discard block |
||
287 | 287 | * @param string|null $role one of the Role::* constants |
288 | 288 | * @return array[] list of parameters as accepted by Message::params() |
289 | 289 | */ |
290 | - private function renderInlineCode( string $code, ?string $role ): array { |
|
291 | - return [ Message::rawParam( $this->addRole( |
|
292 | - '<code>' . htmlspecialchars( $code ) . '</code>', |
|
290 | + private function renderInlineCode(string $code, ?string $role): array { |
|
291 | + return [Message::rawParam($this->addRole( |
|
292 | + '<code>'.htmlspecialchars($code).'</code>', |
|
293 | 293 | $role |
294 | - ) ) ]; |
|
294 | + ))]; |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | * @param string|null $role one of the Role::* constants |
300 | 300 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
301 | 301 | */ |
302 | - private function renderConstraintScope( string $scope, ?string $role ): array { |
|
303 | - switch ( $scope ) { |
|
302 | + private function renderConstraintScope(string $scope, ?string $role): array { |
|
303 | + switch ($scope) { |
|
304 | 304 | case Context::TYPE_STATEMENT: |
305 | 305 | $itemId = $this->config->get( |
306 | 306 | 'WBQualityConstraintsConstraintCheckedOnMainValueId' |
@@ -320,10 +320,10 @@ discard block |
||
320 | 320 | // callers should never let this happen, but if it does happen, |
321 | 321 | // showing “unknown value” seems reasonable |
322 | 322 | // @codeCoverageIgnoreStart |
323 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
323 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
324 | 324 | // @codeCoverageIgnoreEnd |
325 | 325 | } |
326 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
326 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -331,8 +331,8 @@ discard block |
||
331 | 331 | * @param string|null $role one of the Role::* constants |
332 | 332 | * @return array[] list of parameters as accepted by Message::params() |
333 | 333 | */ |
334 | - private function renderConstraintScopeList( array $scopeList, ?string $role ): array { |
|
335 | - return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] ); |
|
334 | + private function renderConstraintScopeList(array $scopeList, ?string $role): array { |
|
335 | + return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -340,25 +340,25 @@ discard block |
||
340 | 340 | * @param string|null $role one of the Role::* constants |
341 | 341 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
342 | 342 | */ |
343 | - private function renderPropertyScope( string $scope, ?string $role ): array { |
|
344 | - switch ( $scope ) { |
|
343 | + private function renderPropertyScope(string $scope, ?string $role): array { |
|
344 | + switch ($scope) { |
|
345 | 345 | case Context::TYPE_STATEMENT: |
346 | - $itemId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
346 | + $itemId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
347 | 347 | break; |
348 | 348 | case Context::TYPE_QUALIFIER: |
349 | - $itemId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
349 | + $itemId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
350 | 350 | break; |
351 | 351 | case Context::TYPE_REFERENCE: |
352 | - $itemId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
352 | + $itemId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
353 | 353 | break; |
354 | 354 | default: |
355 | 355 | // callers should never let this happen, but if it does happen, |
356 | 356 | // showing “unknown value” seems reasonable |
357 | 357 | // @codeCoverageIgnoreStart |
358 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
358 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
359 | 359 | // @codeCoverageIgnoreEnd |
360 | 360 | } |
361 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
361 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -366,8 +366,8 @@ discard block |
||
366 | 366 | * @param string|null $role one of the Role::* constants |
367 | 367 | * @return array[] list of parameters as accepted by Message::params() |
368 | 368 | */ |
369 | - private function renderPropertyScopeList( array $scopeList, ?string $role ): array { |
|
370 | - return $this->renderList( $scopeList, $role, [ $this, 'renderPropertyScope' ] ); |
|
369 | + private function renderPropertyScopeList(array $scopeList, ?string $role): array { |
|
370 | + return $this->renderList($scopeList, $role, [$this, 'renderPropertyScope']); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -375,14 +375,14 @@ discard block |
||
375 | 375 | * @param string|null $role one of the Role::* constants |
376 | 376 | * @return array[] list of parameters as accepted by Message::params() |
377 | 377 | */ |
378 | - private function renderLanguage( string $languageCode, ?string $role ): array { |
|
378 | + private function renderLanguage(string $languageCode, ?string $role): array { |
|
379 | 379 | return [ |
380 | 380 | // ::renderList (through ::renderLanguageList) requires 'raw' parameter |
381 | 381 | // so we effectively build Message::plaintextParam here |
382 | - Message::rawParam( htmlspecialchars( |
|
383 | - $this->languageNameUtils->getLanguageName( $languageCode, $this->userLanguageCode ) |
|
384 | - ) ), |
|
385 | - Message::plaintextParam( $languageCode ), |
|
382 | + Message::rawParam(htmlspecialchars( |
|
383 | + $this->languageNameUtils->getLanguageName($languageCode, $this->userLanguageCode) |
|
384 | + )), |
|
385 | + Message::plaintextParam($languageCode), |
|
386 | 386 | ]; |
387 | 387 | } |
388 | 388 | |
@@ -391,8 +391,8 @@ discard block |
||
391 | 391 | * @param string|null $role one of the Role::* constants |
392 | 392 | * @return array[] list of parameters as accepted by Message::params() |
393 | 393 | */ |
394 | - private function renderLanguageList( array $languageCodes, ?string $role ): array { |
|
395 | - return $this->renderList( $languageCodes, $role, [ $this, 'renderLanguage' ] ); |
|
394 | + private function renderLanguageList(array $languageCodes, ?string $role): array { |
|
395 | + return $this->renderList($languageCodes, $role, [$this, 'renderLanguage']); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | } |
@@ -28,27 +28,27 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param DatabaseUpdater $updater |
30 | 30 | */ |
31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
32 | - $dir = dirname( __DIR__ ) . '/sql/'; |
|
31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
32 | + $dir = dirname(__DIR__).'/sql/'; |
|
33 | 33 | |
34 | 34 | $updater->addExtensionTable( |
35 | 35 | 'wbqc_constraints', |
36 | - $dir . "/{$updater->getDB()->getType()}/tables-generated.sql" |
|
36 | + $dir."/{$updater->getDB()->getType()}/tables-generated.sql" |
|
37 | 37 | ); |
38 | 38 | $updater->addExtensionField( |
39 | 39 | 'wbqc_constraints', |
40 | 40 | 'constraint_id', |
41 | - $dir . '/patch-wbqc_constraints-constraint_id.sql' |
|
41 | + $dir.'/patch-wbqc_constraints-constraint_id.sql' |
|
42 | 42 | ); |
43 | 43 | $updater->addExtensionIndex( |
44 | 44 | 'wbqc_constraints', |
45 | 45 | 'wbqc_constraints_guid_uniq', |
46 | - $dir . '/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
46 | + $dir.'/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
47 | 47 | ); |
48 | 48 | } |
49 | 49 | |
50 | - public static function onWikibaseChange( Change $change ) { |
|
51 | - if ( !( $change instanceof EntityChange ) ) { |
|
50 | + public static function onWikibaseChange(Change $change) { |
|
51 | + if (!($change instanceof EntityChange)) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | /** @var EntityChange $change */ |
@@ -59,48 +59,48 @@ discard block |
||
59 | 59 | |
60 | 60 | // If jobs are enabled and the results would be stored in some way run a job. |
61 | 61 | if ( |
62 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
63 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
62 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
63 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
64 | 64 | self::isSelectedForJobRunBasedOnPercentage() |
65 | 65 | ) { |
66 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
66 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
67 | 67 | $jobQueueGroup->lazyPush( |
68 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
68 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
69 | 69 | ); |
70 | 70 | } |
71 | 71 | |
72 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
73 | - self::isConstraintStatementsChange( $config, $change ) |
|
72 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
73 | + self::isConstraintStatementsChange($config, $change) |
|
74 | 74 | ) { |
75 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
75 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
76 | 76 | $metadata = $change->getMetadata(); |
77 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
77 | + if (array_key_exists('rev_id', $metadata)) { |
|
78 | 78 | $params['revisionId'] = $metadata['rev_id']; |
79 | 79 | } |
80 | 80 | $jobQueueGroup->push( |
81 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
81 | + new JobSpecification('constraintsTableUpdate', $params) |
|
82 | 82 | ); |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | 86 | private static function isSelectedForJobRunBasedOnPercentage() { |
87 | 87 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
88 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
88 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
89 | 89 | |
90 | - return mt_rand( 1, 100 ) <= $percentage; |
|
90 | + return mt_rand(1, 100) <= $percentage; |
|
91 | 91 | } |
92 | 92 | |
93 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
94 | - if ( !( $change instanceof EntityChange ) || |
|
93 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
94 | + if (!($change instanceof EntityChange) || |
|
95 | 95 | $change->getAction() !== EntityChange::UPDATE || |
96 | - !( $change->getEntityId() instanceof NumericPropertyId ) |
|
96 | + !($change->getEntityId() instanceof NumericPropertyId) |
|
97 | 97 | ) { |
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | |
101 | 101 | $info = $change->getInfo(); |
102 | 102 | |
103 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
103 | + if (!array_key_exists('compactDiff', $info)) { |
|
104 | 104 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
105 | 105 | // so we only know that the change *might* affect the constraint statements |
106 | 106 | return true; |
@@ -109,50 +109,50 @@ discard block |
||
109 | 109 | /** @var EntityDiffChangedAspects $aspects */ |
110 | 110 | $aspects = $info['compactDiff']; |
111 | 111 | |
112 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
113 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
112 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
113 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
114 | 114 | } |
115 | 115 | |
116 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
116 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
117 | 117 | $entityContentFactory = WikibaseRepo::getEntityContentFactory(); |
118 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
118 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
119 | 119 | $entityIdLookup = WikibaseRepo::getEntityIdLookup(); |
120 | - $entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
121 | - if ( $entityId !== null ) { |
|
120 | + $entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle()); |
|
121 | + if ($entityId !== null) { |
|
122 | 122 | $resultsCache = ResultsCache::getDefaultInstance(); |
123 | - $resultsCache->delete( $entityId ); |
|
123 | + $resultsCache->delete($entityId); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
128 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
129 | 129 | $lookup = WikibaseRepo::getEntityNamespaceLookup(); |
130 | 130 | $title = $out->getTitle(); |
131 | - if ( $title === null ) { |
|
131 | + if ($title === null) { |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
135 | - if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) { |
|
135 | + if (!$lookup->isNamespaceWithEntities($title->getNamespace())) { |
|
136 | 136 | return; |
137 | 137 | } |
138 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
138 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | 142 | $services = MediaWikiServices::getInstance(); |
143 | 143 | $config = $services->getMainConfig(); |
144 | 144 | |
145 | - $isMobileView = ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) && |
|
146 | - $services->getService( 'MobileFrontend.Context' )->shouldDisplayMobileView(); |
|
147 | - if ( $isMobileView ) { |
|
145 | + $isMobileView = ExtensionRegistry::getInstance()->isLoaded('MobileFrontend') && |
|
146 | + $services->getService('MobileFrontend.Context')->shouldDisplayMobileView(); |
|
147 | + if ($isMobileView) { |
|
148 | 148 | return; |
149 | 149 | } |
150 | 150 | |
151 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
151 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
152 | 152 | |
153 | - if ( $config->get( 'WBQualityConstraintsShowConstraintViolationToNonLoggedInUsers' ) |
|
154 | - || $out->getUser()->isRegistered() ) { |
|
155 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
153 | + if ($config->get('WBQualityConstraintsShowConstraintViolationToNonLoggedInUsers') |
|
154 | + || $out->getUser()->isRegistered()) { |
|
155 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 |