@@ -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 | ]; |
@@ -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 | $messageLocalizer, |
52 | 52 | $this->config |