@@ -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 | |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | CheckResultsRendererFactory $checkResultsRendererFactory, |
| 85 | 85 | StatsFactory $statsFactory |
| 86 | 86 | ) { |
| 87 | - parent::__construct( $main, $name ); |
|
| 87 | + parent::__construct($main, $name); |
|
| 88 | 88 | $this->entityIdParser = $entityIdParser; |
| 89 | 89 | $this->statementGuidValidator = $statementGuidValidator; |
| 90 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
| 91 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
| 90 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
| 91 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
| 92 | 92 | $this->resultsSource = $resultsSource; |
| 93 | 93 | $this->checkResultsRendererFactory = $checkResultsRendererFactory; |
| 94 | 94 | $this->statsFactory = $statsFactory; |
@@ -98,21 +98,21 @@ discard block |
||
| 98 | 98 | * Evaluates the parameters, runs the requested constraint check, and sets up the result |
| 99 | 99 | */ |
| 100 | 100 | public function execute() { |
| 101 | - $this->statsFactory->getCounter( 'check_constraints_execute_total' ) |
|
| 101 | + $this->statsFactory->getCounter('check_constraints_execute_total') |
|
| 102 | 102 | ->increment(); |
| 103 | 103 | |
| 104 | - $this->checkUserRightsAny( 'wbqc-check-constraints' ); |
|
| 104 | + $this->checkUserRightsAny('wbqc-check-constraints'); |
|
| 105 | 105 | |
| 106 | 106 | $params = $this->extractRequestParams(); |
| 107 | 107 | |
| 108 | - $this->validateParameters( $params ); |
|
| 109 | - $entityIds = $this->parseEntityIds( $params ); |
|
| 110 | - $claimIds = $this->parseClaimIds( $params ); |
|
| 108 | + $this->validateParameters($params); |
|
| 109 | + $entityIds = $this->parseEntityIds($params); |
|
| 110 | + $claimIds = $this->parseClaimIds($params); |
|
| 111 | 111 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
| 112 | 112 | $statuses = $params[self::PARAM_STATUS]; |
| 113 | 113 | |
| 114 | 114 | $checkResultsRenderer = $this->checkResultsRendererFactory |
| 115 | - ->getCheckResultsRenderer( $this->getLanguage(), $this ); |
|
| 115 | + ->getCheckResultsRenderer($this->getLanguage(), $this); |
|
| 116 | 116 | |
| 117 | 117 | $this->getResult()->addValue( |
| 118 | 118 | null, |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | ) |
| 127 | 127 | )->getArray() |
| 128 | 128 | ); |
| 129 | - $this->resultBuilder->markSuccess( 1 ); |
|
| 129 | + $this->resultBuilder->markSuccess(1); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -134,24 +134,24 @@ discard block |
||
| 134 | 134 | * |
| 135 | 135 | * @return EntityId[] |
| 136 | 136 | */ |
| 137 | - private function parseEntityIds( array $params ): array { |
|
| 137 | + private function parseEntityIds(array $params): array { |
|
| 138 | 138 | $ids = $params[self::PARAM_ID]; |
| 139 | 139 | |
| 140 | - if ( $ids === null ) { |
|
| 140 | + if ($ids === null) { |
|
| 141 | 141 | return []; |
| 142 | - } elseif ( $ids === [] ) { |
|
| 142 | + } elseif ($ids === []) { |
|
| 143 | 143 | $this->errorReporter->dieError( |
| 144 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
| 144 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - return array_map( function ( $id ) { |
|
| 147 | + return array_map(function($id) { |
|
| 148 | 148 | try { |
| 149 | - return $this->entityIdParser->parse( $id ); |
|
| 150 | - } catch ( EntityIdParsingException ) { |
|
| 149 | + return $this->entityIdParser->parse($id); |
|
| 150 | + } catch (EntityIdParsingException) { |
|
| 151 | 151 | $this->errorReporter->dieError( |
| 152 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
| 152 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
| 153 | 153 | } |
| 154 | - }, $ids ); |
|
| 154 | + }, $ids); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -159,35 +159,35 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @return string[] |
| 161 | 161 | */ |
| 162 | - private function parseClaimIds( array $params ): array { |
|
| 162 | + private function parseClaimIds(array $params): array { |
|
| 163 | 163 | $ids = $params[self::PARAM_CLAIM_ID]; |
| 164 | 164 | |
| 165 | - if ( $ids === null ) { |
|
| 165 | + if ($ids === null) { |
|
| 166 | 166 | return []; |
| 167 | - } elseif ( $ids === [] ) { |
|
| 167 | + } elseif ($ids === []) { |
|
| 168 | 168 | $this->errorReporter->dieError( |
| 169 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
| 169 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - foreach ( $ids as $id ) { |
|
| 173 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
| 172 | + foreach ($ids as $id) { |
|
| 173 | + if (!$this->statementGuidValidator->validate($id)) { |
|
| 174 | 174 | $this->errorReporter->dieError( |
| 175 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
| 175 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | return $ids; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - private function validateParameters( array $params ): void { |
|
| 183 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
| 184 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
| 182 | + private function validateParameters(array $params): void { |
|
| 183 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
| 184 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
| 185 | 185 | ) { |
| 186 | 186 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
| 187 | 187 | $this->errorReporter->dieError( |
| 188 | 188 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
| 189 | 189 | } |
| 190 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
| 190 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
| 191 | 191 | $paramId = self::PARAM_ID; |
| 192 | 192 | $paramClaimId = self::PARAM_CLAIM_ID; |
| 193 | 193 | $this->errorReporter->dieError( |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | ], |
| 229 | 229 | ParamValidator::PARAM_ISMULTI => true, |
| 230 | 230 | ParamValidator::PARAM_ALL => true, |
| 231 | - ParamValidator::PARAM_DEFAULT => implode( '|', CachingResultsSource::CACHED_STATUSES ), |
|
| 231 | + ParamValidator::PARAM_DEFAULT => implode('|', CachingResultsSource::CACHED_STATUSES), |
|
| 232 | 232 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
| 233 | 233 | ], |
| 234 | 234 | ]; |
@@ -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 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $delegatingConstraintChecker, |
| 66 | 66 | $violationMessageRendererFactory, |
| 67 | 67 | $statementGuidParser, |
| 68 | - $statsFactory->withComponent( 'WikibaseQualityConstraints' ) |
|
| 68 | + $statsFactory->withComponent('WikibaseQualityConstraints') |
|
| 69 | 69 | ); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | StatementGuidParser $statementGuidParser, |
| 80 | 80 | StatsFactory $statsFactory |
| 81 | 81 | ) { |
| 82 | - parent::__construct( $main, $name ); |
|
| 82 | + parent::__construct($main, $name); |
|
| 83 | 83 | |
| 84 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
| 84 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
| 85 | 85 | $this->languageFallbackChainFactory = $languageFallbackChainFactory; |
| 86 | 86 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
| 87 | 87 | $this->violationMessageRendererFactory = $violationMessageRendererFactory; |
@@ -90,47 +90,47 @@ discard block |
||
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | public function execute() { |
| 93 | - $this->statsFactory->getCounter( 'check_constraint_parameters_execute_total' ) |
|
| 93 | + $this->statsFactory->getCounter('check_constraint_parameters_execute_total') |
|
| 94 | 94 | ->increment(); |
| 95 | 95 | |
| 96 | - $this->checkUserRightsAny( 'wbqc-check-constraints' ); |
|
| 96 | + $this->checkUserRightsAny('wbqc-check-constraints'); |
|
| 97 | 97 | |
| 98 | 98 | $params = $this->extractRequestParams(); |
| 99 | 99 | $result = $this->getResult(); |
| 100 | 100 | |
| 101 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
| 102 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
| 101 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
| 102 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
| 103 | 103 | |
| 104 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
| 105 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
| 104 | + $this->checkPropertyIds($propertyIds, $result); |
|
| 105 | + $this->checkConstraintIds($constraintIds, $result); |
|
| 106 | 106 | |
| 107 | - $result->addValue( null, 'success', 1 ); |
|
| 107 | + $result->addValue(null, 'success', 1); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | 111 | * @param array|null $propertyIdSerializations |
| 112 | 112 | * @return NumericPropertyId[] |
| 113 | 113 | */ |
| 114 | - private function parsePropertyIds( ?array $propertyIdSerializations ): array { |
|
| 115 | - if ( $propertyIdSerializations === null ) { |
|
| 114 | + private function parsePropertyIds(?array $propertyIdSerializations): array { |
|
| 115 | + if ($propertyIdSerializations === null) { |
|
| 116 | 116 | return []; |
| 117 | - } elseif ( $propertyIdSerializations === [] ) { |
|
| 117 | + } elseif ($propertyIdSerializations === []) { |
|
| 118 | 118 | $this->apiErrorReporter->dieError( |
| 119 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
| 119 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
| 120 | 120 | 'no-data' |
| 121 | 121 | ); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | return array_map( |
| 125 | - function ( $propertyIdSerialization ) { |
|
| 125 | + function($propertyIdSerialization) { |
|
| 126 | 126 | try { |
| 127 | - return new NumericPropertyId( $propertyIdSerialization ); |
|
| 128 | - } catch ( InvalidArgumentException ) { |
|
| 127 | + return new NumericPropertyId($propertyIdSerialization); |
|
| 128 | + } catch (InvalidArgumentException) { |
|
| 129 | 129 | $this->apiErrorReporter->dieError( |
| 130 | 130 | "Invalid id: $propertyIdSerialization", |
| 131 | 131 | 'invalid-property-id', |
| 132 | 132 | 0, // default argument |
| 133 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
| 133 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
| 134 | 134 | ); |
| 135 | 135 | } |
| 136 | 136 | }, |
@@ -142,35 +142,35 @@ discard block |
||
| 142 | 142 | * @param array|null $constraintIds |
| 143 | 143 | * @return string[] |
| 144 | 144 | */ |
| 145 | - private function parseConstraintIds( ?array $constraintIds ): array { |
|
| 146 | - if ( $constraintIds === null ) { |
|
| 145 | + private function parseConstraintIds(?array $constraintIds): array { |
|
| 146 | + if ($constraintIds === null) { |
|
| 147 | 147 | return []; |
| 148 | - } elseif ( $constraintIds === [] ) { |
|
| 148 | + } elseif ($constraintIds === []) { |
|
| 149 | 149 | $this->apiErrorReporter->dieError( |
| 150 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
| 150 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
| 151 | 151 | 'no-data' |
| 152 | 152 | ); |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | return array_map( |
| 156 | - function ( $constraintId ) { |
|
| 156 | + function($constraintId) { |
|
| 157 | 157 | try { |
| 158 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
| 159 | - if ( !$propertyId instanceof NumericPropertyId ) { |
|
| 158 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
| 159 | + if (!$propertyId instanceof NumericPropertyId) { |
|
| 160 | 160 | $this->apiErrorReporter->dieError( |
| 161 | 161 | "Invalid property ID: {$propertyId->getSerialization()}", |
| 162 | 162 | 'invalid-property-id', |
| 163 | 163 | 0, // default argument |
| 164 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
| 164 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
| 165 | 165 | ); |
| 166 | 166 | } |
| 167 | 167 | return $constraintId; |
| 168 | - } catch ( StatementGuidParsingException ) { |
|
| 168 | + } catch (StatementGuidParsingException) { |
|
| 169 | 169 | $this->apiErrorReporter->dieError( |
| 170 | 170 | "Invalid statement GUID: $constraintId", |
| 171 | 171 | 'invalid-guid', |
| 172 | 172 | 0, // default argument |
| 173 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
| 173 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
| 174 | 174 | ); |
| 175 | 175 | } |
| 176 | 176 | }, |
@@ -182,12 +182,12 @@ discard block |
||
| 182 | 182 | * @param NumericPropertyId[] $propertyIds |
| 183 | 183 | * @param ApiResult $result |
| 184 | 184 | */ |
| 185 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ): void { |
|
| 186 | - foreach ( $propertyIds as $propertyId ) { |
|
| 187 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
| 185 | + private function checkPropertyIds(array $propertyIds, ApiResult $result): void { |
|
| 186 | + foreach ($propertyIds as $propertyId) { |
|
| 187 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
| 188 | 188 | $allConstraintExceptions = $this->delegatingConstraintChecker |
| 189 | - ->checkConstraintParametersOnPropertyId( $propertyId ); |
|
| 190 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
| 189 | + ->checkConstraintParametersOnPropertyId($propertyId); |
|
| 190 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
| 191 | 191 | $this->addConstraintParameterExceptionsToResult( |
| 192 | 192 | $constraintId, |
| 193 | 193 | $constraintParameterExceptions, |
@@ -201,15 +201,15 @@ discard block |
||
| 201 | 201 | * @param string[] $constraintIds |
| 202 | 202 | * @param ApiResult $result |
| 203 | 203 | */ |
| 204 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ): void { |
|
| 205 | - foreach ( $constraintIds as $constraintId ) { |
|
| 206 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
| 204 | + private function checkConstraintIds(array $constraintIds, ApiResult $result): void { |
|
| 205 | + foreach ($constraintIds as $constraintId) { |
|
| 206 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
| 207 | 207 | // already checked as part of checkPropertyIds() |
| 208 | 208 | continue; |
| 209 | 209 | } |
| 210 | 210 | $constraintParameterExceptions = $this->delegatingConstraintChecker |
| 211 | - ->checkConstraintParametersOnConstraintId( $constraintId ); |
|
| 212 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
| 211 | + ->checkConstraintParametersOnConstraintId($constraintId); |
|
| 212 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
@@ -217,18 +217,18 @@ discard block |
||
| 217 | 217 | * @param NumericPropertyId $propertyId |
| 218 | 218 | * @return string[] |
| 219 | 219 | */ |
| 220 | - private function getResultPathForPropertyId( NumericPropertyId $propertyId ): array { |
|
| 221 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
| 220 | + private function getResultPathForPropertyId(NumericPropertyId $propertyId): array { |
|
| 221 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
| 225 | 225 | * @param string $constraintId |
| 226 | 226 | * @return string[] |
| 227 | 227 | */ |
| 228 | - private function getResultPathForConstraintId( string $constraintId ): array { |
|
| 229 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
| 228 | + private function getResultPathForConstraintId(string $constraintId): array { |
|
| 229 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
| 230 | 230 | '@phan-var NumericPropertyId $propertyId'; |
| 231 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
| 231 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
@@ -243,8 +243,8 @@ discard block |
||
| 243 | 243 | ?array $constraintParameterExceptions, |
| 244 | 244 | ApiResult $result |
| 245 | 245 | ): void { |
| 246 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
| 247 | - if ( $constraintParameterExceptions === null ) { |
|
| 246 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
| 247 | + if ($constraintParameterExceptions === null) { |
|
| 248 | 248 | $result->addValue( |
| 249 | 249 | $path, |
| 250 | 250 | self::KEY_STATUS, |
@@ -261,11 +261,11 @@ discard block |
||
| 261 | 261 | $violationMessageRenderer = $this->violationMessageRendererFactory |
| 262 | 262 | ->getViolationMessageRenderer( |
| 263 | 263 | $language, |
| 264 | - $this->languageFallbackChainFactory->newFromLanguage( $language ), |
|
| 264 | + $this->languageFallbackChainFactory->newFromLanguage($language), |
|
| 265 | 265 | $this |
| 266 | 266 | ); |
| 267 | 267 | $problems = []; |
| 268 | - foreach ( $constraintParameterExceptions as $constraintParameterException ) { |
|
| 268 | + foreach ($constraintParameterExceptions as $constraintParameterException) { |
|
| 269 | 269 | $problems[] = [ |
| 270 | 270 | self::KEY_MESSAGE_HTML => $violationMessageRenderer->render( |
| 271 | 271 | $constraintParameterException->getViolationMessage() ), |
@@ -304,8 +304,8 @@ discard block |
||
| 304 | 304 | return [ |
| 305 | 305 | 'action=wbcheckconstraintparameters&propertyid=P247' |
| 306 | 306 | => 'apihelp-wbcheckconstraintparameters-example-propertyid-1', |
| 307 | - 'action=wbcheckconstraintparameters&' . |
|
| 308 | - 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' . |
|
| 307 | + 'action=wbcheckconstraintparameters&'. |
|
| 308 | + 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'. |
|
| 309 | 309 | 'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f' |
| 310 | 310 | => 'apihelp-wbcheckconstraintparameters-example-constraintid-2', |
| 311 | 311 | ]; |