@@ -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\Api; |
6 | 6 | |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | return new CheckResultsRenderer( |
42 | 42 | $this->entityTitleLookup, |
43 | 43 | $this->entityIdLabelFormatterFactory |
44 | - ->getEntityIdFormatter( $userLanguage ), |
|
44 | + ->getEntityIdFormatter($userLanguage), |
|
45 | 45 | $this->violationMessageRendererFactory |
46 | - ->getViolationMessageRenderer( $userLanguage, $messageLocalizer ) |
|
46 | + ->getViolationMessageRenderer($userLanguage, $messageLocalizer) |
|
47 | 47 | ); |
48 | 48 | } |
49 | 49 |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | CheckResultsRendererFactory $checkResultsRendererFactory, |
120 | 120 | IBufferingStatsdDataFactory $dataFactory |
121 | 121 | ) { |
122 | - parent::__construct( $main, $name ); |
|
122 | + parent::__construct($main, $name); |
|
123 | 123 | $this->entityIdParser = $entityIdParser; |
124 | 124 | $this->statementGuidValidator = $statementGuidValidator; |
125 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
126 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
125 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
126 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
127 | 127 | $this->resultsSource = $resultsSource; |
128 | 128 | $this->checkResultsRendererFactory = $checkResultsRendererFactory; |
129 | 129 | $this->dataFactory = $dataFactory; |
@@ -139,14 +139,14 @@ discard block |
||
139 | 139 | |
140 | 140 | $params = $this->extractRequestParams(); |
141 | 141 | |
142 | - $this->validateParameters( $params ); |
|
143 | - $entityIds = $this->parseEntityIds( $params ); |
|
144 | - $claimIds = $this->parseClaimIds( $params ); |
|
142 | + $this->validateParameters($params); |
|
143 | + $entityIds = $this->parseEntityIds($params); |
|
144 | + $claimIds = $this->parseClaimIds($params); |
|
145 | 145 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
146 | 146 | $statuses = $params[self::PARAM_STATUS]; |
147 | 147 | |
148 | 148 | $checkResultsRenderer = $this->checkResultsRendererFactory |
149 | - ->getCheckResultsRenderer( $this->getLanguage(), $this ); |
|
149 | + ->getCheckResultsRenderer($this->getLanguage(), $this); |
|
150 | 150 | |
151 | 151 | $this->getResult()->addValue( |
152 | 152 | null, |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | ) |
161 | 161 | )->getArray() |
162 | 162 | ); |
163 | - $this->resultBuilder->markSuccess( 1 ); |
|
163 | + $this->resultBuilder->markSuccess(1); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -168,24 +168,24 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return EntityId[] |
170 | 170 | */ |
171 | - private function parseEntityIds( array $params ) { |
|
171 | + private function parseEntityIds(array $params) { |
|
172 | 172 | $ids = $params[self::PARAM_ID]; |
173 | 173 | |
174 | - if ( $ids === null ) { |
|
174 | + if ($ids === null) { |
|
175 | 175 | return []; |
176 | - } elseif ( $ids === [] ) { |
|
176 | + } elseif ($ids === []) { |
|
177 | 177 | $this->errorReporter->dieError( |
178 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
178 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
179 | 179 | } |
180 | 180 | |
181 | - return array_map( function ( $id ) { |
|
181 | + return array_map(function($id) { |
|
182 | 182 | try { |
183 | - return $this->entityIdParser->parse( $id ); |
|
184 | - } catch ( EntityIdParsingException $e ) { |
|
183 | + return $this->entityIdParser->parse($id); |
|
184 | + } catch (EntityIdParsingException $e) { |
|
185 | 185 | $this->errorReporter->dieError( |
186 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
186 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
187 | 187 | } |
188 | - }, $ids ); |
|
188 | + }, $ids); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -193,35 +193,35 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @return string[] |
195 | 195 | */ |
196 | - private function parseClaimIds( array $params ) { |
|
196 | + private function parseClaimIds(array $params) { |
|
197 | 197 | $ids = $params[self::PARAM_CLAIM_ID]; |
198 | 198 | |
199 | - if ( $ids === null ) { |
|
199 | + if ($ids === null) { |
|
200 | 200 | return []; |
201 | - } elseif ( $ids === [] ) { |
|
201 | + } elseif ($ids === []) { |
|
202 | 202 | $this->errorReporter->dieError( |
203 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
203 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
204 | 204 | } |
205 | 205 | |
206 | - foreach ( $ids as $id ) { |
|
207 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
206 | + foreach ($ids as $id) { |
|
207 | + if (!$this->statementGuidValidator->validate($id)) { |
|
208 | 208 | $this->errorReporter->dieError( |
209 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
209 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | |
213 | 213 | return $ids; |
214 | 214 | } |
215 | 215 | |
216 | - private function validateParameters( array $params ) { |
|
217 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
218 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
216 | + private function validateParameters(array $params) { |
|
217 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
218 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
219 | 219 | ) { |
220 | 220 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
221 | 221 | $this->errorReporter->dieError( |
222 | 222 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
223 | 223 | } |
224 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
224 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
225 | 225 | $paramId = self::PARAM_ID; |
226 | 226 | $paramClaimId = self::PARAM_CLAIM_ID; |
227 | 227 | $this->errorReporter->dieError( |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | ], |
263 | 263 | ParamValidator::PARAM_ISMULTI => true, |
264 | 264 | ParamValidator::PARAM_ALL => true, |
265 | - ParamValidator::PARAM_DEFAULT => implode( '|', CachingResultsSource::CACHED_STATUSES ), |
|
265 | + ParamValidator::PARAM_DEFAULT => implode('|', CachingResultsSource::CACHED_STATUSES), |
|
266 | 266 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
267 | 267 | ], |
268 | 268 | ]; |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | StatementGuidParser $statementGuidParser, |
106 | 106 | IBufferingStatsdDataFactory $dataFactory |
107 | 107 | ) { |
108 | - parent::__construct( $main, $name ); |
|
108 | + parent::__construct($main, $name); |
|
109 | 109 | |
110 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
110 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
111 | 111 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
112 | 112 | $this->violationMessageRendererFactory = $violationMessageRendererFactory; |
113 | 113 | $this->statementGuidParser = $statementGuidParser; |
@@ -122,39 +122,39 @@ discard block |
||
122 | 122 | $params = $this->extractRequestParams(); |
123 | 123 | $result = $this->getResult(); |
124 | 124 | |
125 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
126 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
125 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
126 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
127 | 127 | |
128 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
129 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
128 | + $this->checkPropertyIds($propertyIds, $result); |
|
129 | + $this->checkConstraintIds($constraintIds, $result); |
|
130 | 130 | |
131 | - $result->addValue( null, 'success', 1 ); |
|
131 | + $result->addValue(null, 'success', 1); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | 135 | * @param array|null $propertyIdSerializations |
136 | 136 | * @return NumericPropertyId[] |
137 | 137 | */ |
138 | - private function parsePropertyIds( $propertyIdSerializations ) { |
|
139 | - if ( $propertyIdSerializations === null ) { |
|
138 | + private function parsePropertyIds($propertyIdSerializations) { |
|
139 | + if ($propertyIdSerializations === null) { |
|
140 | 140 | return []; |
141 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
141 | + } elseif (empty($propertyIdSerializations)) { |
|
142 | 142 | $this->apiErrorReporter->dieError( |
143 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
143 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
144 | 144 | 'no-data' |
145 | 145 | ); |
146 | 146 | } |
147 | 147 | |
148 | 148 | return array_map( |
149 | - function ( $propertyIdSerialization ) { |
|
149 | + function($propertyIdSerialization) { |
|
150 | 150 | try { |
151 | - return new NumericPropertyId( $propertyIdSerialization ); |
|
152 | - } catch ( InvalidArgumentException $e ) { |
|
151 | + return new NumericPropertyId($propertyIdSerialization); |
|
152 | + } catch (InvalidArgumentException $e) { |
|
153 | 153 | $this->apiErrorReporter->dieError( |
154 | 154 | "Invalid id: $propertyIdSerialization", |
155 | 155 | 'invalid-property-id', |
156 | 156 | 0, // default argument |
157 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
157 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
158 | 158 | ); |
159 | 159 | } |
160 | 160 | }, |
@@ -166,35 +166,35 @@ discard block |
||
166 | 166 | * @param array|null $constraintIds |
167 | 167 | * @return string[] |
168 | 168 | */ |
169 | - private function parseConstraintIds( $constraintIds ) { |
|
170 | - if ( $constraintIds === null ) { |
|
169 | + private function parseConstraintIds($constraintIds) { |
|
170 | + if ($constraintIds === null) { |
|
171 | 171 | return []; |
172 | - } elseif ( empty( $constraintIds ) ) { |
|
172 | + } elseif (empty($constraintIds)) { |
|
173 | 173 | $this->apiErrorReporter->dieError( |
174 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
174 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
175 | 175 | 'no-data' |
176 | 176 | ); |
177 | 177 | } |
178 | 178 | |
179 | 179 | return array_map( |
180 | - function ( $constraintId ) { |
|
180 | + function($constraintId) { |
|
181 | 181 | try { |
182 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
183 | - if ( !$propertyId instanceof NumericPropertyId ) { |
|
182 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
183 | + if (!$propertyId instanceof NumericPropertyId) { |
|
184 | 184 | $this->apiErrorReporter->dieError( |
185 | 185 | "Invalid property ID: {$propertyId->getSerialization()}", |
186 | 186 | 'invalid-property-id', |
187 | 187 | 0, // default argument |
188 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
188 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
189 | 189 | ); |
190 | 190 | } |
191 | 191 | return $constraintId; |
192 | - } catch ( StatementGuidParsingException $e ) { |
|
192 | + } catch (StatementGuidParsingException $e) { |
|
193 | 193 | $this->apiErrorReporter->dieError( |
194 | 194 | "Invalid statement GUID: $constraintId", |
195 | 195 | 'invalid-guid', |
196 | 196 | 0, // default argument |
197 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
197 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
198 | 198 | ); |
199 | 199 | } |
200 | 200 | }, |
@@ -206,12 +206,12 @@ discard block |
||
206 | 206 | * @param NumericPropertyId[] $propertyIds |
207 | 207 | * @param ApiResult $result |
208 | 208 | */ |
209 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ) { |
|
210 | - foreach ( $propertyIds as $propertyId ) { |
|
211 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
209 | + private function checkPropertyIds(array $propertyIds, ApiResult $result) { |
|
210 | + foreach ($propertyIds as $propertyId) { |
|
211 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
212 | 212 | $allConstraintExceptions = $this->delegatingConstraintChecker |
213 | - ->checkConstraintParametersOnPropertyId( $propertyId ); |
|
214 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
213 | + ->checkConstraintParametersOnPropertyId($propertyId); |
|
214 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
215 | 215 | $this->addConstraintParameterExceptionsToResult( |
216 | 216 | $constraintId, |
217 | 217 | $constraintParameterExceptions, |
@@ -225,15 +225,15 @@ discard block |
||
225 | 225 | * @param string[] $constraintIds |
226 | 226 | * @param ApiResult $result |
227 | 227 | */ |
228 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ) { |
|
229 | - foreach ( $constraintIds as $constraintId ) { |
|
230 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
228 | + private function checkConstraintIds(array $constraintIds, ApiResult $result) { |
|
229 | + foreach ($constraintIds as $constraintId) { |
|
230 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
231 | 231 | // already checked as part of checkPropertyIds() |
232 | 232 | continue; |
233 | 233 | } |
234 | 234 | $constraintParameterExceptions = $this->delegatingConstraintChecker |
235 | - ->checkConstraintParametersOnConstraintId( $constraintId ); |
|
236 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
235 | + ->checkConstraintParametersOnConstraintId($constraintId); |
|
236 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
@@ -241,18 +241,18 @@ discard block |
||
241 | 241 | * @param NumericPropertyId $propertyId |
242 | 242 | * @return string[] |
243 | 243 | */ |
244 | - private function getResultPathForPropertyId( NumericPropertyId $propertyId ) { |
|
245 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
244 | + private function getResultPathForPropertyId(NumericPropertyId $propertyId) { |
|
245 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
249 | 249 | * @param string $constraintId |
250 | 250 | * @return string[] |
251 | 251 | */ |
252 | - private function getResultPathForConstraintId( $constraintId ) { |
|
253 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
252 | + private function getResultPathForConstraintId($constraintId) { |
|
253 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
254 | 254 | '@phan-var NumericPropertyId $propertyId'; |
255 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
255 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | $constraintParameterExceptions, |
268 | 268 | ApiResult $result |
269 | 269 | ) { |
270 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
271 | - if ( $constraintParameterExceptions === null ) { |
|
270 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
271 | + if ($constraintParameterExceptions === null) { |
|
272 | 272 | $result->addValue( |
273 | 273 | $path, |
274 | 274 | self::KEY_STATUS, |
@@ -278,13 +278,13 @@ discard block |
||
278 | 278 | $result->addValue( |
279 | 279 | $path, |
280 | 280 | self::KEY_STATUS, |
281 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
281 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
282 | 282 | ); |
283 | 283 | |
284 | 284 | $violationMessageRenderer = $this->violationMessageRendererFactory |
285 | - ->getViolationMessageRenderer( $this->getLanguage(), $this ); |
|
285 | + ->getViolationMessageRenderer($this->getLanguage(), $this); |
|
286 | 286 | $problems = []; |
287 | - foreach ( $constraintParameterExceptions as $constraintParameterException ) { |
|
287 | + foreach ($constraintParameterExceptions as $constraintParameterException) { |
|
288 | 288 | $problems[] = [ |
289 | 289 | self::KEY_MESSAGE_HTML => $violationMessageRenderer->render( |
290 | 290 | $constraintParameterException->getViolationMessage() ), |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | return [ |
324 | 324 | 'action=wbcheckconstraintparameters&propertyid=P247' |
325 | 325 | => 'apihelp-wbcheckconstraintparameters-example-propertyid-1', |
326 | - 'action=wbcheckconstraintparameters&' . |
|
327 | - 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' . |
|
326 | + 'action=wbcheckconstraintparameters&'. |
|
327 | + 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'. |
|
328 | 328 | 'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f' |
329 | 329 | => 'apihelp-wbcheckconstraintparameters-example-constraintid-2', |
330 | 330 | ]; |
@@ -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 | } |
@@ -30,53 +30,53 @@ discard block |
||
30 | 30 | use WikiMap; |
31 | 31 | |
32 | 32 | return [ |
33 | - ConstraintsServices::EXPIRY_LOCK => static function ( MediaWikiServices $services ) { |
|
34 | - return new ExpiryLock( ObjectCache::getInstance( CACHE_ANYTHING ) ); |
|
33 | + ConstraintsServices::EXPIRY_LOCK => static function(MediaWikiServices $services) { |
|
34 | + return new ExpiryLock(ObjectCache::getInstance(CACHE_ANYTHING)); |
|
35 | 35 | }, |
36 | 36 | |
37 | - ConstraintsServices::LOGGING_HELPER => static function ( MediaWikiServices $services ) { |
|
37 | + ConstraintsServices::LOGGING_HELPER => static function(MediaWikiServices $services) { |
|
38 | 38 | return new LoggingHelper( |
39 | 39 | $services->getStatsdDataFactory(), |
40 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
40 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
41 | 41 | $services->getMainConfig() |
42 | 42 | ); |
43 | 43 | }, |
44 | 44 | |
45 | - ConstraintsServices::CONSTRAINT_STORE => static function ( MediaWikiServices $services ) { |
|
46 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
47 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
48 | - if ( $propertySource === null ) { |
|
49 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for properties not stored in a database.' ); |
|
45 | + ConstraintsServices::CONSTRAINT_STORE => static function(MediaWikiServices $services) { |
|
46 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
47 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
48 | + if ($propertySource === null) { |
|
49 | + throw new RuntimeException('Can\'t get a ConstraintStore for properties not stored in a database.'); |
|
50 | 50 | } |
51 | 51 | |
52 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
53 | - if ( $propertySource->getSourceName() !== $localEntitySourceName ) { |
|
54 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for a non local entity source.' ); |
|
52 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
53 | + if ($propertySource->getSourceName() !== $localEntitySourceName) { |
|
54 | + throw new RuntimeException('Can\'t get a ConstraintStore for a non local entity source.'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | $dbName = $propertySource->getDatabaseName(); |
58 | 58 | return new ConstraintRepositoryStore( |
59 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
59 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
60 | 60 | $dbName |
61 | 61 | ); |
62 | 62 | }, |
63 | 63 | |
64 | - ConstraintsServices::CONSTRAINT_LOOKUP => static function ( MediaWikiServices $services ) { |
|
65 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
66 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
67 | - if ( $propertySource === null ) { |
|
68 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for properties not stored in a database.' ); |
|
64 | + ConstraintsServices::CONSTRAINT_LOOKUP => static function(MediaWikiServices $services) { |
|
65 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
66 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
67 | + if ($propertySource === null) { |
|
68 | + throw new RuntimeException('Can\'t get a ConstraintStore for properties not stored in a database.'); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $dbName = $propertySource->getDatabaseName(); |
72 | 72 | $rawLookup = new ConstraintRepositoryLookup( |
73 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
73 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
74 | 74 | $dbName |
75 | 75 | ); |
76 | - return new CachingConstraintLookup( $rawLookup ); |
|
76 | + return new CachingConstraintLookup($rawLookup); |
|
77 | 77 | }, |
78 | 78 | |
79 | - ConstraintsServices::CHECK_RESULT_SERIALIZER => static function ( MediaWikiServices $services ) { |
|
79 | + ConstraintsServices::CHECK_RESULT_SERIALIZER => static function(MediaWikiServices $services) { |
|
80 | 80 | return new CheckResultSerializer( |
81 | 81 | new ConstraintSerializer( |
82 | 82 | false // constraint parameters are not exposed |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | ); |
88 | 88 | }, |
89 | 89 | |
90 | - ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function ( MediaWikiServices $services ) { |
|
91 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
92 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
90 | + ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function(MediaWikiServices $services) { |
|
91 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
92 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
93 | 93 | |
94 | 94 | return new CheckResultDeserializer( |
95 | 95 | new ConstraintDeserializer(), |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | ); |
103 | 103 | }, |
104 | 104 | |
105 | - ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function ( MediaWikiServices $services ) { |
|
105 | + ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function(MediaWikiServices $services) { |
|
106 | 106 | return new ViolationMessageSerializer(); |
107 | 107 | }, |
108 | 108 | |
109 | - ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function ( MediaWikiServices $services ) { |
|
110 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
111 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
109 | + ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function(MediaWikiServices $services) { |
|
110 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
111 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
112 | 112 | |
113 | 113 | return new ViolationMessageDeserializer( |
114 | 114 | $entityIdParser, |
@@ -116,37 +116,37 @@ discard block |
||
116 | 116 | ); |
117 | 117 | }, |
118 | 118 | |
119 | - ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function ( MediaWikiServices $services ) { |
|
120 | - $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory( $services ); |
|
121 | - $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
119 | + ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function(MediaWikiServices $services) { |
|
120 | + $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory($services); |
|
121 | + $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
122 | 122 | |
123 | 123 | return new ConstraintParameterParser( |
124 | 124 | $services->getMainConfig(), |
125 | 125 | $deserializerFactory, |
126 | - $entitySourceDefinitions->getDatabaseSourceForEntityType( 'item' )->getConceptBaseUri() |
|
126 | + $entitySourceDefinitions->getDatabaseSourceForEntityType('item')->getConceptBaseUri() |
|
127 | 127 | ); |
128 | 128 | }, |
129 | 129 | |
130 | - ConstraintsServices::CONNECTION_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
130 | + ConstraintsServices::CONNECTION_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
131 | 131 | return new ConnectionCheckerHelper(); |
132 | 132 | }, |
133 | 133 | |
134 | - ConstraintsServices::RANGE_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
134 | + ConstraintsServices::RANGE_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
135 | 135 | return new RangeCheckerHelper( |
136 | 136 | $services->getMainConfig(), |
137 | - WikibaseRepo::getUnitConverter( $services ) |
|
137 | + WikibaseRepo::getUnitConverter($services) |
|
138 | 138 | ); |
139 | 139 | }, |
140 | 140 | |
141 | - ConstraintsServices::SPARQL_HELPER => static function ( MediaWikiServices $services ) { |
|
142 | - $endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
143 | - if ( $endpoint === '' ) { |
|
141 | + ConstraintsServices::SPARQL_HELPER => static function(MediaWikiServices $services) { |
|
142 | + $endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint'); |
|
143 | + if ($endpoint === '') { |
|
144 | 144 | return new DummySparqlHelper(); |
145 | 145 | } |
146 | 146 | |
147 | - $rdfVocabulary = WikibaseRepo::getRdfVocabulary( $services ); |
|
148 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
149 | - $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup( $services ); |
|
147 | + $rdfVocabulary = WikibaseRepo::getRdfVocabulary($services); |
|
148 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
149 | + $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup($services); |
|
150 | 150 | |
151 | 151 | return new SparqlHelper( |
152 | 152 | $services->getMainConfig(), |
@@ -154,126 +154,126 @@ discard block |
||
154 | 154 | $entityIdParser, |
155 | 155 | $propertyDataTypeLookup, |
156 | 156 | $services->getMainWANObjectCache(), |
157 | - ConstraintsServices::getViolationMessageSerializer( $services ), |
|
158 | - ConstraintsServices::getViolationMessageDeserializer( $services ), |
|
157 | + ConstraintsServices::getViolationMessageSerializer($services), |
|
158 | + ConstraintsServices::getViolationMessageDeserializer($services), |
|
159 | 159 | $services->getStatsdDataFactory(), |
160 | - ConstraintsServices::getExpiryLock( $services ), |
|
161 | - ConstraintsServices::getLoggingHelper( $services ), |
|
162 | - WikiMap::getCurrentWikiId() . ' WikibaseQualityConstraints ' . $services->getHttpRequestFactory()->getUserAgent(), |
|
160 | + ConstraintsServices::getExpiryLock($services), |
|
161 | + ConstraintsServices::getLoggingHelper($services), |
|
162 | + WikiMap::getCurrentWikiId().' WikibaseQualityConstraints '.$services->getHttpRequestFactory()->getUserAgent(), |
|
163 | 163 | $services->getHttpRequestFactory() |
164 | 164 | ); |
165 | 165 | }, |
166 | 166 | |
167 | - ConstraintsServices::TYPE_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
167 | + ConstraintsServices::TYPE_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
168 | 168 | return new TypeCheckerHelper( |
169 | - WikibaseServices::getEntityLookup( $services ), |
|
169 | + WikibaseServices::getEntityLookup($services), |
|
170 | 170 | $services->getMainConfig(), |
171 | - ConstraintsServices::getSparqlHelper( $services ), |
|
171 | + ConstraintsServices::getSparqlHelper($services), |
|
172 | 172 | $services->getStatsdDataFactory() |
173 | 173 | ); |
174 | 174 | }, |
175 | 175 | |
176 | - ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function ( MediaWikiServices $services ) { |
|
177 | - $statementGuidParser = WikibaseRepo::getStatementGuidParser( $services ); |
|
176 | + ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function(MediaWikiServices $services) { |
|
177 | + $statementGuidParser = WikibaseRepo::getStatementGuidParser($services); |
|
178 | 178 | |
179 | 179 | $config = $services->getMainConfig(); |
180 | 180 | $checkerMap = [ |
181 | - $config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
182 | - => ConstraintCheckerServices::getConflictsWithChecker( $services ), |
|
183 | - $config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
184 | - => ConstraintCheckerServices::getItemChecker( $services ), |
|
185 | - $config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
186 | - => ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ), |
|
187 | - $config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
188 | - => ConstraintCheckerServices::getSymmetricChecker( $services ), |
|
189 | - $config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
190 | - => ConstraintCheckerServices::getInverseChecker( $services ), |
|
191 | - $config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
192 | - => ConstraintCheckerServices::getQualifierChecker( $services ), |
|
193 | - $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
194 | - => ConstraintCheckerServices::getQualifiersChecker( $services ), |
|
195 | - $config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
196 | - => ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ), |
|
197 | - $config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
198 | - => ConstraintCheckerServices::getRangeChecker( $services ), |
|
199 | - $config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
200 | - => ConstraintCheckerServices::getDiffWithinRangeChecker( $services ), |
|
201 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
202 | - => ConstraintCheckerServices::getTypeChecker( $services ), |
|
203 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
204 | - => ConstraintCheckerServices::getValueTypeChecker( $services ), |
|
205 | - $config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
206 | - => ConstraintCheckerServices::getSingleValueChecker( $services ), |
|
207 | - $config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
208 | - => ConstraintCheckerServices::getMultiValueChecker( $services ), |
|
209 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
210 | - => ConstraintCheckerServices::getUniqueValueChecker( $services ), |
|
211 | - $config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
212 | - => ConstraintCheckerServices::getFormatChecker( $services ), |
|
213 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
214 | - => ConstraintCheckerServices::getCommonsLinkChecker( $services ), |
|
215 | - $config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
216 | - => ConstraintCheckerServices::getOneOfChecker( $services ), |
|
217 | - $config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
218 | - => ConstraintCheckerServices::getValueOnlyChecker( $services ), |
|
219 | - $config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
220 | - => ConstraintCheckerServices::getReferenceChecker( $services ), |
|
221 | - $config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
222 | - => ConstraintCheckerServices::getNoBoundsChecker( $services ), |
|
223 | - $config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
224 | - => ConstraintCheckerServices::getAllowedUnitsChecker( $services ), |
|
225 | - $config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
|
226 | - => ConstraintCheckerServices::getSingleBestValueChecker( $services ), |
|
227 | - $config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
|
228 | - => ConstraintCheckerServices::getEntityTypeChecker( $services ), |
|
229 | - $config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
|
230 | - => ConstraintCheckerServices::getNoneOfChecker( $services ), |
|
231 | - $config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
|
232 | - => ConstraintCheckerServices::getIntegerChecker( $services ), |
|
233 | - $config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
|
234 | - => ConstraintCheckerServices::getCitationNeededChecker( $services ), |
|
235 | - $config->get( 'WBQualityConstraintsPropertyScopeConstraintId' ) |
|
236 | - => ConstraintCheckerServices::getPropertyScopeChecker( $services ), |
|
237 | - $config->get( 'WBQualityConstraintsContemporaryConstraintId' ) |
|
238 | - => ConstraintCheckerServices::getContemporaryChecker( $services ), |
|
239 | - $config->get( 'WBQualityConstraintsLexemeLanguageConstraintId' ) |
|
240 | - => ConstraintCheckerServices::getLexemeLanguageChecker( $services ), |
|
241 | - $config->get( 'WBQualityConstraintsLabelInLanguageConstraintId' ) |
|
242 | - => ConstraintCheckerServices::getLabelInLanguageChecker( $services ), |
|
181 | + $config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
182 | + => ConstraintCheckerServices::getConflictsWithChecker($services), |
|
183 | + $config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
184 | + => ConstraintCheckerServices::getItemChecker($services), |
|
185 | + $config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
186 | + => ConstraintCheckerServices::getTargetRequiredClaimChecker($services), |
|
187 | + $config->get('WBQualityConstraintsSymmetricConstraintId') |
|
188 | + => ConstraintCheckerServices::getSymmetricChecker($services), |
|
189 | + $config->get('WBQualityConstraintsInverseConstraintId') |
|
190 | + => ConstraintCheckerServices::getInverseChecker($services), |
|
191 | + $config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
192 | + => ConstraintCheckerServices::getQualifierChecker($services), |
|
193 | + $config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
194 | + => ConstraintCheckerServices::getQualifiersChecker($services), |
|
195 | + $config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
196 | + => ConstraintCheckerServices::getMandatoryQualifiersChecker($services), |
|
197 | + $config->get('WBQualityConstraintsRangeConstraintId') |
|
198 | + => ConstraintCheckerServices::getRangeChecker($services), |
|
199 | + $config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
200 | + => ConstraintCheckerServices::getDiffWithinRangeChecker($services), |
|
201 | + $config->get('WBQualityConstraintsTypeConstraintId') |
|
202 | + => ConstraintCheckerServices::getTypeChecker($services), |
|
203 | + $config->get('WBQualityConstraintsValueTypeConstraintId') |
|
204 | + => ConstraintCheckerServices::getValueTypeChecker($services), |
|
205 | + $config->get('WBQualityConstraintsSingleValueConstraintId') |
|
206 | + => ConstraintCheckerServices::getSingleValueChecker($services), |
|
207 | + $config->get('WBQualityConstraintsMultiValueConstraintId') |
|
208 | + => ConstraintCheckerServices::getMultiValueChecker($services), |
|
209 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
210 | + => ConstraintCheckerServices::getUniqueValueChecker($services), |
|
211 | + $config->get('WBQualityConstraintsFormatConstraintId') |
|
212 | + => ConstraintCheckerServices::getFormatChecker($services), |
|
213 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
214 | + => ConstraintCheckerServices::getCommonsLinkChecker($services), |
|
215 | + $config->get('WBQualityConstraintsOneOfConstraintId') |
|
216 | + => ConstraintCheckerServices::getOneOfChecker($services), |
|
217 | + $config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
218 | + => ConstraintCheckerServices::getValueOnlyChecker($services), |
|
219 | + $config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
220 | + => ConstraintCheckerServices::getReferenceChecker($services), |
|
221 | + $config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
222 | + => ConstraintCheckerServices::getNoBoundsChecker($services), |
|
223 | + $config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
224 | + => ConstraintCheckerServices::getAllowedUnitsChecker($services), |
|
225 | + $config->get('WBQualityConstraintsSingleBestValueConstraintId') |
|
226 | + => ConstraintCheckerServices::getSingleBestValueChecker($services), |
|
227 | + $config->get('WBQualityConstraintsAllowedEntityTypesConstraintId') |
|
228 | + => ConstraintCheckerServices::getEntityTypeChecker($services), |
|
229 | + $config->get('WBQualityConstraintsNoneOfConstraintId') |
|
230 | + => ConstraintCheckerServices::getNoneOfChecker($services), |
|
231 | + $config->get('WBQualityConstraintsIntegerConstraintId') |
|
232 | + => ConstraintCheckerServices::getIntegerChecker($services), |
|
233 | + $config->get('WBQualityConstraintsCitationNeededConstraintId') |
|
234 | + => ConstraintCheckerServices::getCitationNeededChecker($services), |
|
235 | + $config->get('WBQualityConstraintsPropertyScopeConstraintId') |
|
236 | + => ConstraintCheckerServices::getPropertyScopeChecker($services), |
|
237 | + $config->get('WBQualityConstraintsContemporaryConstraintId') |
|
238 | + => ConstraintCheckerServices::getContemporaryChecker($services), |
|
239 | + $config->get('WBQualityConstraintsLexemeLanguageConstraintId') |
|
240 | + => ConstraintCheckerServices::getLexemeLanguageChecker($services), |
|
241 | + $config->get('WBQualityConstraintsLabelInLanguageConstraintId') |
|
242 | + => ConstraintCheckerServices::getLabelInLanguageChecker($services), |
|
243 | 243 | ]; |
244 | 244 | |
245 | 245 | return new DelegatingConstraintChecker( |
246 | - WikibaseServices::getEntityLookup( $services ), |
|
246 | + WikibaseServices::getEntityLookup($services), |
|
247 | 247 | $checkerMap, |
248 | - ConstraintsServices::getConstraintLookup( $services ), |
|
249 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
248 | + ConstraintsServices::getConstraintLookup($services), |
|
249 | + ConstraintsServices::getConstraintParameterParser($services), |
|
250 | 250 | $statementGuidParser, |
251 | - ConstraintsServices::getLoggingHelper( $services ), |
|
252 | - $config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
253 | - $config->get( 'WBQualityConstraintsCheckReferences' ), |
|
254 | - $config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
251 | + ConstraintsServices::getLoggingHelper($services), |
|
252 | + $config->get('WBQualityConstraintsCheckQualifiers'), |
|
253 | + $config->get('WBQualityConstraintsCheckReferences'), |
|
254 | + $config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
255 | 255 | ); |
256 | 256 | }, |
257 | 257 | |
258 | - ConstraintsServices::RESULTS_SOURCE => static function ( MediaWikiServices $services ) { |
|
258 | + ConstraintsServices::RESULTS_SOURCE => static function(MediaWikiServices $services) { |
|
259 | 259 | $config = $services->getMainConfig(); |
260 | 260 | $resultsSource = new CheckingResultsSource( |
261 | - ConstraintsServices::getDelegatingConstraintChecker( $services ) |
|
261 | + ConstraintsServices::getDelegatingConstraintChecker($services) |
|
262 | 262 | ); |
263 | 263 | |
264 | 264 | $cacheCheckConstraintsResults = false; |
265 | 265 | |
266 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
266 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
267 | 267 | $cacheCheckConstraintsResults = true; |
268 | 268 | // check that we can use getLocalRepoWikiPageMetaDataAccessor() |
269 | 269 | // TODO we should always be able to cache constraint check results (T244726) |
270 | - $entitySources = WikibaseRepo::getEntitySourceDefinitions( $services )->getSources(); |
|
271 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
270 | + $entitySources = WikibaseRepo::getEntitySourceDefinitions($services)->getSources(); |
|
271 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
272 | 272 | |
273 | - foreach ( $entitySources as $entitySource ) { |
|
274 | - if ( $entitySource->getSourceName() !== $localEntitySourceName ) { |
|
275 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' )->warning( |
|
276 | - 'Cannot cache constraint check results for non-local source: ' . |
|
273 | + foreach ($entitySources as $entitySource) { |
|
274 | + if ($entitySource->getSourceName() !== $localEntitySourceName) { |
|
275 | + LoggerFactory::getInstance('WikibaseQualityConstraints')->warning( |
|
276 | + 'Cannot cache constraint check results for non-local source: '. |
|
277 | 277 | $entitySource->getSourceName() |
278 | 278 | ); |
279 | 279 | $cacheCheckConstraintsResults = false; |
@@ -282,40 +282,40 @@ discard block |
||
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
285 | - if ( $cacheCheckConstraintsResults ) { |
|
285 | + if ($cacheCheckConstraintsResults) { |
|
286 | 286 | $possiblyStaleConstraintTypes = [ |
287 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
288 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
289 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
290 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
287 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
288 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
289 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
290 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
291 | 291 | ]; |
292 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
292 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
293 | 293 | $wikiPageEntityMetaDataAccessor = WikibaseRepo::getLocalRepoWikiPageMetaDataAccessor( |
294 | 294 | $services ); |
295 | 295 | |
296 | 296 | $resultsSource = new CachingResultsSource( |
297 | 297 | $resultsSource, |
298 | 298 | ResultsCache::getDefaultInstance(), |
299 | - ConstraintsServices::getCheckResultSerializer( $services ), |
|
300 | - ConstraintsServices::getCheckResultDeserializer( $services ), |
|
299 | + ConstraintsServices::getCheckResultSerializer($services), |
|
300 | + ConstraintsServices::getCheckResultDeserializer($services), |
|
301 | 301 | $wikiPageEntityMetaDataAccessor, |
302 | 302 | $entityIdParser, |
303 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
303 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
304 | 304 | $possiblyStaleConstraintTypes, |
305 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
306 | - ConstraintsServices::getLoggingHelper( $services ) |
|
305 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
306 | + ConstraintsServices::getLoggingHelper($services) |
|
307 | 307 | ); |
308 | 308 | } |
309 | 309 | |
310 | 310 | return $resultsSource; |
311 | 311 | }, |
312 | 312 | |
313 | - ConstraintsServices::VIOLATION_MESSAGE_RENDERER_FACTORY => static function ( MediaWikiServices $services ) { |
|
313 | + ConstraintsServices::VIOLATION_MESSAGE_RENDERER_FACTORY => static function(MediaWikiServices $services) { |
|
314 | 314 | return new ViolationMessageRendererFactory( |
315 | 315 | $services->getMainConfig(), |
316 | 316 | $services->getLanguageNameUtils(), |
317 | - WikibaseRepo::getEntityIdHtmlLinkFormatterFactory( $services ), |
|
318 | - WikibaseRepo::getValueFormatterFactory( $services ) |
|
317 | + WikibaseRepo::getEntityIdHtmlLinkFormatterFactory($services), |
|
318 | + WikibaseRepo::getValueFormatterFactory($services) |
|
319 | 319 | ); |
320 | 320 | }, |
321 | 321 | ]; |
@@ -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 | } |
@@ -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 | |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | ): ViolationMessageRenderer { |
42 | 42 | $userLanguageCode = $userLanguage->getCode(); |
43 | 43 | $formatterOptions = new FormatterOptions(); |
44 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $userLanguageCode ); |
|
44 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $userLanguageCode); |
|
45 | 45 | return new MultilingualTextViolationMessageRenderer( |
46 | 46 | $this->entityIdHtmlLinkFormatterFactory |
47 | - ->getEntityIdFormatter( $userLanguage ), |
|
47 | + ->getEntityIdFormatter($userLanguage), |
|
48 | 48 | $this->valueFormatterFactory |
49 | - ->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ), |
|
49 | + ->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions), |
|
50 | 50 | $this->languageNameUtils, |
51 | 51 | $userLanguageCode, |
52 | 52 | $messageLocalizer, |
@@ -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 |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | callable $defaultResultsPerEntity = null |
145 | 145 | ) { |
146 | 146 | $checkResults = []; |
147 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
147 | + $entity = $this->entityLookup->getEntity($entityId); |
|
148 | 148 | |
149 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
150 | - $startTime = microtime( true ); |
|
149 | + if ($entity instanceof StatementListProvidingEntity) { |
|
150 | + $startTime = microtime(true); |
|
151 | 151 | |
152 | 152 | $checkResults = $this->checkEveryStatement( |
153 | 153 | $entity, |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | $defaultResultsPerContext |
156 | 156 | ); |
157 | 157 | |
158 | - $endTime = microtime( true ); |
|
158 | + $endTime = microtime(true); |
|
159 | 159 | |
160 | - if ( $constraintIds === null ) { // only log full constraint checks |
|
160 | + if ($constraintIds === null) { // only log full constraint checks |
|
161 | 161 | $this->loggingHelper->logConstraintCheckOnEntity( |
162 | 162 | $entityId, |
163 | 163 | $checkResults, |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | } |
168 | 168 | } |
169 | 169 | |
170 | - if ( $defaultResultsPerEntity !== null ) { |
|
171 | - $checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults ); |
|
170 | + if ($defaultResultsPerEntity !== null) { |
|
171 | + $checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults); |
|
172 | 172 | } |
173 | 173 | |
174 | - return $this->sortResult( $checkResults ); |
|
174 | + return $this->sortResult($checkResults); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | callable $defaultResults = null |
194 | 194 | ) { |
195 | 195 | |
196 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
196 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
197 | 197 | $entityId = $parsedGuid->getEntityId(); |
198 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
199 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
200 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
201 | - if ( $statement ) { |
|
198 | + $entity = $this->entityLookup->getEntity($entityId); |
|
199 | + if ($entity instanceof StatementListProvidingEntity) { |
|
200 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
201 | + if ($statement) { |
|
202 | 202 | $result = $this->checkStatement( |
203 | 203 | $entity, |
204 | 204 | $statement, |
205 | 205 | $constraintIds, |
206 | 206 | $defaultResults |
207 | 207 | ); |
208 | - $output = $this->sortResult( $result ); |
|
208 | + $output = $this->sortResult($result); |
|
209 | 209 | return $output; |
210 | 210 | } |
211 | 211 | } |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | return []; |
214 | 214 | } |
215 | 215 | |
216 | - private function getValidContextTypes( Constraint $constraint ) { |
|
217 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
216 | + private function getValidContextTypes(Constraint $constraint) { |
|
217 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
218 | 218 | return [ |
219 | 219 | Context::TYPE_STATEMENT, |
220 | 220 | Context::TYPE_QUALIFIER, |
@@ -222,25 +222,25 @@ discard block |
||
222 | 222 | ]; |
223 | 223 | } |
224 | 224 | |
225 | - return array_keys( array_filter( |
|
225 | + return array_keys(array_filter( |
|
226 | 226 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
227 | - static function ( $resultStatus ) { |
|
227 | + static function($resultStatus) { |
|
228 | 228 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
229 | 229 | } |
230 | - ) ); |
|
230 | + )); |
|
231 | 231 | } |
232 | 232 | |
233 | - private function getValidEntityTypes( Constraint $constraint ) { |
|
234 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
235 | - return array_keys( ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED ); |
|
233 | + private function getValidEntityTypes(Constraint $constraint) { |
|
234 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
235 | + return array_keys(ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED); |
|
236 | 236 | } |
237 | 237 | |
238 | - return array_keys( array_filter( |
|
238 | + return array_keys(array_filter( |
|
239 | 239 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedEntityTypes(), |
240 | - static function ( $resultStatus ) { |
|
240 | + static function($resultStatus) { |
|
241 | 241 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
242 | 242 | } |
243 | - ) ); |
|
243 | + )); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -251,33 +251,33 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @return ConstraintParameterException[] |
253 | 253 | */ |
254 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
254 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
255 | 255 | $constraintParameters = $constraint->getConstraintParameters(); |
256 | 256 | try { |
257 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
258 | - } catch ( ConstraintParameterException $e ) { |
|
259 | - return [ $e ]; |
|
257 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
258 | + } catch (ConstraintParameterException $e) { |
|
259 | + return [$e]; |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | $problems = []; |
263 | 263 | try { |
264 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
265 | - } catch ( ConstraintParameterException $e ) { |
|
264 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
265 | + } catch (ConstraintParameterException $e) { |
|
266 | 266 | $problems[] = $e; |
267 | 267 | } |
268 | 268 | try { |
269 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
270 | - } catch ( ConstraintParameterException $e ) { |
|
269 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
270 | + } catch (ConstraintParameterException $e) { |
|
271 | 271 | $problems[] = $e; |
272 | 272 | } |
273 | 273 | try { |
274 | 274 | $this->constraintParameterParser->parseConstraintScopeParameters( |
275 | 275 | $constraintParameters, |
276 | 276 | $constraint->getConstraintTypeItemId(), |
277 | - $this->getValidContextTypes( $constraint ), |
|
278 | - $this->getValidEntityTypes( $constraint ) |
|
277 | + $this->getValidContextTypes($constraint), |
|
278 | + $this->getValidEntityTypes($constraint) |
|
279 | 279 | ); |
280 | - } catch ( ConstraintParameterException $e ) { |
|
280 | + } catch (ConstraintParameterException $e) { |
|
281 | 281 | $problems[] = $e; |
282 | 282 | } |
283 | 283 | return $problems; |
@@ -290,16 +290,16 @@ discard block |
||
290 | 290 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
291 | 291 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
292 | 292 | */ |
293 | - public function checkConstraintParametersOnPropertyId( NumericPropertyId $propertyId ) { |
|
294 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
293 | + public function checkConstraintParametersOnPropertyId(NumericPropertyId $propertyId) { |
|
294 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
295 | 295 | $result = []; |
296 | 296 | |
297 | - foreach ( $constraints as $constraint ) { |
|
298 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
297 | + foreach ($constraints as $constraint) { |
|
298 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
299 | 299 | |
300 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
300 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
301 | 301 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
302 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
302 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | $result[$constraint->getConstraintId()] = $problems; |
@@ -316,18 +316,18 @@ discard block |
||
316 | 316 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
317 | 317 | * (empty means all parameters okay), or null if constraint is not found |
318 | 318 | */ |
319 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
320 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
319 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
320 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
321 | 321 | '@phan-var NumericPropertyId $propertyId'; |
322 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
322 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
323 | 323 | |
324 | - foreach ( $constraints as $constraint ) { |
|
325 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
326 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
324 | + foreach ($constraints as $constraint) { |
|
325 | + if ($constraint->getConstraintId() === $constraintId) { |
|
326 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
327 | 327 | |
328 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
328 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
329 | 329 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
330 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
330 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | return $problems; |
@@ -352,14 +352,14 @@ discard block |
||
352 | 352 | $result = []; |
353 | 353 | |
354 | 354 | /** @var Statement $statement */ |
355 | - foreach ( $entity->getStatements() as $statement ) { |
|
356 | - $result = array_merge( $result, |
|
355 | + foreach ($entity->getStatements() as $statement) { |
|
356 | + $result = array_merge($result, |
|
357 | 357 | $this->checkStatement( |
358 | 358 | $entity, |
359 | 359 | $statement, |
360 | 360 | $constraintIds, |
361 | 361 | $defaultResultsPerContext |
362 | - ) ); |
|
362 | + )); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | return $result; |
@@ -381,32 +381,32 @@ discard block |
||
381 | 381 | ) { |
382 | 382 | $result = []; |
383 | 383 | |
384 | - $result = array_merge( $result, |
|
384 | + $result = array_merge($result, |
|
385 | 385 | $this->checkConstraintsForMainSnak( |
386 | 386 | $entity, |
387 | 387 | $statement, |
388 | 388 | $constraintIds, |
389 | 389 | $defaultResultsPerContext |
390 | - ) ); |
|
390 | + )); |
|
391 | 391 | |
392 | - if ( $this->checkQualifiers ) { |
|
393 | - $result = array_merge( $result, |
|
392 | + if ($this->checkQualifiers) { |
|
393 | + $result = array_merge($result, |
|
394 | 394 | $this->checkConstraintsForQualifiers( |
395 | 395 | $entity, |
396 | 396 | $statement, |
397 | 397 | $constraintIds, |
398 | 398 | $defaultResultsPerContext |
399 | - ) ); |
|
399 | + )); |
|
400 | 400 | } |
401 | 401 | |
402 | - if ( $this->checkReferences ) { |
|
403 | - $result = array_merge( $result, |
|
402 | + if ($this->checkReferences) { |
|
403 | + $result = array_merge($result, |
|
404 | 404 | $this->checkConstraintsForReferences( |
405 | 405 | $entity, |
406 | 406 | $statement, |
407 | 407 | $constraintIds, |
408 | 408 | $defaultResultsPerContext |
409 | - ) ); |
|
409 | + )); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | return $result; |
@@ -421,17 +421,17 @@ discard block |
||
421 | 421 | * @param string[]|null $constraintIds |
422 | 422 | * @return Constraint[] |
423 | 423 | */ |
424 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
425 | - if ( !( $propertyId instanceof NumericPropertyId ) ) { |
|
424 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
425 | + if (!($propertyId instanceof NumericPropertyId)) { |
|
426 | 426 | throw new InvalidArgumentException( |
427 | - 'Non-numeric property ID not supported:' . $propertyId->getSerialization() |
|
427 | + 'Non-numeric property ID not supported:'.$propertyId->getSerialization() |
|
428 | 428 | ); |
429 | 429 | } |
430 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
431 | - if ( $constraintIds !== null ) { |
|
430 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
431 | + if ($constraintIds !== null) { |
|
432 | 432 | $constraintsToUse = []; |
433 | - foreach ( $constraints as $constraint ) { |
|
434 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
433 | + foreach ($constraints as $constraint) { |
|
434 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
435 | 435 | $constraintsToUse[] = $constraint; |
436 | 436 | } |
437 | 437 | } |
@@ -455,18 +455,18 @@ discard block |
||
455 | 455 | array $constraintIds = null, |
456 | 456 | callable $defaultResults = null |
457 | 457 | ) { |
458 | - $context = new MainSnakContext( $entity, $statement ); |
|
458 | + $context = new MainSnakContext($entity, $statement); |
|
459 | 459 | $constraints = $this->getConstraintsToUse( |
460 | 460 | $statement->getPropertyId(), |
461 | 461 | $constraintIds |
462 | 462 | ); |
463 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
463 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
464 | 464 | |
465 | - foreach ( $constraints as $constraint ) { |
|
465 | + foreach ($constraints as $constraint) { |
|
466 | 466 | $parameters = $constraint->getConstraintParameters(); |
467 | 467 | try { |
468 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
469 | - } catch ( ConstraintParameterException $e ) { |
|
468 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
469 | + } catch (ConstraintParameterException $e) { |
|
470 | 470 | $result[] = new CheckResult( |
471 | 471 | $context, |
472 | 472 | $constraint, |
@@ -476,13 +476,13 @@ discard block |
||
476 | 476 | continue; |
477 | 477 | } |
478 | 478 | |
479 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
480 | - $message = new ViolationMessage( 'wbqc-violation-message-exception' ); |
|
481 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
479 | + if (in_array($entity->getId(), $exceptions)) { |
|
480 | + $message = new ViolationMessage('wbqc-violation-message-exception'); |
|
481 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
482 | 482 | continue; |
483 | 483 | } |
484 | 484 | |
485 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
485 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | return $result; |
@@ -504,24 +504,24 @@ discard block |
||
504 | 504 | ) { |
505 | 505 | $result = []; |
506 | 506 | |
507 | - if ( in_array( |
|
507 | + if (in_array( |
|
508 | 508 | $statement->getPropertyId()->getSerialization(), |
509 | 509 | $this->propertiesWithViolatingQualifiers |
510 | - ) ) { |
|
510 | + )) { |
|
511 | 511 | return $result; |
512 | 512 | } |
513 | 513 | |
514 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
515 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
516 | - if ( $defaultResultsPerContext !== null ) { |
|
517 | - $result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) ); |
|
514 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
515 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
516 | + if ($defaultResultsPerContext !== null) { |
|
517 | + $result = array_merge($result, $defaultResultsPerContext($qualifierContext)); |
|
518 | 518 | } |
519 | 519 | $qualifierConstraints = $this->getConstraintsToUse( |
520 | 520 | $qualifierContext->getSnak()->getPropertyId(), |
521 | 521 | $constraintIds |
522 | 522 | ); |
523 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
524 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
523 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
524 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
525 | 525 | } |
526 | 526 | } |
527 | 527 | |
@@ -545,19 +545,19 @@ discard block |
||
545 | 545 | $result = []; |
546 | 546 | |
547 | 547 | /** @var Reference $reference */ |
548 | - foreach ( $statement->getReferences() as $reference ) { |
|
549 | - foreach ( $reference->getSnaks() as $snak ) { |
|
548 | + foreach ($statement->getReferences() as $reference) { |
|
549 | + foreach ($reference->getSnaks() as $snak) { |
|
550 | 550 | $referenceContext = new ReferenceContext( |
551 | 551 | $entity, $statement, $reference, $snak |
552 | 552 | ); |
553 | - if ( $defaultResultsPerContext !== null ) { |
|
554 | - $result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) ); |
|
553 | + if ($defaultResultsPerContext !== null) { |
|
554 | + $result = array_merge($result, $defaultResultsPerContext($referenceContext)); |
|
555 | 555 | } |
556 | 556 | $referenceConstraints = $this->getConstraintsToUse( |
557 | 557 | $referenceContext->getSnak()->getPropertyId(), |
558 | 558 | $constraintIds |
559 | 559 | ); |
560 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
560 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
561 | 561 | $result[] = $this->getCheckResultFor( |
562 | 562 | $referenceContext, |
563 | 563 | $referenceConstraint |
@@ -575,20 +575,20 @@ discard block |
||
575 | 575 | * |
576 | 576 | * @return CheckResult |
577 | 577 | */ |
578 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
579 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
578 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
579 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
580 | 580 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
581 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
581 | + $result = $this->handleScope($checker, $context, $constraint); |
|
582 | 582 | |
583 | - if ( $result !== null ) { |
|
584 | - $this->addMetadata( $context, $result ); |
|
583 | + if ($result !== null) { |
|
584 | + $this->addMetadata($context, $result); |
|
585 | 585 | return $result; |
586 | 586 | } |
587 | 587 | |
588 | - $startTime = microtime( true ); |
|
588 | + $startTime = microtime(true); |
|
589 | 589 | try { |
590 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
591 | - } catch ( ConstraintParameterException $e ) { |
|
590 | + $result = $checker->checkConstraint($context, $constraint); |
|
591 | + } catch (ConstraintParameterException $e) { |
|
592 | 592 | $result = new CheckResult( |
593 | 593 | $context, |
594 | 594 | $constraint, |
@@ -596,28 +596,28 @@ discard block |
||
596 | 596 | CheckResult::STATUS_BAD_PARAMETERS, |
597 | 597 | $e->getViolationMessage() |
598 | 598 | ); |
599 | - } catch ( SparqlHelperException $e ) { |
|
600 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
601 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, $message ); |
|
599 | + } catch (SparqlHelperException $e) { |
|
600 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
601 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, $message); |
|
602 | 602 | } |
603 | - $endTime = microtime( true ); |
|
603 | + $endTime = microtime(true); |
|
604 | 604 | |
605 | - $this->addMetadata( $context, $result ); |
|
605 | + $this->addMetadata($context, $result); |
|
606 | 606 | |
607 | - $this->downgradeResultStatus( $context, $result ); |
|
607 | + $this->downgradeResultStatus($context, $result); |
|
608 | 608 | |
609 | 609 | $this->loggingHelper->logConstraintCheck( |
610 | 610 | $context, |
611 | 611 | $constraint, |
612 | 612 | $result, |
613 | - get_class( $checker ), |
|
613 | + get_class($checker), |
|
614 | 614 | $endTime - $startTime, |
615 | 615 | __METHOD__ |
616 | 616 | ); |
617 | 617 | |
618 | 618 | return $result; |
619 | 619 | } else { |
620 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
620 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
621 | 621 | } |
622 | 622 | } |
623 | 623 | |
@@ -626,84 +626,84 @@ discard block |
||
626 | 626 | Context $context, |
627 | 627 | Constraint $constraint |
628 | 628 | ): ?CheckResult { |
629 | - $validContextTypes = $this->getValidContextTypes( $constraint ); |
|
630 | - $validEntityTypes = $this->getValidEntityTypes( $constraint ); |
|
629 | + $validContextTypes = $this->getValidContextTypes($constraint); |
|
630 | + $validEntityTypes = $this->getValidEntityTypes($constraint); |
|
631 | 631 | try { |
632 | - [ $checkedContextTypes, $checkedEntityTypes ] = $this->constraintParameterParser->parseConstraintScopeParameters( |
|
632 | + [$checkedContextTypes, $checkedEntityTypes] = $this->constraintParameterParser->parseConstraintScopeParameters( |
|
633 | 633 | $constraint->getConstraintParameters(), |
634 | 634 | $constraint->getConstraintTypeItemId(), |
635 | 635 | $validContextTypes, |
636 | 636 | $validEntityTypes |
637 | 637 | ); |
638 | - } catch ( ConstraintParameterException $e ) { |
|
639 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
638 | + } catch (ConstraintParameterException $e) { |
|
639 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
640 | 640 | } |
641 | 641 | |
642 | - if ( $checkedContextTypes === null ) { |
|
642 | + if ($checkedContextTypes === null) { |
|
643 | 643 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
644 | 644 | } |
645 | 645 | $contextType = $context->getType(); |
646 | - if ( !in_array( $contextType, $checkedContextTypes ) ) { |
|
647 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
646 | + if (!in_array($contextType, $checkedContextTypes)) { |
|
647 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
648 | 648 | } |
649 | - if ( $checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO ) { |
|
650 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
649 | + if ($checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO) { |
|
650 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
651 | 651 | } |
652 | 652 | |
653 | - if ( $checkedEntityTypes === null ) { |
|
653 | + if ($checkedEntityTypes === null) { |
|
654 | 654 | $checkedEntityTypes = $validEntityTypes; |
655 | 655 | } |
656 | 656 | $entityType = $context->getEntity()->getType(); |
657 | - if ( !in_array( $entityType, $checkedEntityTypes ) ) { |
|
658 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
657 | + if (!in_array($entityType, $checkedEntityTypes)) { |
|
658 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
659 | 659 | } |
660 | - if ( $checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO ) { |
|
661 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
660 | + if ($checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO) { |
|
661 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | return null; |
665 | 665 | } |
666 | 666 | |
667 | - private function addMetadata( Context $context, CheckResult $result ) { |
|
668 | - $result->withMetadata( Metadata::merge( [ |
|
667 | + private function addMetadata(Context $context, CheckResult $result) { |
|
668 | + $result->withMetadata(Metadata::merge([ |
|
669 | 669 | $result->getMetadata(), |
670 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
671 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
672 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
673 | - ] ) ), |
|
674 | - ] ) ); |
|
670 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
671 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
672 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
673 | + ])), |
|
674 | + ])); |
|
675 | 675 | } |
676 | 676 | |
677 | - private function downgradeResultStatus( Context $context, CheckResult &$result ) { |
|
677 | + private function downgradeResultStatus(Context $context, CheckResult & $result) { |
|
678 | 678 | $constraint = $result->getConstraint(); |
679 | 679 | try { |
680 | 680 | $constraintStatus = $this->constraintParameterParser |
681 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
682 | - } catch ( ConstraintParameterException $e ) { |
|
683 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
681 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
682 | + } catch (ConstraintParameterException $e) { |
|
683 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
684 | 684 | $constraintStatus = null; |
685 | 685 | } |
686 | - if ( $constraintStatus === null ) { |
|
686 | + if ($constraintStatus === null) { |
|
687 | 687 | // downgrade violation to warning |
688 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
689 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
688 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
689 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
690 | 690 | } |
691 | - } elseif ( $constraintStatus === 'suggestion' ) { |
|
691 | + } elseif ($constraintStatus === 'suggestion') { |
|
692 | 692 | // downgrade violation to suggestion |
693 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
694 | - $result->setStatus( CheckResult::STATUS_SUGGESTION ); |
|
693 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
694 | + $result->setStatus(CheckResult::STATUS_SUGGESTION); |
|
695 | 695 | } |
696 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
696 | + $result->addParameter('constraint_status', $constraintStatus); |
|
697 | 697 | } else { |
698 | - if ( $constraintStatus !== 'mandatory' ) { |
|
698 | + if ($constraintStatus !== 'mandatory') { |
|
699 | 699 | // @codeCoverageIgnoreStart |
700 | 700 | throw new LogicException( |
701 | - "Unknown constraint status '$constraintStatus', " . |
|
701 | + "Unknown constraint status '$constraintStatus', ". |
|
702 | 702 | "only known statuses are 'mandatory' and 'suggestion'" |
703 | 703 | ); |
704 | 704 | // @codeCoverageIgnoreEnd |
705 | 705 | } |
706 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
706 | + $result->addParameter('constraint_status', $constraintStatus); |
|
707 | 707 | } |
708 | 708 | } |
709 | 709 | |
@@ -712,12 +712,12 @@ discard block |
||
712 | 712 | * |
713 | 713 | * @return CheckResult[] |
714 | 714 | */ |
715 | - private function sortResult( array $result ) { |
|
716 | - if ( count( $result ) < 2 ) { |
|
715 | + private function sortResult(array $result) { |
|
716 | + if (count($result) < 2) { |
|
717 | 717 | return $result; |
718 | 718 | } |
719 | 719 | |
720 | - $sortFunction = static function ( CheckResult $a, CheckResult $b ) { |
|
720 | + $sortFunction = static function(CheckResult $a, CheckResult $b) { |
|
721 | 721 | $orderNum = 0; |
722 | 722 | $order = [ |
723 | 723 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -734,55 +734,55 @@ discard block |
||
734 | 734 | $statusA = $a->getStatus(); |
735 | 735 | $statusB = $b->getStatus(); |
736 | 736 | |
737 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
738 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
737 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
738 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
739 | 739 | |
740 | - if ( $orderA === $orderB ) { |
|
740 | + if ($orderA === $orderB) { |
|
741 | 741 | $cursorA = $a->getContextCursor(); |
742 | 742 | $cursorB = $b->getContextCursor(); |
743 | 743 | |
744 | - if ( $cursorA instanceof EntityContextCursor ) { |
|
744 | + if ($cursorA instanceof EntityContextCursor) { |
|
745 | 745 | return $cursorB instanceof EntityContextCursor ? 0 : -1; |
746 | 746 | } |
747 | - if ( $cursorB instanceof EntityContextCursor ) { |
|
747 | + if ($cursorB instanceof EntityContextCursor) { |
|
748 | 748 | return $cursorA instanceof EntityContextCursor ? 0 : 1; |
749 | 749 | } |
750 | 750 | |
751 | 751 | $pidA = $cursorA->getSnakPropertyId(); |
752 | 752 | $pidB = $cursorB->getSnakPropertyId(); |
753 | 753 | |
754 | - if ( $pidA === $pidB ) { |
|
754 | + if ($pidA === $pidB) { |
|
755 | 755 | $hashA = $cursorA->getSnakHash(); |
756 | 756 | $hashB = $cursorB->getSnakHash(); |
757 | 757 | |
758 | - if ( $hashA === $hashB ) { |
|
759 | - if ( $a instanceof NullResult ) { |
|
758 | + if ($hashA === $hashB) { |
|
759 | + if ($a instanceof NullResult) { |
|
760 | 760 | return $b instanceof NullResult ? 0 : -1; |
761 | 761 | } |
762 | - if ( $b instanceof NullResult ) { |
|
762 | + if ($b instanceof NullResult) { |
|
763 | 763 | return $a instanceof NullResult ? 0 : 1; |
764 | 764 | } |
765 | 765 | |
766 | 766 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
767 | 767 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
768 | 768 | |
769 | - if ( $typeA == $typeB ) { |
|
769 | + if ($typeA == $typeB) { |
|
770 | 770 | return 0; |
771 | 771 | } else { |
772 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
772 | + return ($typeA > $typeB) ? 1 : -1; |
|
773 | 773 | } |
774 | 774 | } else { |
775 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
775 | + return ($hashA > $hashB) ? 1 : -1; |
|
776 | 776 | } |
777 | 777 | } else { |
778 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
778 | + return ($pidA > $pidB) ? 1 : -1; |
|
779 | 779 | } |
780 | 780 | } else { |
781 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
781 | + return ($orderA > $orderB) ? 1 : -1; |
|
782 | 782 | } |
783 | 783 | }; |
784 | 784 | |
785 | - uasort( $result, $sortFunction ); |
|
785 | + uasort($result, $sortFunction); |
|
786 | 786 | |
787 | 787 | return $result; |
788 | 788 | } |