@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | * @throws ConstraintParameterException |
77 | 77 | * @return CheckResult |
78 | 78 | */ |
79 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
80 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
81 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
79 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
80 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
81 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -90,50 +90,50 @@ discard block |
||
90 | 90 | true |
91 | 91 | ); |
92 | 92 | |
93 | - $message = ( new ViolationMessage( 'wbqc-violation-message-language' ) ) |
|
94 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
95 | - ->withItemIdSnakValueList( $languages, Role::OBJECT ); |
|
93 | + $message = (new ViolationMessage('wbqc-violation-message-language')) |
|
94 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
95 | + ->withItemIdSnakValueList($languages, Role::OBJECT); |
|
96 | 96 | $status = CheckResult::STATUS_VIOLATION; |
97 | 97 | |
98 | - $lexeme = $this->getLexeme( $context ); |
|
99 | - if ( !$lexeme ) { |
|
98 | + $lexeme = $this->getLexeme($context); |
|
99 | + if (!$lexeme) { |
|
100 | 100 | // Lexeme doesn't exist, let's not bother |
101 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE ); |
|
101 | + return new CheckResult($context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** @var Lexeme $lexeme */ |
105 | 105 | '@phan-var Lexeme $lexeme'; |
106 | 106 | |
107 | - foreach ( $languages as $language ) { |
|
108 | - if ( $language->isNoValue() || $language->isSomeValue() ) { |
|
107 | + foreach ($languages as $language) { |
|
108 | + if ($language->isNoValue() || $language->isSomeValue()) { |
|
109 | 109 | continue; |
110 | 110 | } |
111 | - if ( $lexeme->getLanguage()->equals( $language->getItemId() ) ) { |
|
111 | + if ($lexeme->getLanguage()->equals($language->getItemId())) { |
|
112 | 112 | $message = null; |
113 | 113 | $status = CheckResult::STATUS_COMPLIANCE; |
114 | 114 | break; |
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | - return new CheckResult( $context, $constraint, $status, $message ); |
|
118 | + return new CheckResult($context, $constraint, $status, $message); |
|
119 | 119 | } |
120 | 120 | |
121 | - private function getLexeme( Context $context ): ?EntityDocument { |
|
121 | + private function getLexeme(Context $context): ?EntityDocument { |
|
122 | 122 | $entityType = $context->getEntity()->getType(); |
123 | 123 | |
124 | - if ( $entityType === Lexeme::ENTITY_TYPE ) { |
|
124 | + if ($entityType === Lexeme::ENTITY_TYPE) { |
|
125 | 125 | return $context->getEntity(); |
126 | 126 | } |
127 | 127 | |
128 | - if ( in_array( $entityType, [ Form::ENTITY_TYPE, Sense::ENTITY_TYPE ] ) ) { |
|
128 | + if (in_array($entityType, [Form::ENTITY_TYPE, Sense::ENTITY_TYPE])) { |
|
129 | 129 | /** @var LexemeSubEntityId $id */ |
130 | 130 | $id = $context->getEntity()->getId(); |
131 | 131 | '@phan-var LexemeSubEntityId $id'; |
132 | - return $this->entityLookup->getEntity( $id->getLexemeId() ); |
|
132 | + return $this->entityLookup->getEntity($id->getLexemeId()); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
136 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
137 | 137 | $constraintParameters = $constraint->getConstraintParameters(); |
138 | 138 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
139 | 139 | $exceptions = []; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $constraintTypeItemId, |
144 | 144 | true |
145 | 145 | ); |
146 | - } catch ( ConstraintParameterException $e ) { |
|
146 | + } catch (ConstraintParameterException $e) { |
|
147 | 147 | $exceptions[] = $e; |
148 | 148 | } |
149 | 149 | return $exceptions; |
@@ -36,17 +36,17 @@ discard block |
||
36 | 36 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
37 | 37 | } |
38 | 38 | |
39 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
39 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
40 | 40 | $snak = $context->getSnak(); |
41 | 41 | |
42 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
42 | + if (!$snak instanceof PropertyValueSnak) { |
|
43 | 43 | // nothing to check |
44 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
44 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
45 | 45 | } |
46 | 46 | |
47 | - if ( $snak->getDataValue() instanceof QuantityValue ) { |
|
48 | - $message = ( new ViolationMessage( 'wbqc-violation-message-noBounds' ) ) |
|
49 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ); |
|
47 | + if ($snak->getDataValue() instanceof QuantityValue) { |
|
48 | + $message = (new ViolationMessage('wbqc-violation-message-noBounds')) |
|
49 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY); |
|
50 | 50 | return new CheckResult( |
51 | 51 | $context, |
52 | 52 | $constraint, |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | ); |
56 | 56 | } |
57 | 57 | |
58 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
58 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
59 | 59 | } |
60 | 60 | |
61 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
61 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
62 | 62 | // no parameters |
63 | 63 | return []; |
64 | 64 | } |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | * @throws ConstraintParameterException |
90 | 90 | * @return CheckResult |
91 | 91 | */ |
92 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
93 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
94 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
92 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
93 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
94 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | |
105 | 105 | $snak = $context->getSnak(); |
106 | 106 | |
107 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
107 | + if (!$snak instanceof PropertyValueSnak) { |
|
108 | 108 | // nothing to check |
109 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
109 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | $dataValue = $snak->getDataValue(); |
@@ -115,18 +115,18 @@ discard block |
||
115 | 115 | * error handling: |
116 | 116 | * type of $dataValue for properties with 'Inverse' constraint has to be 'wikibase-entityid' |
117 | 117 | */ |
118 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
119 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
120 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
121 | - ->withDataValueType( 'wikibase-entityid' ); |
|
122 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
118 | + if (!$dataValue instanceof EntityIdValue) { |
|
119 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
120 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
121 | + ->withDataValueType('wikibase-entityid'); |
|
122 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | $targetEntityId = $dataValue->getEntityId(); |
126 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
127 | - if ( !$targetEntity instanceof StatementListProvider ) { |
|
128 | - $message = new ViolationMessage( 'wbqc-violation-message-target-entity-must-exist' ); |
|
129 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
126 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
127 | + if (!$targetEntity instanceof StatementListProvider) { |
|
128 | + $message = new ViolationMessage('wbqc-violation-message-target-entity-must-exist'); |
|
129 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | $inverseStatement = $this->connectionCheckerHelper->findStatementWithPropertyAndEntityIdValue( |
@@ -134,23 +134,23 @@ discard block |
||
134 | 134 | $propertyId, |
135 | 135 | $context->getEntity()->getId() |
136 | 136 | ); |
137 | - if ( $inverseStatement !== null ) { |
|
137 | + if ($inverseStatement !== null) { |
|
138 | 138 | $message = null; |
139 | 139 | $status = CheckResult::STATUS_COMPLIANCE; |
140 | 140 | } else { |
141 | - $message = ( new ViolationMessage( 'wbqc-violation-message-inverse' ) ) |
|
142 | - ->withEntityId( $targetEntityId, Role::SUBJECT ) |
|
143 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
144 | - ->withEntityId( $context->getEntity()->getId(), Role::OBJECT ); |
|
141 | + $message = (new ViolationMessage('wbqc-violation-message-inverse')) |
|
142 | + ->withEntityId($targetEntityId, Role::SUBJECT) |
|
143 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
144 | + ->withEntityId($context->getEntity()->getId(), Role::OBJECT); |
|
145 | 145 | $status = CheckResult::STATUS_VIOLATION; |
146 | 146 | } |
147 | 147 | |
148 | - return ( new CheckResult( $context, $constraint, $status, $message ) ) |
|
149 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
150 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
148 | + return (new CheckResult($context, $constraint, $status, $message)) |
|
149 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
150 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
151 | 151 | } |
152 | 152 | |
153 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
153 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
154 | 154 | $constraintParameters = $constraint->getConstraintParameters(); |
155 | 155 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
156 | 156 | $exceptions = []; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $constraintParameters, |
160 | 160 | $constraintTypeItemId |
161 | 161 | ); |
162 | - } catch ( ConstraintParameterException $e ) { |
|
162 | + } catch (ConstraintParameterException $e) { |
|
163 | 163 | $exceptions[] = $e; |
164 | 164 | } |
165 | 165 | return $exceptions; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @codeCoverageIgnore This method is purely declarative. |
81 | 81 | */ |
82 | 82 | public function getDefaultContextTypes(): array { |
83 | - return [ Context::TYPE_STATEMENT ]; |
|
83 | + return [Context::TYPE_STATEMENT]; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** @codeCoverageIgnore This method is purely declarative. */ |
@@ -97,31 +97,31 @@ discard block |
||
97 | 97 | * @return CheckResult |
98 | 98 | * @throws ConfigException |
99 | 99 | */ |
100 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
101 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
102 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
100 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
101 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
102 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
103 | 103 | } |
104 | 104 | $snak = $context->getSnak(); |
105 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
105 | + if (!$snak instanceof PropertyValueSnak) { |
|
106 | 106 | // nothing to check |
107 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
107 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | $dataValue = $snak->getDataValue(); |
111 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
111 | + if (!$dataValue instanceof EntityIdValue) { |
|
112 | 112 | // wrong data type |
113 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
114 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
115 | - ->withDataValueType( 'wikibase-entityid' ); |
|
116 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
113 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
114 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
115 | + ->withDataValueType('wikibase-entityid'); |
|
116 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | $objectId = $dataValue->getEntityId(); |
120 | - $objectItem = $this->entityLookup->getEntity( $objectId ); |
|
121 | - if ( !( $objectItem instanceof StatementListProvider ) ) { |
|
120 | + $objectItem = $this->entityLookup->getEntity($objectId); |
|
121 | + if (!($objectItem instanceof StatementListProvider)) { |
|
122 | 122 | // object was deleted/doesn't exist |
123 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
124 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
123 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
124 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
125 | 125 | } |
126 | 126 | /** @var Statement[] $objectStatements */ |
127 | 127 | $objectStatements = $objectItem->getStatements()->toArray(); |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | $subjectId = $context->getEntity()->getId(); |
130 | 130 | $subjectStatements = $context->getEntity()->getStatements()->toArray(); |
131 | 131 | /** @var String[] $startPropertyIds */ |
132 | - $startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS ); |
|
132 | + $startPropertyIds = $this->config->get(self::CONFIG_VARIABLE_START_PROPERTY_IDS); |
|
133 | 133 | /** @var String[] $endPropertyIds */ |
134 | - $endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS ); |
|
134 | + $endPropertyIds = $this->config->get(self::CONFIG_VARIABLE_END_PROPERTY_IDS); |
|
135 | 135 | $subjectStartValue = $this->getExtremeValue( |
136 | 136 | $startPropertyIds, |
137 | 137 | $subjectStatements, |
@@ -153,15 +153,15 @@ discard block |
||
153 | 153 | 'end' |
154 | 154 | ); |
155 | 155 | if ( |
156 | - $this->rangeCheckerHelper->getComparison( $subjectStartValue, $subjectEndValue ) <= 0 && |
|
157 | - $this->rangeCheckerHelper->getComparison( $objectStartValue, $objectEndValue ) <= 0 && ( |
|
158 | - $this->rangeCheckerHelper->getComparison( $subjectEndValue, $objectStartValue ) < 0 || |
|
159 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectStartValue ) < 0 |
|
156 | + $this->rangeCheckerHelper->getComparison($subjectStartValue, $subjectEndValue) <= 0 && |
|
157 | + $this->rangeCheckerHelper->getComparison($objectStartValue, $objectEndValue) <= 0 && ( |
|
158 | + $this->rangeCheckerHelper->getComparison($subjectEndValue, $objectStartValue) < 0 || |
|
159 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectStartValue) < 0 |
|
160 | 160 | ) |
161 | 161 | ) { |
162 | 162 | if ( |
163 | 163 | $subjectEndValue == null || |
164 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectEndValue ) < 0 |
|
164 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectEndValue) < 0 |
|
165 | 165 | ) { |
166 | 166 | $earlierEntityId = $objectId; |
167 | 167 | $minEndValue = $objectEndValue; |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $message = null; |
187 | 187 | $status = CheckResult::STATUS_COMPLIANCE; |
188 | 188 | } |
189 | - return new CheckResult( $context, $constraint, $status, $message ); |
|
189 | + return new CheckResult($context, $constraint, $status, $message); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -196,19 +196,19 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @return DataValue|null |
198 | 198 | */ |
199 | - private function getExtremeValue( $extremePropertyIds, $statements, $startOrEnd ) { |
|
200 | - if ( $startOrEnd !== 'start' && $startOrEnd !== 'end' ) { |
|
201 | - throw new \InvalidArgumentException( '$startOrEnd must be \'start\' or \'end\'.' ); |
|
199 | + private function getExtremeValue($extremePropertyIds, $statements, $startOrEnd) { |
|
200 | + if ($startOrEnd !== 'start' && $startOrEnd !== 'end') { |
|
201 | + throw new \InvalidArgumentException('$startOrEnd must be \'start\' or \'end\'.'); |
|
202 | 202 | } |
203 | 203 | $extremeValue = null; |
204 | - foreach ( $extremePropertyIds as $extremePropertyId ) { |
|
205 | - $statementList = new StatementList( ...$statements ); |
|
206 | - $extremeStatements = $statementList->getByPropertyId( new NumericPropertyId( $extremePropertyId ) ); |
|
204 | + foreach ($extremePropertyIds as $extremePropertyId) { |
|
205 | + $statementList = new StatementList(...$statements); |
|
206 | + $extremeStatements = $statementList->getByPropertyId(new NumericPropertyId($extremePropertyId)); |
|
207 | 207 | /** @var Statement $extremeStatement */ |
208 | - foreach ( $extremeStatements as $extremeStatement ) { |
|
209 | - if ( $extremeStatement->getRank() !== Statement::RANK_DEPRECATED ) { |
|
208 | + foreach ($extremeStatements as $extremeStatement) { |
|
209 | + if ($extremeStatement->getRank() !== Statement::RANK_DEPRECATED) { |
|
210 | 210 | $snak = $extremeStatement->getMainSnak(); |
211 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
211 | + if (!$snak instanceof PropertyValueSnak) { |
|
212 | 212 | return null; |
213 | 213 | } else { |
214 | 214 | $comparison = $this->rangeCheckerHelper->getComparison( |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | ); |
218 | 218 | if ( |
219 | 219 | $extremeValue === null || |
220 | - ( $startOrEnd === 'start' && $comparison < 0 ) || |
|
221 | - ( $startOrEnd === 'end' && $comparison > 0 ) |
|
220 | + ($startOrEnd === 'start' && $comparison < 0) || |
|
221 | + ($startOrEnd === 'end' && $comparison > 0) |
|
222 | 222 | ) { |
223 | 223 | $extremeValue = $snak->getDataValue(); |
224 | 224 | } |
@@ -248,17 +248,16 @@ discard block |
||
248 | 248 | DataValue $maxStartValue |
249 | 249 | ) { |
250 | 250 | $messageKey = $earlierEntityId === $subjectId ? |
251 | - 'wbqc-violation-message-contemporary-subject-earlier' : |
|
252 | - 'wbqc-violation-message-contemporary-value-earlier'; |
|
253 | - return ( new ViolationMessage( $messageKey ) ) |
|
254 | - ->withEntityId( $subjectId, Role::SUBJECT ) |
|
255 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
256 | - ->withEntityId( $objectId, Role::OBJECT ) |
|
257 | - ->withDataValue( $minEndValue, Role::OBJECT ) |
|
258 | - ->withDataValue( $maxStartValue, Role::OBJECT ); |
|
251 | + 'wbqc-violation-message-contemporary-subject-earlier' : 'wbqc-violation-message-contemporary-value-earlier'; |
|
252 | + return (new ViolationMessage($messageKey)) |
|
253 | + ->withEntityId($subjectId, Role::SUBJECT) |
|
254 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
255 | + ->withEntityId($objectId, Role::OBJECT) |
|
256 | + ->withDataValue($minEndValue, Role::OBJECT) |
|
257 | + ->withDataValue($maxStartValue, Role::OBJECT); |
|
259 | 258 | } |
260 | 259 | |
261 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
260 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
262 | 261 | // no parameters |
263 | 262 | return []; |
264 | 263 | } |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
89 | 89 | * @return CheckResult |
90 | 90 | */ |
91 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
92 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
93 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
91 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
92 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
93 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -106,18 +106,18 @@ discard block |
||
106 | 106 | $constraintTypeItemId |
107 | 107 | ); |
108 | 108 | $relationIds = []; |
109 | - if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) { |
|
110 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
109 | + if ($relation === 'instance' || $relation === 'instanceOrSubclass') { |
|
110 | + $relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
111 | 111 | } |
112 | - if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) { |
|
113 | - $relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
112 | + if ($relation === 'subclass' || $relation === 'instanceOrSubclass') { |
|
113 | + $relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | $snak = $context->getSnak(); |
117 | 117 | |
118 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
118 | + if (!$snak instanceof PropertyValueSnak) { |
|
119 | 119 | // nothing to check |
120 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
120 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | $dataValue = $snak->getDataValue(); |
@@ -126,23 +126,23 @@ discard block |
||
126 | 126 | * error handling: |
127 | 127 | * type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid' |
128 | 128 | */ |
129 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
130 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
131 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
132 | - ->withDataValueType( 'wikibase-entityid' ); |
|
133 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
129 | + if (!$dataValue instanceof EntityIdValue) { |
|
130 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
131 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
132 | + ->withDataValueType('wikibase-entityid'); |
|
133 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | try { |
137 | - $item = $this->entityLookup->getEntity( $dataValue->getEntityId() ); |
|
138 | - } catch ( UnresolvedEntityRedirectException $e ) { |
|
137 | + $item = $this->entityLookup->getEntity($dataValue->getEntityId()); |
|
138 | + } catch (UnresolvedEntityRedirectException $e) { |
|
139 | 139 | // Edge case (double redirect): Pretend the entity doesn't exist |
140 | 140 | $item = null; |
141 | 141 | } |
142 | 142 | |
143 | - if ( !( $item instanceof StatementListProvidingEntity ) ) { |
|
144 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
145 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
143 | + if (!($item instanceof StatementListProvidingEntity)) { |
|
144 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
145 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $statements = $item->getStatements(); |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $classes |
154 | 154 | ); |
155 | 155 | |
156 | - if ( $result->getBool() ) { |
|
156 | + if ($result->getBool()) { |
|
157 | 157 | $message = null; |
158 | 158 | $status = CheckResult::STATUS_COMPLIANCE; |
159 | 159 | } else { |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | $status = CheckResult::STATUS_VIOLATION; |
168 | 168 | } |
169 | 169 | |
170 | - return ( new CheckResult( $context, $constraint, $status, $message ) ) |
|
171 | - ->withMetadata( $result->getMetadata() ); |
|
170 | + return (new CheckResult($context, $constraint, $status, $message)) |
|
171 | + ->withMetadata($result->getMetadata()); |
|
172 | 172 | } |
173 | 173 | |
174 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
174 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
175 | 175 | $constraintParameters = $constraint->getConstraintParameters(); |
176 | 176 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
177 | 177 | $exceptions = []; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | $constraintParameters, |
181 | 181 | $constraintTypeItemId |
182 | 182 | ); |
183 | - } catch ( ConstraintParameterException $e ) { |
|
183 | + } catch (ConstraintParameterException $e) { |
|
184 | 184 | $exceptions[] = $e; |
185 | 185 | } |
186 | 186 | try { |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $constraintParameters, |
189 | 189 | $constraintTypeItemId |
190 | 190 | ); |
191 | - } catch ( ConstraintParameterException $e ) { |
|
191 | + } catch (ConstraintParameterException $e) { |
|
192 | 192 | $exceptions[] = $e; |
193 | 193 | } |
194 | 194 | return $exceptions; |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
30 | 30 | * @param LoggerInterface|null $logger |
31 | 31 | */ |
32 | - public function __construct( ILoadBalancer $lb, $dbName, ?LoggerInterface $logger = null ) { |
|
32 | + public function __construct(ILoadBalancer $lb, $dbName, ?LoggerInterface $logger = null) { |
|
33 | 33 | $this->lb = $lb; |
34 | 34 | $this->dbName = $dbName; |
35 | 35 | $this->logger = $logger ?? new NullLogger(); |
@@ -40,22 +40,22 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return Constraint[] |
42 | 42 | */ |
43 | - public function queryConstraintsForProperty( NumericPropertyId $propertyId ) { |
|
44 | - $dbr = $this->lb->getConnection( ILoadBalancer::DB_REPLICA, [], $this->dbName ); |
|
43 | + public function queryConstraintsForProperty(NumericPropertyId $propertyId) { |
|
44 | + $dbr = $this->lb->getConnection(ILoadBalancer::DB_REPLICA, [], $this->dbName); |
|
45 | 45 | |
46 | 46 | $results = $dbr->newSelectQueryBuilder() |
47 | - ->select( [ |
|
47 | + ->select([ |
|
48 | 48 | 'constraint_type_qid', |
49 | 49 | 'constraint_parameters', |
50 | 50 | 'constraint_guid', |
51 | 51 | 'pid', |
52 | - ] ) |
|
53 | - ->from( 'wbqc_constraints' ) |
|
54 | - ->where( [ 'pid' => $propertyId->getNumericId() ] ) |
|
55 | - ->caller( __METHOD__ ) |
|
52 | + ]) |
|
53 | + ->from('wbqc_constraints') |
|
54 | + ->where(['pid' => $propertyId->getNumericId()]) |
|
55 | + ->caller(__METHOD__) |
|
56 | 56 | ->fetchResultSet(); |
57 | 57 | |
58 | - return $this->convertToConstraints( $results ); |
|
58 | + return $this->convertToConstraints($results); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -63,25 +63,25 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @return Constraint[] |
65 | 65 | */ |
66 | - private function convertToConstraints( IResultWrapper $results ) { |
|
66 | + private function convertToConstraints(IResultWrapper $results) { |
|
67 | 67 | $constraints = []; |
68 | - foreach ( $results as $result ) { |
|
68 | + foreach ($results as $result) { |
|
69 | 69 | $constraintTypeItemId = $result->constraint_type_qid; |
70 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
70 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
71 | 71 | |
72 | - if ( $constraintParameters === null ) { |
|
72 | + if ($constraintParameters === null) { |
|
73 | 73 | // T171295 |
74 | - $this->logger->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
74 | + $this->logger->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
75 | 75 | 'method' => __METHOD__, |
76 | 76 | 'constraintId' => $result->constraint_guid, |
77 | 77 | 'constraintParameters' => $result->constraint_parameters, |
78 | - ] ); |
|
79 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
78 | + ]); |
|
79 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $constraints[] = new Constraint( |
83 | 83 | $result->constraint_guid, |
84 | - NumericPropertyId::newFromNumber( $result->pid ), |
|
84 | + NumericPropertyId::newFromNumber($result->pid), |
|
85 | 85 | $constraintTypeItemId, |
86 | 86 | $constraintParameters |
87 | 87 | ); |
@@ -31,58 +31,58 @@ discard block |
||
31 | 31 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResultSerializer; |
32 | 32 | |
33 | 33 | return [ |
34 | - ConstraintsServices::EXPIRY_LOCK => static function ( MediaWikiServices $services ): ExpiryLock { |
|
35 | - return new ExpiryLock( $services->getObjectCacheFactory()->getInstance( CACHE_ANYTHING ) ); |
|
34 | + ConstraintsServices::EXPIRY_LOCK => static function(MediaWikiServices $services): ExpiryLock { |
|
35 | + return new ExpiryLock($services->getObjectCacheFactory()->getInstance(CACHE_ANYTHING)); |
|
36 | 36 | }, |
37 | 37 | |
38 | - ConstraintsServices::LOGGER => static function ( MediaWikiServices $services ): LoggerInterface { |
|
39 | - return LoggerFactory::getInstance( 'WikibaseQualityConstraints' ); |
|
38 | + ConstraintsServices::LOGGER => static function(MediaWikiServices $services): LoggerInterface { |
|
39 | + return LoggerFactory::getInstance('WikibaseQualityConstraints'); |
|
40 | 40 | }, |
41 | 41 | |
42 | - ConstraintsServices::LOGGING_HELPER => static function ( MediaWikiServices $services ): LoggingHelper { |
|
42 | + ConstraintsServices::LOGGING_HELPER => static function(MediaWikiServices $services): LoggingHelper { |
|
43 | 43 | return new LoggingHelper( |
44 | 44 | $services->getStatsdDataFactory(), |
45 | - ConstraintsServices::getLogger( $services ), |
|
45 | + ConstraintsServices::getLogger($services), |
|
46 | 46 | $services->getMainConfig() |
47 | 47 | ); |
48 | 48 | }, |
49 | 49 | |
50 | - ConstraintsServices::CONSTRAINT_STORE => static function ( MediaWikiServices $services ): ConstraintRepositoryStore { |
|
51 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
52 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
53 | - if ( $propertySource === null ) { |
|
54 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for properties not stored in a database.' ); |
|
50 | + ConstraintsServices::CONSTRAINT_STORE => static function(MediaWikiServices $services): ConstraintRepositoryStore { |
|
51 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
52 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
53 | + if ($propertySource === null) { |
|
54 | + throw new RuntimeException('Can\'t get a ConstraintStore for properties not stored in a database.'); |
|
55 | 55 | } |
56 | 56 | |
57 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
58 | - if ( $propertySource->getSourceName() !== $localEntitySourceName ) { |
|
59 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for a non local entity source.' ); |
|
57 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
58 | + if ($propertySource->getSourceName() !== $localEntitySourceName) { |
|
59 | + throw new RuntimeException('Can\'t get a ConstraintStore for a non local entity source.'); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $dbName = $propertySource->getDatabaseName(); |
63 | 63 | return new ConstraintRepositoryStore( |
64 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
64 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
65 | 65 | $dbName |
66 | 66 | ); |
67 | 67 | }, |
68 | 68 | |
69 | - ConstraintsServices::CONSTRAINT_LOOKUP => static function ( MediaWikiServices $services ): ConstraintLookup { |
|
70 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
71 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
72 | - if ( $propertySource === null ) { |
|
73 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for properties not stored in a database.' ); |
|
69 | + ConstraintsServices::CONSTRAINT_LOOKUP => static function(MediaWikiServices $services): ConstraintLookup { |
|
70 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
71 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
72 | + if ($propertySource === null) { |
|
73 | + throw new RuntimeException('Can\'t get a ConstraintStore for properties not stored in a database.'); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | $dbName = $propertySource->getDatabaseName(); |
77 | 77 | $rawLookup = new ConstraintRepositoryLookup( |
78 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
78 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
79 | 79 | $dbName, |
80 | - ConstraintsServices::getLogger( $services ) |
|
80 | + ConstraintsServices::getLogger($services) |
|
81 | 81 | ); |
82 | - return new CachingConstraintLookup( $rawLookup ); |
|
82 | + return new CachingConstraintLookup($rawLookup); |
|
83 | 83 | }, |
84 | 84 | |
85 | - ConstraintsServices::CHECK_RESULT_SERIALIZER => static function ( MediaWikiServices $services ): CheckResultSerializer { |
|
85 | + ConstraintsServices::CHECK_RESULT_SERIALIZER => static function(MediaWikiServices $services): CheckResultSerializer { |
|
86 | 86 | return new CheckResultSerializer( |
87 | 87 | new ConstraintSerializer( |
88 | 88 | false // constraint parameters are not exposed |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | ); |
94 | 94 | }, |
95 | 95 | |
96 | - ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function ( MediaWikiServices $services ): CheckResultDeserializer { |
|
97 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
98 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
96 | + ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function(MediaWikiServices $services): CheckResultDeserializer { |
|
97 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
98 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
99 | 99 | |
100 | 100 | return new CheckResultDeserializer( |
101 | 101 | new ConstraintDeserializer(), |
@@ -108,17 +108,17 @@ discard block |
||
108 | 108 | ); |
109 | 109 | }, |
110 | 110 | |
111 | - ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function ( |
|
111 | + ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function( |
|
112 | 112 | MediaWikiServices $services |
113 | 113 | ): ViolationMessageSerializer { |
114 | 114 | return new ViolationMessageSerializer(); |
115 | 115 | }, |
116 | 116 | |
117 | - ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function ( |
|
117 | + ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function( |
|
118 | 118 | MediaWikiServices $services |
119 | 119 | ): ViolationMessageDeserializer { |
120 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
121 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
120 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
121 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
122 | 122 | |
123 | 123 | return new ViolationMessageDeserializer( |
124 | 124 | $entityIdParser, |
@@ -126,40 +126,40 @@ discard block |
||
126 | 126 | ); |
127 | 127 | }, |
128 | 128 | |
129 | - ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function ( |
|
129 | + ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function( |
|
130 | 130 | MediaWikiServices $services |
131 | 131 | ): ConstraintParameterParser { |
132 | - $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory( $services ); |
|
133 | - $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
132 | + $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory($services); |
|
133 | + $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
134 | 134 | |
135 | 135 | return new ConstraintParameterParser( |
136 | 136 | $services->getMainConfig(), |
137 | 137 | $deserializerFactory, |
138 | - $entitySourceDefinitions->getDatabaseSourceForEntityType( 'item' )->getConceptBaseUri() |
|
138 | + $entitySourceDefinitions->getDatabaseSourceForEntityType('item')->getConceptBaseUri() |
|
139 | 139 | ); |
140 | 140 | }, |
141 | 141 | |
142 | - ConstraintsServices::CONNECTION_CHECKER_HELPER => static function ( MediaWikiServices $services ): ConnectionCheckerHelper { |
|
142 | + ConstraintsServices::CONNECTION_CHECKER_HELPER => static function(MediaWikiServices $services): ConnectionCheckerHelper { |
|
143 | 143 | return new ConnectionCheckerHelper(); |
144 | 144 | }, |
145 | 145 | |
146 | - ConstraintsServices::RANGE_CHECKER_HELPER => static function ( MediaWikiServices $services ): RangeCheckerHelper { |
|
146 | + ConstraintsServices::RANGE_CHECKER_HELPER => static function(MediaWikiServices $services): RangeCheckerHelper { |
|
147 | 147 | return new RangeCheckerHelper( |
148 | 148 | $services->getMainConfig(), |
149 | - WikibaseRepo::getUnitConverter( $services ) |
|
149 | + WikibaseRepo::getUnitConverter($services) |
|
150 | 150 | ); |
151 | 151 | }, |
152 | 152 | |
153 | - ConstraintsServices::SPARQL_HELPER => static function ( MediaWikiServices $services ): SparqlHelper { |
|
154 | - $endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
155 | - if ( $endpoint === '' ) { |
|
153 | + ConstraintsServices::SPARQL_HELPER => static function(MediaWikiServices $services): SparqlHelper { |
|
154 | + $endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint'); |
|
155 | + if ($endpoint === '') { |
|
156 | 156 | return new DummySparqlHelper(); |
157 | 157 | } |
158 | 158 | |
159 | - $rdfVocabulary = WikibaseRepo::getRdfVocabulary( $services ); |
|
160 | - $valueSnakRdfBuilderFactory = WikibaseRepo::getValueSnakRdfBuilderFactory( $services ); |
|
161 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
162 | - $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup( $services ); |
|
159 | + $rdfVocabulary = WikibaseRepo::getRdfVocabulary($services); |
|
160 | + $valueSnakRdfBuilderFactory = WikibaseRepo::getValueSnakRdfBuilderFactory($services); |
|
161 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
162 | + $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup($services); |
|
163 | 163 | |
164 | 164 | return new SparqlHelper( |
165 | 165 | $services->getMainConfig(), |
@@ -168,128 +168,128 @@ discard block |
||
168 | 168 | $entityIdParser, |
169 | 169 | $propertyDataTypeLookup, |
170 | 170 | $services->getMainWANObjectCache(), |
171 | - ConstraintsServices::getViolationMessageSerializer( $services ), |
|
172 | - ConstraintsServices::getViolationMessageDeserializer( $services ), |
|
171 | + ConstraintsServices::getViolationMessageSerializer($services), |
|
172 | + ConstraintsServices::getViolationMessageDeserializer($services), |
|
173 | 173 | $services->getStatsdDataFactory(), |
174 | - ConstraintsServices::getExpiryLock( $services ), |
|
175 | - ConstraintsServices::getLoggingHelper( $services ), |
|
176 | - WikiMap::getCurrentWikiId() . ' WikibaseQualityConstraints ' . $services->getHttpRequestFactory()->getUserAgent(), |
|
174 | + ConstraintsServices::getExpiryLock($services), |
|
175 | + ConstraintsServices::getLoggingHelper($services), |
|
176 | + WikiMap::getCurrentWikiId().' WikibaseQualityConstraints '.$services->getHttpRequestFactory()->getUserAgent(), |
|
177 | 177 | $services->getHttpRequestFactory() |
178 | 178 | ); |
179 | 179 | }, |
180 | 180 | |
181 | - ConstraintsServices::TYPE_CHECKER_HELPER => static function ( MediaWikiServices $services ): TypeCheckerHelper { |
|
181 | + ConstraintsServices::TYPE_CHECKER_HELPER => static function(MediaWikiServices $services): TypeCheckerHelper { |
|
182 | 182 | return new TypeCheckerHelper( |
183 | - WikibaseServices::getEntityLookup( $services ), |
|
183 | + WikibaseServices::getEntityLookup($services), |
|
184 | 184 | $services->getMainConfig(), |
185 | - ConstraintsServices::getSparqlHelper( $services ), |
|
186 | - $services->getStatsFactory()->withComponent( 'WikibaseQualityConstraints' ) |
|
185 | + ConstraintsServices::getSparqlHelper($services), |
|
186 | + $services->getStatsFactory()->withComponent('WikibaseQualityConstraints') |
|
187 | 187 | ); |
188 | 188 | }, |
189 | 189 | |
190 | - ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function ( |
|
190 | + ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function( |
|
191 | 191 | MediaWikiServices $services |
192 | 192 | ): DelegatingConstraintChecker { |
193 | - $statementGuidParser = WikibaseRepo::getStatementGuidParser( $services ); |
|
193 | + $statementGuidParser = WikibaseRepo::getStatementGuidParser($services); |
|
194 | 194 | |
195 | 195 | $config = $services->getMainConfig(); |
196 | 196 | $checkerMap = [ |
197 | - $config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
198 | - => ConstraintCheckerServices::getConflictsWithChecker( $services ), |
|
199 | - $config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
200 | - => ConstraintCheckerServices::getItemChecker( $services ), |
|
201 | - $config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
202 | - => ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ), |
|
203 | - $config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
204 | - => ConstraintCheckerServices::getSymmetricChecker( $services ), |
|
205 | - $config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
206 | - => ConstraintCheckerServices::getInverseChecker( $services ), |
|
207 | - $config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
208 | - => ConstraintCheckerServices::getQualifierChecker( $services ), |
|
209 | - $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
210 | - => ConstraintCheckerServices::getQualifiersChecker( $services ), |
|
211 | - $config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
212 | - => ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ), |
|
213 | - $config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
214 | - => ConstraintCheckerServices::getRangeChecker( $services ), |
|
215 | - $config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
216 | - => ConstraintCheckerServices::getDiffWithinRangeChecker( $services ), |
|
217 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
218 | - => ConstraintCheckerServices::getTypeChecker( $services ), |
|
219 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
220 | - => ConstraintCheckerServices::getValueTypeChecker( $services ), |
|
221 | - $config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
222 | - => ConstraintCheckerServices::getSingleValueChecker( $services ), |
|
223 | - $config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
224 | - => ConstraintCheckerServices::getMultiValueChecker( $services ), |
|
225 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
226 | - => ConstraintCheckerServices::getUniqueValueChecker( $services ), |
|
227 | - $config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
228 | - => ConstraintCheckerServices::getFormatChecker( $services ), |
|
229 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
230 | - => ConstraintCheckerServices::getCommonsLinkChecker( $services ), |
|
231 | - $config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
232 | - => ConstraintCheckerServices::getOneOfChecker( $services ), |
|
233 | - $config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
234 | - => ConstraintCheckerServices::getValueOnlyChecker( $services ), |
|
235 | - $config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
236 | - => ConstraintCheckerServices::getReferenceChecker( $services ), |
|
237 | - $config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
238 | - => ConstraintCheckerServices::getNoBoundsChecker( $services ), |
|
239 | - $config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
240 | - => ConstraintCheckerServices::getAllowedUnitsChecker( $services ), |
|
241 | - $config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
|
242 | - => ConstraintCheckerServices::getSingleBestValueChecker( $services ), |
|
243 | - $config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
|
244 | - => ConstraintCheckerServices::getEntityTypeChecker( $services ), |
|
245 | - $config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
|
246 | - => ConstraintCheckerServices::getNoneOfChecker( $services ), |
|
247 | - $config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
|
248 | - => ConstraintCheckerServices::getIntegerChecker( $services ), |
|
249 | - $config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
|
250 | - => ConstraintCheckerServices::getCitationNeededChecker( $services ), |
|
251 | - $config->get( 'WBQualityConstraintsPropertyScopeConstraintId' ) |
|
252 | - => ConstraintCheckerServices::getPropertyScopeChecker( $services ), |
|
253 | - $config->get( 'WBQualityConstraintsContemporaryConstraintId' ) |
|
254 | - => ConstraintCheckerServices::getContemporaryChecker( $services ), |
|
255 | - $config->get( 'WBQualityConstraintsLexemeLanguageConstraintId' ) |
|
256 | - => ConstraintCheckerServices::getLexemeLanguageChecker( $services ), |
|
257 | - $config->get( 'WBQualityConstraintsLabelInLanguageConstraintId' ) |
|
258 | - => ConstraintCheckerServices::getLabelInLanguageChecker( $services ), |
|
197 | + $config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
198 | + => ConstraintCheckerServices::getConflictsWithChecker($services), |
|
199 | + $config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
200 | + => ConstraintCheckerServices::getItemChecker($services), |
|
201 | + $config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
202 | + => ConstraintCheckerServices::getTargetRequiredClaimChecker($services), |
|
203 | + $config->get('WBQualityConstraintsSymmetricConstraintId') |
|
204 | + => ConstraintCheckerServices::getSymmetricChecker($services), |
|
205 | + $config->get('WBQualityConstraintsInverseConstraintId') |
|
206 | + => ConstraintCheckerServices::getInverseChecker($services), |
|
207 | + $config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
208 | + => ConstraintCheckerServices::getQualifierChecker($services), |
|
209 | + $config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
210 | + => ConstraintCheckerServices::getQualifiersChecker($services), |
|
211 | + $config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
212 | + => ConstraintCheckerServices::getMandatoryQualifiersChecker($services), |
|
213 | + $config->get('WBQualityConstraintsRangeConstraintId') |
|
214 | + => ConstraintCheckerServices::getRangeChecker($services), |
|
215 | + $config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
216 | + => ConstraintCheckerServices::getDiffWithinRangeChecker($services), |
|
217 | + $config->get('WBQualityConstraintsTypeConstraintId') |
|
218 | + => ConstraintCheckerServices::getTypeChecker($services), |
|
219 | + $config->get('WBQualityConstraintsValueTypeConstraintId') |
|
220 | + => ConstraintCheckerServices::getValueTypeChecker($services), |
|
221 | + $config->get('WBQualityConstraintsSingleValueConstraintId') |
|
222 | + => ConstraintCheckerServices::getSingleValueChecker($services), |
|
223 | + $config->get('WBQualityConstraintsMultiValueConstraintId') |
|
224 | + => ConstraintCheckerServices::getMultiValueChecker($services), |
|
225 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
226 | + => ConstraintCheckerServices::getUniqueValueChecker($services), |
|
227 | + $config->get('WBQualityConstraintsFormatConstraintId') |
|
228 | + => ConstraintCheckerServices::getFormatChecker($services), |
|
229 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
230 | + => ConstraintCheckerServices::getCommonsLinkChecker($services), |
|
231 | + $config->get('WBQualityConstraintsOneOfConstraintId') |
|
232 | + => ConstraintCheckerServices::getOneOfChecker($services), |
|
233 | + $config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
234 | + => ConstraintCheckerServices::getValueOnlyChecker($services), |
|
235 | + $config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
236 | + => ConstraintCheckerServices::getReferenceChecker($services), |
|
237 | + $config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
238 | + => ConstraintCheckerServices::getNoBoundsChecker($services), |
|
239 | + $config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
240 | + => ConstraintCheckerServices::getAllowedUnitsChecker($services), |
|
241 | + $config->get('WBQualityConstraintsSingleBestValueConstraintId') |
|
242 | + => ConstraintCheckerServices::getSingleBestValueChecker($services), |
|
243 | + $config->get('WBQualityConstraintsAllowedEntityTypesConstraintId') |
|
244 | + => ConstraintCheckerServices::getEntityTypeChecker($services), |
|
245 | + $config->get('WBQualityConstraintsNoneOfConstraintId') |
|
246 | + => ConstraintCheckerServices::getNoneOfChecker($services), |
|
247 | + $config->get('WBQualityConstraintsIntegerConstraintId') |
|
248 | + => ConstraintCheckerServices::getIntegerChecker($services), |
|
249 | + $config->get('WBQualityConstraintsCitationNeededConstraintId') |
|
250 | + => ConstraintCheckerServices::getCitationNeededChecker($services), |
|
251 | + $config->get('WBQualityConstraintsPropertyScopeConstraintId') |
|
252 | + => ConstraintCheckerServices::getPropertyScopeChecker($services), |
|
253 | + $config->get('WBQualityConstraintsContemporaryConstraintId') |
|
254 | + => ConstraintCheckerServices::getContemporaryChecker($services), |
|
255 | + $config->get('WBQualityConstraintsLexemeLanguageConstraintId') |
|
256 | + => ConstraintCheckerServices::getLexemeLanguageChecker($services), |
|
257 | + $config->get('WBQualityConstraintsLabelInLanguageConstraintId') |
|
258 | + => ConstraintCheckerServices::getLabelInLanguageChecker($services), |
|
259 | 259 | ]; |
260 | 260 | |
261 | 261 | return new DelegatingConstraintChecker( |
262 | - WikibaseServices::getEntityLookup( $services ), |
|
262 | + WikibaseServices::getEntityLookup($services), |
|
263 | 263 | $checkerMap, |
264 | - ConstraintsServices::getConstraintLookup( $services ), |
|
265 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
264 | + ConstraintsServices::getConstraintLookup($services), |
|
265 | + ConstraintsServices::getConstraintParameterParser($services), |
|
266 | 266 | $statementGuidParser, |
267 | - ConstraintsServices::getLoggingHelper( $services ), |
|
268 | - $config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
269 | - $config->get( 'WBQualityConstraintsCheckReferences' ), |
|
270 | - $config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
267 | + ConstraintsServices::getLoggingHelper($services), |
|
268 | + $config->get('WBQualityConstraintsCheckQualifiers'), |
|
269 | + $config->get('WBQualityConstraintsCheckReferences'), |
|
270 | + $config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
271 | 271 | ); |
272 | 272 | }, |
273 | 273 | |
274 | - ConstraintsServices::RESULTS_SOURCE => static function ( MediaWikiServices $services ): ResultsSource { |
|
274 | + ConstraintsServices::RESULTS_SOURCE => static function(MediaWikiServices $services): ResultsSource { |
|
275 | 275 | $config = $services->getMainConfig(); |
276 | 276 | $resultsSource = new CheckingResultsSource( |
277 | - ConstraintsServices::getDelegatingConstraintChecker( $services ) |
|
277 | + ConstraintsServices::getDelegatingConstraintChecker($services) |
|
278 | 278 | ); |
279 | 279 | |
280 | 280 | $cacheCheckConstraintsResults = false; |
281 | 281 | |
282 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
282 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
283 | 283 | $cacheCheckConstraintsResults = true; |
284 | 284 | // check that we can use getLocalRepoWikiPageMetaDataAccessor() |
285 | 285 | // TODO we should always be able to cache constraint check results (T244726) |
286 | - $entitySources = WikibaseRepo::getEntitySourceDefinitions( $services )->getSources(); |
|
287 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
286 | + $entitySources = WikibaseRepo::getEntitySourceDefinitions($services)->getSources(); |
|
287 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
288 | 288 | |
289 | - foreach ( $entitySources as $entitySource ) { |
|
290 | - if ( $entitySource->getSourceName() !== $localEntitySourceName ) { |
|
291 | - ConstraintsServices::getLogger( $services )->warning( |
|
292 | - 'Cannot cache constraint check results for non-local source: ' . |
|
289 | + foreach ($entitySources as $entitySource) { |
|
290 | + if ($entitySource->getSourceName() !== $localEntitySourceName) { |
|
291 | + ConstraintsServices::getLogger($services)->warning( |
|
292 | + 'Cannot cache constraint check results for non-local source: '. |
|
293 | 293 | $entitySource->getSourceName() |
294 | 294 | ); |
295 | 295 | $cacheCheckConstraintsResults = false; |
@@ -298,42 +298,42 @@ discard block |
||
298 | 298 | } |
299 | 299 | } |
300 | 300 | |
301 | - if ( $cacheCheckConstraintsResults ) { |
|
301 | + if ($cacheCheckConstraintsResults) { |
|
302 | 302 | $possiblyStaleConstraintTypes = [ |
303 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
304 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
305 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
306 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
303 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
304 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
305 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
306 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
307 | 307 | ]; |
308 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
308 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
309 | 309 | $wikiPageEntityMetaDataAccessor = WikibaseRepo::getLocalRepoWikiPageMetaDataAccessor( |
310 | 310 | $services ); |
311 | 311 | |
312 | 312 | $resultsSource = new CachingResultsSource( |
313 | 313 | $resultsSource, |
314 | 314 | ResultsCache::getDefaultInstance(), |
315 | - ConstraintsServices::getCheckResultSerializer( $services ), |
|
316 | - ConstraintsServices::getCheckResultDeserializer( $services ), |
|
315 | + ConstraintsServices::getCheckResultSerializer($services), |
|
316 | + ConstraintsServices::getCheckResultDeserializer($services), |
|
317 | 317 | $wikiPageEntityMetaDataAccessor, |
318 | 318 | $entityIdParser, |
319 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
319 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
320 | 320 | $possiblyStaleConstraintTypes, |
321 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
322 | - ConstraintsServices::getLoggingHelper( $services ) |
|
321 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
322 | + ConstraintsServices::getLoggingHelper($services) |
|
323 | 323 | ); |
324 | 324 | } |
325 | 325 | |
326 | 326 | return $resultsSource; |
327 | 327 | }, |
328 | 328 | |
329 | - ConstraintsServices::VIOLATION_MESSAGE_RENDERER_FACTORY => static function ( |
|
329 | + ConstraintsServices::VIOLATION_MESSAGE_RENDERER_FACTORY => static function( |
|
330 | 330 | MediaWikiServices $services |
331 | 331 | ): ViolationMessageRendererFactory { |
332 | 332 | return new ViolationMessageRendererFactory( |
333 | 333 | $services->getMainConfig(), |
334 | 334 | $services->getLanguageNameUtils(), |
335 | - WikibaseRepo::getEntityIdHtmlLinkFormatterFactory( $services ), |
|
336 | - WikibaseRepo::getValueFormatterFactory( $services ) |
|
335 | + WikibaseRepo::getEntityIdHtmlLinkFormatterFactory($services), |
|
336 | + WikibaseRepo::getValueFormatterFactory($services) |
|
337 | 337 | ); |
338 | 338 | }, |
339 | 339 | ]; |
@@ -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; |
6 | 6 | |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | public const ENTITY_LOOKUP_WITHOUT_CACHE = 'WBQC_EntityLookupWithoutCache'; |
27 | 27 | |
28 | 28 | /** @return mixed */ |
29 | - private static function getService( ?MediaWikiServices $services, string $name ) { |
|
29 | + private static function getService(?MediaWikiServices $services, string $name) { |
|
30 | 30 | $services ??= MediaWikiServices::getInstance(); |
31 | - return $services->getService( $name ); |
|
31 | + return $services->getService($name); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * this lookup ignores exceptions (such as unresolved redirects, T93273), |
39 | 39 | * as it is more convenient to treat them all as missing entities in WBQC. |
40 | 40 | */ |
41 | - public static function getEntityLookup( ?MediaWikiServices $services = null ): EntityLookup { |
|
42 | - return self::getService( $services, self::ENTITY_LOOKUP ); |
|
41 | + public static function getEntityLookup(?MediaWikiServices $services = null): EntityLookup { |
|
42 | + return self::getService($services, self::ENTITY_LOOKUP); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | * were exceeding the request memory limit when they were all added to the cache (T227450). |
50 | 50 | * Also, like {@link self::getEntityLookup()}, this lookup ignores exceptions. |
51 | 51 | */ |
52 | - public static function getEntityLookupWithoutCache( ?MediaWikiServices $services = null ): EntityLookup { |
|
53 | - return self::getService( $services, self::ENTITY_LOOKUP_WITHOUT_CACHE ); |
|
52 | + public static function getEntityLookupWithoutCache(?MediaWikiServices $services = null): EntityLookup { |
|
53 | + return self::getService($services, self::ENTITY_LOOKUP_WITHOUT_CACHE); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | } |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | BeforePageDisplayHook |
27 | 27 | { |
28 | 28 | |
29 | - public static function onWikibaseChange( Change $change ) { |
|
30 | - if ( !( $change instanceof EntityChange ) ) { |
|
29 | + public static function onWikibaseChange(Change $change) { |
|
30 | + if (!($change instanceof EntityChange)) { |
|
31 | 31 | return; |
32 | 32 | } |
33 | 33 | /** @var EntityChange $change */ |
@@ -38,48 +38,48 @@ discard block |
||
38 | 38 | |
39 | 39 | // If jobs are enabled and the results would be stored in some way run a job. |
40 | 40 | if ( |
41 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
42 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
41 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
42 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
43 | 43 | self::isSelectedForJobRunBasedOnPercentage() |
44 | 44 | ) { |
45 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
45 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
46 | 46 | $jobQueueGroup->lazyPush( |
47 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
47 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
48 | 48 | ); |
49 | 49 | } |
50 | 50 | |
51 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
52 | - self::isConstraintStatementsChange( $config, $change ) |
|
51 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
52 | + self::isConstraintStatementsChange($config, $change) |
|
53 | 53 | ) { |
54 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
54 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
55 | 55 | $metadata = $change->getMetadata(); |
56 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
56 | + if (array_key_exists('rev_id', $metadata)) { |
|
57 | 57 | $params['revisionId'] = $metadata['rev_id']; |
58 | 58 | } |
59 | 59 | $jobQueueGroup->push( |
60 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
60 | + new JobSpecification('constraintsTableUpdate', $params) |
|
61 | 61 | ); |
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | 65 | private static function isSelectedForJobRunBasedOnPercentage(): bool { |
66 | 66 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
67 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
67 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
68 | 68 | |
69 | - return mt_rand( 1, 100 ) <= $percentage; |
|
69 | + return mt_rand(1, 100) <= $percentage; |
|
70 | 70 | } |
71 | 71 | |
72 | - public static function isConstraintStatementsChange( Config $config, Change $change ): bool { |
|
73 | - if ( !( $change instanceof EntityChange ) || |
|
72 | + public static function isConstraintStatementsChange(Config $config, Change $change): bool { |
|
73 | + if (!($change instanceof EntityChange) || |
|
74 | 74 | $change->getAction() !== EntityChange::UPDATE || |
75 | - !( $change->getEntityId() instanceof NumericPropertyId ) |
|
75 | + !($change->getEntityId() instanceof NumericPropertyId) |
|
76 | 76 | ) { |
77 | 77 | return false; |
78 | 78 | } |
79 | 79 | |
80 | 80 | $info = $change->getInfo(); |
81 | 81 | |
82 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
82 | + if (!array_key_exists('compactDiff', $info)) { |
|
83 | 83 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
84 | 84 | // so we only know that the change *might* affect the constraint statements |
85 | 85 | return true; |
@@ -88,52 +88,52 @@ discard block |
||
88 | 88 | /** @var EntityDiffChangedAspects $aspects */ |
89 | 89 | $aspects = $info['compactDiff']; |
90 | 90 | |
91 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
92 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
91 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
92 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** @inheritDoc */ |
96 | - public function onArticlePurge( $wikiPage ) { |
|
96 | + public function onArticlePurge($wikiPage) { |
|
97 | 97 | $entityContentFactory = WikibaseRepo::getEntityContentFactory(); |
98 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
98 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
99 | 99 | $entityIdLookup = WikibaseRepo::getEntityIdLookup(); |
100 | - $entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
101 | - if ( $entityId !== null ) { |
|
100 | + $entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle()); |
|
101 | + if ($entityId !== null) { |
|
102 | 102 | $resultsCache = ResultsCache::getDefaultInstance(); |
103 | - $resultsCache->delete( $entityId ); |
|
103 | + $resultsCache->delete($entityId); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
108 | 108 | /** @inheritDoc */ |
109 | - public function onBeforePageDisplay( $out, $skin ): void { |
|
109 | + public function onBeforePageDisplay($out, $skin): void { |
|
110 | 110 | $lookup = WikibaseRepo::getEntityNamespaceLookup(); |
111 | 111 | $title = $out->getTitle(); |
112 | - if ( $title === null ) { |
|
112 | + if ($title === null) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | 115 | |
116 | - if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) { |
|
116 | + if (!$lookup->isNamespaceWithEntities($title->getNamespace())) { |
|
117 | 117 | return; |
118 | 118 | } |
119 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
119 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | 123 | $services = MediaWikiServices::getInstance(); |
124 | 124 | $config = $services->getMainConfig(); |
125 | 125 | |
126 | - $isMobileView = ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) && |
|
127 | - $services->getService( 'MobileFrontend.Context' )->shouldDisplayMobileView(); |
|
128 | - if ( $isMobileView ) { |
|
126 | + $isMobileView = ExtensionRegistry::getInstance()->isLoaded('MobileFrontend') && |
|
127 | + $services->getService('MobileFrontend.Context')->shouldDisplayMobileView(); |
|
128 | + if ($isMobileView) { |
|
129 | 129 | return; |
130 | 130 | } |
131 | 131 | |
132 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
132 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
133 | 133 | |
134 | - if ( $config->get( 'WBQualityConstraintsShowConstraintViolationToNonLoggedInUsers' ) |
|
135 | - || $out->getUser()->isRegistered() ) { |
|
136 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
134 | + if ($config->get('WBQualityConstraintsShowConstraintViolationToNonLoggedInUsers') |
|
135 | + || $out->getUser()->isRegistered()) { |
|
136 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 |