@@ -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\Helper; |
| 6 | 6 | |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | * Check if any errors are recorded in the constraint parameters. |
| 69 | 69 | * @throws ConstraintParameterException |
| 70 | 70 | */ |
| 71 | - public function checkError( array $parameters ): void { |
|
| 72 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
| 71 | + public function checkError(array $parameters): void { |
|
| 72 | + if (array_key_exists('@error', $parameters)) { |
|
| 73 | 73 | $error = $parameters['@error']; |
| 74 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
| 74 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
| 75 | 75 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
| 76 | 76 | } else { |
| 77 | 77 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
| 78 | 78 | } |
| 79 | - throw new ConstraintParameterException( new ViolationMessage( $msg ) ); |
|
| 79 | + throw new ConstraintParameterException(new ViolationMessage($msg)); |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | * Require that $parameters contains exactly one $parameterId parameter. |
| 85 | 85 | * @throws ConstraintParameterException |
| 86 | 86 | */ |
| 87 | - private function requireSingleParameter( array $parameters, string $parameterId ): void { |
|
| 88 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
| 87 | + private function requireSingleParameter(array $parameters, string $parameterId): void { |
|
| 88 | + if (count($parameters[$parameterId]) !== 1) { |
|
| 89 | 89 | throw new ConstraintParameterException( |
| 90 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) ) |
|
| 91 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 90 | + (new ViolationMessage('wbqc-violation-message-parameter-single')) |
|
| 91 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 92 | 92 | ); |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -97,11 +97,11 @@ discard block |
||
| 97 | 97 | * Require that $snak is a {@link PropertyValueSnak}. |
| 98 | 98 | * @throws ConstraintParameterException |
| 99 | 99 | */ |
| 100 | - private function requireValueParameter( Snak $snak, string $parameterId ): void { |
|
| 101 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
| 100 | + private function requireValueParameter(Snak $snak, string $parameterId): void { |
|
| 101 | + if (!($snak instanceof PropertyValueSnak)) { |
|
| 102 | 102 | throw new ConstraintParameterException( |
| 103 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
| 104 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 103 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
| 104 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 105 | 105 | ); |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -110,17 +110,17 @@ discard block |
||
| 110 | 110 | * Parse a single entity ID parameter. |
| 111 | 111 | * @throws ConstraintParameterException |
| 112 | 112 | */ |
| 113 | - private function parseEntityIdParameter( array $snakSerialization, string $parameterId ): EntityId { |
|
| 114 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
| 115 | - $this->requireValueParameter( $snak, $parameterId ); |
|
| 113 | + private function parseEntityIdParameter(array $snakSerialization, string $parameterId): EntityId { |
|
| 114 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
| 115 | + $this->requireValueParameter($snak, $parameterId); |
|
| 116 | 116 | $value = $snak->getDataValue(); |
| 117 | - if ( $value instanceof EntityIdValue ) { |
|
| 117 | + if ($value instanceof EntityIdValue) { |
|
| 118 | 118 | return $value->getEntityId(); |
| 119 | 119 | } else { |
| 120 | 120 | throw new ConstraintParameterException( |
| 121 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) ) |
|
| 122 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 123 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 121 | + (new ViolationMessage('wbqc-violation-message-parameter-entity')) |
|
| 122 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 123 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 124 | 124 | ); |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -131,20 +131,20 @@ discard block |
||
| 131 | 131 | * @throws ConstraintParameterException if the parameter is invalid or missing |
| 132 | 132 | * @return string[] class entity ID serializations |
| 133 | 133 | */ |
| 134 | - public function parseClassParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
| 135 | - $this->checkError( $constraintParameters ); |
|
| 136 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
| 137 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
| 134 | + public function parseClassParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
| 135 | + $this->checkError($constraintParameters); |
|
| 136 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
| 137 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
| 138 | 138 | throw new ConstraintParameterException( |
| 139 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
| 140 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 141 | - ->withEntityId( new NumericPropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 139 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
| 140 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 141 | + ->withEntityId(new NumericPropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 142 | 142 | ); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $classes = []; |
| 146 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
| 147 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
| 146 | + foreach ($constraintParameters[$classId] as $class) { |
|
| 147 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
| 148 | 148 | } |
| 149 | 149 | return $classes; |
| 150 | 150 | } |
@@ -155,31 +155,31 @@ discard block |
||
| 155 | 155 | * @throws ConstraintParameterException if the parameter is invalid or missing |
| 156 | 156 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
| 157 | 157 | */ |
| 158 | - public function parseRelationParameter( array $constraintParameters, string $constraintTypeItemId ): string { |
|
| 159 | - $this->checkError( $constraintParameters ); |
|
| 160 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
| 161 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
| 158 | + public function parseRelationParameter(array $constraintParameters, string $constraintTypeItemId): string { |
|
| 159 | + $this->checkError($constraintParameters); |
|
| 160 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
| 161 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
| 162 | 162 | throw new ConstraintParameterException( |
| 163 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
| 164 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 165 | - ->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 163 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
| 164 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 165 | + ->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 166 | 166 | ); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
| 170 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
| 171 | - if ( !( $relationEntityId instanceof ItemId ) ) { |
|
| 169 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
| 170 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
| 171 | + if (!($relationEntityId instanceof ItemId)) { |
|
| 172 | 172 | throw new ConstraintParameterException( |
| 173 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
| 174 | - ->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 175 | - ->withDataValue( new EntityIdValue( $relationEntityId ), Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 173 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
| 174 | + ->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 175 | + ->withDataValue(new EntityIdValue($relationEntityId), Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 176 | 176 | ); |
| 177 | 177 | } |
| 178 | - return $this->mapItemId( $relationEntityId, [ |
|
| 179 | - $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ) => 'instance', |
|
| 180 | - $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ) => 'subclass', |
|
| 181 | - $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ) => 'instanceOrSubclass', |
|
| 182 | - ], $relationId ); |
|
| 178 | + return $this->mapItemId($relationEntityId, [ |
|
| 179 | + $this->config->get('WBQualityConstraintsInstanceOfRelationId') => 'instance', |
|
| 180 | + $this->config->get('WBQualityConstraintsSubclassOfRelationId') => 'subclass', |
|
| 181 | + $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId') => 'instanceOrSubclass', |
|
| 182 | + ], $relationId); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -189,20 +189,20 @@ discard block |
||
| 189 | 189 | * @throws ConstraintParameterException |
| 190 | 190 | * @return PropertyId |
| 191 | 191 | */ |
| 192 | - private function parsePropertyIdParameter( array $snakSerialization, string $parameterId ): PropertyId { |
|
| 193 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
| 194 | - $this->requireValueParameter( $snak, $parameterId ); |
|
| 192 | + private function parsePropertyIdParameter(array $snakSerialization, string $parameterId): PropertyId { |
|
| 193 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
| 194 | + $this->requireValueParameter($snak, $parameterId); |
|
| 195 | 195 | $value = $snak->getDataValue(); |
| 196 | - if ( $value instanceof EntityIdValue ) { |
|
| 196 | + if ($value instanceof EntityIdValue) { |
|
| 197 | 197 | $id = $value->getEntityId(); |
| 198 | - if ( $id instanceof PropertyId ) { |
|
| 198 | + if ($id instanceof PropertyId) { |
|
| 199 | 199 | return $id; |
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | throw new ConstraintParameterException( |
| 203 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) ) |
|
| 204 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 205 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 203 | + (new ViolationMessage('wbqc-violation-message-parameter-property')) |
|
| 204 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 205 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 206 | 206 | ); |
| 207 | 207 | } |
| 208 | 208 | |
@@ -213,33 +213,33 @@ discard block |
||
| 213 | 213 | * @throws ConstraintParameterException if the parameter is invalid or missing |
| 214 | 214 | * @return PropertyId |
| 215 | 215 | */ |
| 216 | - public function parsePropertyParameter( array $constraintParameters, string $constraintTypeItemId ): PropertyId { |
|
| 217 | - $this->checkError( $constraintParameters ); |
|
| 218 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
| 219 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
| 216 | + public function parsePropertyParameter(array $constraintParameters, string $constraintTypeItemId): PropertyId { |
|
| 217 | + $this->checkError($constraintParameters); |
|
| 218 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
| 219 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
| 220 | 220 | throw new ConstraintParameterException( |
| 221 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
| 222 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 223 | - ->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 221 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
| 222 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 223 | + ->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 224 | 224 | ); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
| 228 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
| 227 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
| 228 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - private function parseItemIdParameter( PropertyValueSnak $snak, string $parameterId ): ItemIdSnakValue { |
|
| 231 | + private function parseItemIdParameter(PropertyValueSnak $snak, string $parameterId): ItemIdSnakValue { |
|
| 232 | 232 | $dataValue = $snak->getDataValue(); |
| 233 | - if ( $dataValue instanceof EntityIdValue ) { |
|
| 233 | + if ($dataValue instanceof EntityIdValue) { |
|
| 234 | 234 | $entityId = $dataValue->getEntityId(); |
| 235 | - if ( $entityId instanceof ItemId ) { |
|
| 236 | - return ItemIdSnakValue::fromItemId( $entityId ); |
|
| 235 | + if ($entityId instanceof ItemId) { |
|
| 236 | + return ItemIdSnakValue::fromItemId($entityId); |
|
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | throw new ConstraintParameterException( |
| 240 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
| 241 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 242 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 240 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
| 241 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 242 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 243 | 243 | ); |
| 244 | 244 | } |
| 245 | 245 | |
@@ -257,16 +257,16 @@ discard block |
||
| 257 | 257 | bool $required, |
| 258 | 258 | string $parameterId = null |
| 259 | 259 | ): array { |
| 260 | - $this->checkError( $constraintParameters ); |
|
| 261 | - if ( $parameterId === null ) { |
|
| 262 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
| 260 | + $this->checkError($constraintParameters); |
|
| 261 | + if ($parameterId === null) { |
|
| 262 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
| 263 | 263 | } |
| 264 | - if ( !array_key_exists( $parameterId, $constraintParameters ) ) { |
|
| 265 | - if ( $required ) { |
|
| 264 | + if (!array_key_exists($parameterId, $constraintParameters)) { |
|
| 265 | + if ($required) { |
|
| 266 | 266 | throw new ConstraintParameterException( |
| 267 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
| 268 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 269 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 267 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
| 268 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 269 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 270 | 270 | ); |
| 271 | 271 | } else { |
| 272 | 272 | return []; |
@@ -274,11 +274,11 @@ discard block |
||
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | $values = []; |
| 277 | - foreach ( $constraintParameters[$parameterId] as $parameter ) { |
|
| 278 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
| 279 | - switch ( true ) { |
|
| 277 | + foreach ($constraintParameters[$parameterId] as $parameter) { |
|
| 278 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
| 279 | + switch (true) { |
|
| 280 | 280 | case $snak instanceof PropertyValueSnak: |
| 281 | - $values[] = $this->parseItemIdParameter( $snak, $parameterId ); |
|
| 281 | + $values[] = $this->parseItemIdParameter($snak, $parameterId); |
|
| 282 | 282 | break; |
| 283 | 283 | case $snak instanceof PropertySomeValueSnak: |
| 284 | 284 | $values[] = ItemIdSnakValue::someValue(); |
@@ -306,13 +306,13 @@ discard block |
||
| 306 | 306 | bool $required, |
| 307 | 307 | string $parameterId |
| 308 | 308 | ): array { |
| 309 | - return array_map( static function ( ItemIdSnakValue $value ) use ( $parameterId ): ItemId { |
|
| 310 | - if ( $value->isValue() ) { |
|
| 309 | + return array_map(static function(ItemIdSnakValue $value) use ($parameterId): ItemId { |
|
| 310 | + if ($value->isValue()) { |
|
| 311 | 311 | return $value->getItemId(); |
| 312 | 312 | } else { |
| 313 | 313 | throw new ConstraintParameterException( |
| 314 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
| 315 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 314 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
| 315 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 316 | 316 | ); |
| 317 | 317 | } |
| 318 | 318 | }, $this->parseItemsParameter( |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | $constraintTypeItemId, |
| 321 | 321 | $required, |
| 322 | 322 | $parameterId |
| 323 | - ) ); |
|
| 323 | + )); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
@@ -328,18 +328,18 @@ discard block |
||
| 328 | 328 | * @throws ConstraintParameterException |
| 329 | 329 | * @return mixed elements of $mapping |
| 330 | 330 | */ |
| 331 | - private function mapItemId( ItemId $itemId, array $mapping, string $parameterId ) { |
|
| 331 | + private function mapItemId(ItemId $itemId, array $mapping, string $parameterId) { |
|
| 332 | 332 | $serialization = $itemId->getSerialization(); |
| 333 | - if ( array_key_exists( $serialization, $mapping ) ) { |
|
| 333 | + if (array_key_exists($serialization, $mapping)) { |
|
| 334 | 334 | return $mapping[$serialization]; |
| 335 | 335 | } else { |
| 336 | - $allowed = array_map( static function ( $id ) { |
|
| 337 | - return new ItemId( $id ); |
|
| 338 | - }, array_keys( $mapping ) ); |
|
| 336 | + $allowed = array_map(static function($id) { |
|
| 337 | + return new ItemId($id); |
|
| 338 | + }, array_keys($mapping)); |
|
| 339 | 339 | throw new ConstraintParameterException( |
| 340 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
| 341 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 342 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 340 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
| 341 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 342 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 343 | 343 | ); |
| 344 | 344 | } |
| 345 | 345 | } |
@@ -350,27 +350,27 @@ discard block |
||
| 350 | 350 | * @throws ConstraintParameterException if the parameter is invalid or missing |
| 351 | 351 | * @return PropertyId[] |
| 352 | 352 | */ |
| 353 | - public function parsePropertiesParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
| 354 | - $this->checkError( $constraintParameters ); |
|
| 355 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
| 356 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
| 353 | + public function parsePropertiesParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
| 354 | + $this->checkError($constraintParameters); |
|
| 355 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
| 356 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
| 357 | 357 | throw new ConstraintParameterException( |
| 358 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
| 359 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 360 | - ->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 358 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
| 359 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 360 | + ->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 361 | 361 | ); |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | $parameters = $constraintParameters[$propertyId]; |
| 365 | - if ( count( $parameters ) === 1 && |
|
| 366 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
| 365 | + if (count($parameters) === 1 && |
|
| 366 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
| 367 | 367 | ) { |
| 368 | 368 | return []; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | $properties = []; |
| 372 | - foreach ( $parameters as $parameter ) { |
|
| 373 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
| 372 | + foreach ($parameters as $parameter) { |
|
| 373 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
| 374 | 374 | } |
| 375 | 375 | return $properties; |
| 376 | 376 | } |
@@ -378,24 +378,24 @@ discard block |
||
| 378 | 378 | /** |
| 379 | 379 | * @throws ConstraintParameterException |
| 380 | 380 | */ |
| 381 | - private function parseValueOrNoValueParameter( array $snakSerialization, string $parameterId ): ?DataValue { |
|
| 382 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
| 383 | - if ( $snak instanceof PropertyValueSnak ) { |
|
| 381 | + private function parseValueOrNoValueParameter(array $snakSerialization, string $parameterId): ?DataValue { |
|
| 382 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
| 383 | + if ($snak instanceof PropertyValueSnak) { |
|
| 384 | 384 | return $snak->getDataValue(); |
| 385 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
| 385 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
| 386 | 386 | return null; |
| 387 | 387 | } else { |
| 388 | 388 | throw new ConstraintParameterException( |
| 389 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
| 390 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 389 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
| 390 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 391 | 391 | ); |
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, string $parameterId ): ?DataValue { |
|
| 395 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, string $parameterId): ?DataValue { |
|
| 396 | 396 | try { |
| 397 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
| 398 | - } catch ( ConstraintParameterException $e ) { |
|
| 397 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
| 398 | + } catch (ConstraintParameterException $e) { |
|
| 399 | 399 | // unknown value means “now” |
| 400 | 400 | return new NowValue(); |
| 401 | 401 | } |
@@ -404,14 +404,14 @@ discard block |
||
| 404 | 404 | /** |
| 405 | 405 | * Checks whether there is exactly one non-null quantity with the given unit. |
| 406 | 406 | */ |
| 407 | - private function exactlyOneQuantityWithUnit( ?DataValue $min, ?DataValue $max, string $unit ): bool { |
|
| 408 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
| 409 | - !( $max instanceof UnboundedQuantityValue ) |
|
| 407 | + private function exactlyOneQuantityWithUnit(?DataValue $min, ?DataValue $max, string $unit): bool { |
|
| 408 | + if (!($min instanceof UnboundedQuantityValue) || |
|
| 409 | + !($max instanceof UnboundedQuantityValue) |
|
| 410 | 410 | ) { |
| 411 | 411 | return false; |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
| 414 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | /** |
@@ -431,42 +431,42 @@ discard block |
||
| 431 | 431 | string $constraintTypeItemId, |
| 432 | 432 | string $type |
| 433 | 433 | ): array { |
| 434 | - $this->checkError( $constraintParameters ); |
|
| 435 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
| 436 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
| 434 | + $this->checkError($constraintParameters); |
|
| 435 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
| 436 | + !array_key_exists($maximumId, $constraintParameters) |
|
| 437 | 437 | ) { |
| 438 | 438 | throw new ConstraintParameterException( |
| 439 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) ) |
|
| 440 | - ->withDataValueType( $type ) |
|
| 441 | - ->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 442 | - ->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 443 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 439 | + (new ViolationMessage('wbqc-violation-message-range-parameters-needed')) |
|
| 440 | + ->withDataValueType($type) |
|
| 441 | + ->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 442 | + ->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 443 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 444 | 444 | ); |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
| 448 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
| 447 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
| 448 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
| 449 | 449 | $parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
| 450 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
| 451 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
| 450 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
| 451 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
| 452 | 452 | |
| 453 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
| 454 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
| 453 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
| 454 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
| 455 | 455 | throw new ConstraintParameterException( |
| 456 | - new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
| 456 | + new ViolationMessage('wbqc-violation-message-range-parameters-one-year') |
|
| 457 | 457 | ); |
| 458 | 458 | } |
| 459 | - if ( ( $min === null && $max === null ) || |
|
| 460 | - ( $min !== null && $max !== null && $min->equals( $max ) ) |
|
| 459 | + if (($min === null && $max === null) || |
|
| 460 | + ($min !== null && $max !== null && $min->equals($max)) |
|
| 461 | 461 | ) { |
| 462 | 462 | throw new ConstraintParameterException( |
| 463 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) ) |
|
| 464 | - ->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 465 | - ->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 463 | + (new ViolationMessage('wbqc-violation-message-range-parameters-same')) |
|
| 464 | + ->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 465 | + ->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 466 | 466 | ); |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | - return [ $min, $max ]; |
|
| 469 | + return [$min, $max]; |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -476,11 +476,11 @@ discard block |
||
| 476 | 476 | * @throws ConstraintParameterException if the parameter is invalid or missing |
| 477 | 477 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
| 478 | 478 | */ |
| 479 | - public function parseQuantityRangeParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
| 479 | + public function parseQuantityRangeParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
| 480 | 480 | return $this->parseRangeParameter( |
| 481 | 481 | $constraintParameters, |
| 482 | - $this->config->get( 'WBQualityConstraintsMinimumQuantityId' ), |
|
| 483 | - $this->config->get( 'WBQualityConstraintsMaximumQuantityId' ), |
|
| 482 | + $this->config->get('WBQualityConstraintsMinimumQuantityId'), |
|
| 483 | + $this->config->get('WBQualityConstraintsMaximumQuantityId'), |
|
| 484 | 484 | $constraintTypeItemId, |
| 485 | 485 | 'quantity' |
| 486 | 486 | ); |
@@ -493,11 +493,11 @@ discard block |
||
| 493 | 493 | * @throws ConstraintParameterException if the parameter is invalid or missing |
| 494 | 494 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
| 495 | 495 | */ |
| 496 | - public function parseTimeRangeParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
| 496 | + public function parseTimeRangeParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
| 497 | 497 | return $this->parseRangeParameter( |
| 498 | 498 | $constraintParameters, |
| 499 | - $this->config->get( 'WBQualityConstraintsMinimumDateId' ), |
|
| 500 | - $this->config->get( 'WBQualityConstraintsMaximumDateId' ), |
|
| 499 | + $this->config->get('WBQualityConstraintsMinimumDateId'), |
|
| 500 | + $this->config->get('WBQualityConstraintsMaximumDateId'), |
|
| 501 | 501 | $constraintTypeItemId, |
| 502 | 502 | 'time' |
| 503 | 503 | ); |
@@ -510,20 +510,20 @@ discard block |
||
| 510 | 510 | * @throws ConstraintParameterException |
| 511 | 511 | * @return string[] |
| 512 | 512 | */ |
| 513 | - public function parseLanguageParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
| 514 | - $this->checkError( $constraintParameters ); |
|
| 515 | - $languagePropertyId = $this->config->get( 'WBQualityConstraintsLanguagePropertyId' ); |
|
| 516 | - if ( !array_key_exists( $languagePropertyId, $constraintParameters ) ) { |
|
| 513 | + public function parseLanguageParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
| 514 | + $this->checkError($constraintParameters); |
|
| 515 | + $languagePropertyId = $this->config->get('WBQualityConstraintsLanguagePropertyId'); |
|
| 516 | + if (!array_key_exists($languagePropertyId, $constraintParameters)) { |
|
| 517 | 517 | throw new ConstraintParameterException( |
| 518 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
| 519 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 520 | - ->withEntityId( new NumericPropertyId( $languagePropertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 518 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
| 519 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 520 | + ->withEntityId(new NumericPropertyId($languagePropertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 521 | 521 | ); |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | $languages = []; |
| 525 | - foreach ( $constraintParameters[$languagePropertyId] as $snak ) { |
|
| 526 | - $languages[] = $this->parseStringParameter( $snak, $languagePropertyId ); |
|
| 525 | + foreach ($constraintParameters[$languagePropertyId] as $snak) { |
|
| 526 | + $languages[] = $this->parseStringParameter($snak, $languagePropertyId); |
|
| 527 | 527 | } |
| 528 | 528 | return $languages; |
| 529 | 529 | } |
@@ -532,17 +532,17 @@ discard block |
||
| 532 | 532 | * Parse a single string parameter. |
| 533 | 533 | * @throws ConstraintParameterException |
| 534 | 534 | */ |
| 535 | - private function parseStringParameter( array $snakSerialization, string $parameterId ): string { |
|
| 536 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
| 537 | - $this->requireValueParameter( $snak, $parameterId ); |
|
| 535 | + private function parseStringParameter(array $snakSerialization, string $parameterId): string { |
|
| 536 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
| 537 | + $this->requireValueParameter($snak, $parameterId); |
|
| 538 | 538 | $value = $snak->getDataValue(); |
| 539 | - if ( $value instanceof StringValue ) { |
|
| 539 | + if ($value instanceof StringValue) { |
|
| 540 | 540 | return $value->getValue(); |
| 541 | 541 | } else { |
| 542 | 542 | throw new ConstraintParameterException( |
| 543 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) ) |
|
| 544 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 545 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 543 | + (new ViolationMessage('wbqc-violation-message-parameter-string')) |
|
| 544 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 545 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 546 | 546 | ); |
| 547 | 547 | } |
| 548 | 548 | } |
@@ -553,15 +553,15 @@ discard block |
||
| 553 | 553 | * @throws ConstraintParameterException if the parameter is invalid or missing |
| 554 | 554 | * @return string |
| 555 | 555 | */ |
| 556 | - public function parseNamespaceParameter( array $constraintParameters, string $constraintTypeItemId ): string { |
|
| 557 | - $this->checkError( $constraintParameters ); |
|
| 558 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
| 559 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
| 556 | + public function parseNamespaceParameter(array $constraintParameters, string $constraintTypeItemId): string { |
|
| 557 | + $this->checkError($constraintParameters); |
|
| 558 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
| 559 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
| 560 | 560 | return ''; |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
| 564 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
| 563 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
| 564 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | /** |
@@ -570,19 +570,19 @@ discard block |
||
| 570 | 570 | * @throws ConstraintParameterException if the parameter is invalid or missing |
| 571 | 571 | * @return string |
| 572 | 572 | */ |
| 573 | - public function parseFormatParameter( array $constraintParameters, string $constraintTypeItemId ): string { |
|
| 574 | - $this->checkError( $constraintParameters ); |
|
| 575 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
| 576 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
| 573 | + public function parseFormatParameter(array $constraintParameters, string $constraintTypeItemId): string { |
|
| 574 | + $this->checkError($constraintParameters); |
|
| 575 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
| 576 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
| 577 | 577 | throw new ConstraintParameterException( |
| 578 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
| 579 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 580 | - ->withEntityId( new NumericPropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 578 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
| 579 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 580 | + ->withEntityId(new NumericPropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 581 | 581 | ); |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
| 585 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
| 584 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
| 585 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | /** |
@@ -590,16 +590,16 @@ discard block |
||
| 590 | 590 | * @throws ConstraintParameterException if the parameter is invalid |
| 591 | 591 | * @return EntityId[] |
| 592 | 592 | */ |
| 593 | - public function parseExceptionParameter( array $constraintParameters ): array { |
|
| 594 | - $this->checkError( $constraintParameters ); |
|
| 595 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
| 596 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
| 593 | + public function parseExceptionParameter(array $constraintParameters): array { |
|
| 594 | + $this->checkError($constraintParameters); |
|
| 595 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
| 596 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
| 597 | 597 | return []; |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | return array_map( |
| 601 | - function ( $snakSerialization ) use ( $exceptionId ) { |
|
| 602 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
| 601 | + function($snakSerialization) use ($exceptionId) { |
|
| 602 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
| 603 | 603 | }, |
| 604 | 604 | $constraintParameters[$exceptionId] |
| 605 | 605 | ); |
@@ -610,39 +610,39 @@ discard block |
||
| 610 | 610 | * @throws ConstraintParameterException if the parameter is invalid |
| 611 | 611 | * @return string|null 'mandatory', 'suggestion' or null |
| 612 | 612 | */ |
| 613 | - public function parseConstraintStatusParameter( array $constraintParameters ): ?string { |
|
| 614 | - $this->checkError( $constraintParameters ); |
|
| 615 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
| 616 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
| 613 | + public function parseConstraintStatusParameter(array $constraintParameters): ?string { |
|
| 614 | + $this->checkError($constraintParameters); |
|
| 615 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
| 616 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
| 617 | 617 | return null; |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
| 621 | - $supportedStatuses = [ new ItemId( $mandatoryId ) ]; |
|
| 622 | - if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) { |
|
| 623 | - $suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' ); |
|
| 624 | - $supportedStatuses[] = new ItemId( $suggestionId ); |
|
| 620 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
| 621 | + $supportedStatuses = [new ItemId($mandatoryId)]; |
|
| 622 | + if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) { |
|
| 623 | + $suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId'); |
|
| 624 | + $supportedStatuses[] = new ItemId($suggestionId); |
|
| 625 | 625 | } else { |
| 626 | 626 | $suggestionId = null; |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
| 630 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
| 631 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
| 629 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
| 630 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
| 631 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
| 632 | 632 | '@phan-var \Wikibase\DataModel\Snak\PropertyValueSnak $snak'; |
| 633 | 633 | $dataValue = $snak->getDataValue(); |
| 634 | 634 | '@phan-var EntityIdValue $dataValue'; |
| 635 | 635 | $entityId = $dataValue->getEntityId(); |
| 636 | 636 | $statusId = $entityId->getSerialization(); |
| 637 | 637 | |
| 638 | - if ( $statusId === $mandatoryId ) { |
|
| 638 | + if ($statusId === $mandatoryId) { |
|
| 639 | 639 | return 'mandatory'; |
| 640 | - } elseif ( $statusId === $suggestionId ) { |
|
| 640 | + } elseif ($statusId === $suggestionId) { |
|
| 641 | 641 | return 'suggestion'; |
| 642 | 642 | } else { |
| 643 | 643 | throw new ConstraintParameterException( |
| 644 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
| 645 | - ->withEntityId( new NumericPropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 644 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
| 645 | + ->withEntityId(new NumericPropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 646 | 646 | ->withEntityIdList( |
| 647 | 647 | $supportedStatuses, |
| 648 | 648 | Role::CONSTRAINT_PARAMETER_VALUE |
@@ -655,12 +655,12 @@ discard block |
||
| 655 | 655 | * Require that $dataValue is a {@link MonolingualTextValue}. |
| 656 | 656 | * @throws ConstraintParameterException |
| 657 | 657 | */ |
| 658 | - private function requireMonolingualTextParameter( DataValue $dataValue, string $parameterId ): void { |
|
| 659 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
| 658 | + private function requireMonolingualTextParameter(DataValue $dataValue, string $parameterId): void { |
|
| 659 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
| 660 | 660 | throw new ConstraintParameterException( |
| 661 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) ) |
|
| 662 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 663 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 661 | + (new ViolationMessage('wbqc-violation-message-parameter-monolingualtext')) |
|
| 662 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 663 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 664 | 664 | ); |
| 665 | 665 | } |
| 666 | 666 | } |
@@ -670,31 +670,31 @@ discard block |
||
| 670 | 670 | * |
| 671 | 671 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
| 672 | 672 | */ |
| 673 | - private function parseMultilingualTextParameter( array $snakSerializations, string $parameterId ): MultilingualTextValue { |
|
| 673 | + private function parseMultilingualTextParameter(array $snakSerializations, string $parameterId): MultilingualTextValue { |
|
| 674 | 674 | $result = []; |
| 675 | 675 | |
| 676 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
| 677 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
| 678 | - $this->requireValueParameter( $snak, $parameterId ); |
|
| 676 | + foreach ($snakSerializations as $snakSerialization) { |
|
| 677 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
| 678 | + $this->requireValueParameter($snak, $parameterId); |
|
| 679 | 679 | |
| 680 | 680 | $value = $snak->getDataValue(); |
| 681 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
| 681 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
| 682 | 682 | /** @var MonolingualTextValue $value */ |
| 683 | 683 | '@phan-var MonolingualTextValue $value'; |
| 684 | 684 | |
| 685 | 685 | $code = $value->getLanguageCode(); |
| 686 | - if ( array_key_exists( $code, $result ) ) { |
|
| 686 | + if (array_key_exists($code, $result)) { |
|
| 687 | 687 | throw new ConstraintParameterException( |
| 688 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) ) |
|
| 689 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 690 | - ->withLanguage( $code ) |
|
| 688 | + (new ViolationMessage('wbqc-violation-message-parameter-single-per-language')) |
|
| 689 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 690 | + ->withLanguage($code) |
|
| 691 | 691 | ); |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | $result[$code] = $value; |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | - return new MultilingualTextValue( $result ); |
|
| 697 | + return new MultilingualTextValue($result); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | /** |
@@ -702,11 +702,11 @@ discard block |
||
| 702 | 702 | * @throws ConstraintParameterException if the parameter is invalid |
| 703 | 703 | * @return MultilingualTextValue |
| 704 | 704 | */ |
| 705 | - public function parseSyntaxClarificationParameter( array $constraintParameters ): MultilingualTextValue { |
|
| 706 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
| 705 | + public function parseSyntaxClarificationParameter(array $constraintParameters): MultilingualTextValue { |
|
| 706 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
| 707 | 707 | |
| 708 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
| 709 | - return new MultilingualTextValue( [] ); |
|
| 708 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
| 709 | + return new MultilingualTextValue([]); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -722,11 +722,11 @@ discard block |
||
| 722 | 722 | * @throws ConstraintParameterException if the parameter is invalid |
| 723 | 723 | * @return MultilingualTextValue |
| 724 | 724 | */ |
| 725 | - public function parseConstraintClarificationParameter( array $constraintParameters ): MultilingualTextValue { |
|
| 726 | - $constraintClarificationId = $this->config->get( 'WBQualityConstraintsConstraintClarificationId' ); |
|
| 725 | + public function parseConstraintClarificationParameter(array $constraintParameters): MultilingualTextValue { |
|
| 726 | + $constraintClarificationId = $this->config->get('WBQualityConstraintsConstraintClarificationId'); |
|
| 727 | 727 | |
| 728 | - if ( !array_key_exists( $constraintClarificationId, $constraintParameters ) ) { |
|
| 729 | - return new MultilingualTextValue( [] ); |
|
| 728 | + if (!array_key_exists($constraintClarificationId, $constraintParameters)) { |
|
| 729 | + return new MultilingualTextValue([]); |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | $constraintClarifications = $this->parseMultilingualTextParameter( |
@@ -759,14 +759,14 @@ discard block |
||
| 759 | 759 | array $validContextTypes, |
| 760 | 760 | array $validEntityTypes |
| 761 | 761 | ): array { |
| 762 | - $contextTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
| 762 | + $contextTypeParameterId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
| 763 | 763 | $contextTypeItemIds = $this->parseItemIdsParameter( |
| 764 | 764 | $constraintParameters, |
| 765 | 765 | $constraintTypeItemId, |
| 766 | 766 | false, |
| 767 | 767 | $contextTypeParameterId |
| 768 | 768 | ); |
| 769 | - $entityTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintEntityTypesId' ); |
|
| 769 | + $entityTypeParameterId = $this->config->get('WBQualityConstraintsConstraintEntityTypesId'); |
|
| 770 | 770 | $entityTypeItemIds = $this->parseItemIdsParameter( |
| 771 | 771 | $constraintParameters, |
| 772 | 772 | $constraintTypeItemId, |
@@ -782,26 +782,26 @@ discard block |
||
| 782 | 782 | $contextTypes = null; |
| 783 | 783 | $entityTypes = null; |
| 784 | 784 | |
| 785 | - if ( $contextTypeParameterId === $entityTypeParameterId ) { |
|
| 785 | + if ($contextTypeParameterId === $entityTypeParameterId) { |
|
| 786 | 786 | $itemIds = $contextTypeItemIds; |
| 787 | 787 | $mapping = $contextTypeMapping + $entityTypeMapping; |
| 788 | - foreach ( $itemIds as $itemId ) { |
|
| 789 | - $mapped = $this->mapItemId( $itemId, $mapping, $contextTypeParameterId ); |
|
| 790 | - if ( in_array( $mapped, $contextTypeMapping, true ) ) { |
|
| 788 | + foreach ($itemIds as $itemId) { |
|
| 789 | + $mapped = $this->mapItemId($itemId, $mapping, $contextTypeParameterId); |
|
| 790 | + if (in_array($mapped, $contextTypeMapping, true)) { |
|
| 791 | 791 | $contextTypes[] = $mapped; |
| 792 | 792 | } else { |
| 793 | 793 | $entityTypes[] = $mapped; |
| 794 | 794 | } |
| 795 | 795 | } |
| 796 | 796 | } else { |
| 797 | - foreach ( $contextTypeItemIds as $contextTypeItemId ) { |
|
| 797 | + foreach ($contextTypeItemIds as $contextTypeItemId) { |
|
| 798 | 798 | $contextTypes[] = $this->mapItemId( |
| 799 | 799 | $contextTypeItemId, |
| 800 | 800 | $contextTypeMapping, |
| 801 | 801 | $contextTypeParameterId |
| 802 | 802 | ); |
| 803 | 803 | } |
| 804 | - foreach ( $entityTypeItemIds as $entityTypeItemId ) { |
|
| 804 | + foreach ($entityTypeItemIds as $entityTypeItemId) { |
|
| 805 | 805 | $entityTypes[] = $this->mapItemId( |
| 806 | 806 | $entityTypeItemId, |
| 807 | 807 | $entityTypeMapping, |
@@ -810,21 +810,21 @@ discard block |
||
| 810 | 810 | } |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | - $this->checkValidScope( $constraintTypeItemId, $contextTypes, $validContextTypes ); |
|
| 814 | - $this->checkValidScope( $constraintTypeItemId, $entityTypes, $validEntityTypes ); |
|
| 813 | + $this->checkValidScope($constraintTypeItemId, $contextTypes, $validContextTypes); |
|
| 814 | + $this->checkValidScope($constraintTypeItemId, $entityTypes, $validEntityTypes); |
|
| 815 | 815 | |
| 816 | - return [ $contextTypes, $entityTypes ]; |
|
| 816 | + return [$contextTypes, $entityTypes]; |
|
| 817 | 817 | } |
| 818 | 818 | |
| 819 | - private function checkValidScope( string $constraintTypeItemId, ?array $types, array $validTypes ): void { |
|
| 820 | - $invalidTypes = array_diff( $types ?: [], $validTypes ); |
|
| 821 | - if ( $invalidTypes !== [] ) { |
|
| 822 | - $invalidType = array_pop( $invalidTypes ); |
|
| 819 | + private function checkValidScope(string $constraintTypeItemId, ?array $types, array $validTypes): void { |
|
| 820 | + $invalidTypes = array_diff($types ?: [], $validTypes); |
|
| 821 | + if ($invalidTypes !== []) { |
|
| 822 | + $invalidType = array_pop($invalidTypes); |
|
| 823 | 823 | throw new ConstraintParameterException( |
| 824 | - ( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) ) |
|
| 825 | - ->withConstraintScope( $invalidType, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 826 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 827 | - ->withConstraintScopeList( $validTypes, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 824 | + (new ViolationMessage('wbqc-violation-message-invalid-scope')) |
|
| 825 | + ->withConstraintScope($invalidType, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 826 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 827 | + ->withConstraintScopeList($validTypes, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 828 | 828 | ); |
| 829 | 829 | } |
| 830 | 830 | } |
@@ -832,8 +832,8 @@ discard block |
||
| 832 | 832 | /** |
| 833 | 833 | * Turn an item ID into a full unit string (using the concept URI). |
| 834 | 834 | */ |
| 835 | - private function parseUnitParameter( ItemId $unitId ): string { |
|
| 836 | - return $this->unitItemConceptBaseUri . $unitId->getSerialization(); |
|
| 835 | + private function parseUnitParameter(ItemId $unitId): string { |
|
| 836 | + return $this->unitItemConceptBaseUri.$unitId->getSerialization(); |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | /** |
@@ -841,23 +841,23 @@ discard block |
||
| 841 | 841 | * |
| 842 | 842 | * @throws ConstraintParameterException |
| 843 | 843 | */ |
| 844 | - private function parseUnitItem( ItemIdSnakValue $item ): UnitsParameter { |
|
| 845 | - switch ( true ) { |
|
| 844 | + private function parseUnitItem(ItemIdSnakValue $item): UnitsParameter { |
|
| 845 | + switch (true) { |
|
| 846 | 846 | case $item->isValue(): |
| 847 | - $unit = $this->parseUnitParameter( $item->getItemId() ); |
|
| 847 | + $unit = $this->parseUnitParameter($item->getItemId()); |
|
| 848 | 848 | return new UnitsParameter( |
| 849 | - [ $item->getItemId() ], |
|
| 850 | - [ UnboundedQuantityValue::newFromNumber( 1, $unit ) ], |
|
| 849 | + [$item->getItemId()], |
|
| 850 | + [UnboundedQuantityValue::newFromNumber(1, $unit)], |
|
| 851 | 851 | false |
| 852 | 852 | ); |
| 853 | 853 | case $item->isSomeValue(): |
| 854 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
| 854 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
| 855 | 855 | throw new ConstraintParameterException( |
| 856 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
| 857 | - ->withEntityId( new NumericPropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
| 856 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
| 857 | + ->withEntityId(new NumericPropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
| 858 | 858 | ); |
| 859 | 859 | case $item->isNoValue(): |
| 860 | - return new UnitsParameter( [], [], true ); |
|
| 860 | + return new UnitsParameter([], [], true); |
|
| 861 | 861 | } |
| 862 | 862 | } |
| 863 | 863 | |
@@ -867,36 +867,36 @@ discard block |
||
| 867 | 867 | * @throws ConstraintParameterException if the parameter is invalid or missing |
| 868 | 868 | * @return UnitsParameter |
| 869 | 869 | */ |
| 870 | - public function parseUnitsParameter( array $constraintParameters, string $constraintTypeItemId ): UnitsParameter { |
|
| 871 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
| 870 | + public function parseUnitsParameter(array $constraintParameters, string $constraintTypeItemId): UnitsParameter { |
|
| 871 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
| 872 | 872 | $unitItems = []; |
| 873 | 873 | $unitQuantities = []; |
| 874 | 874 | $unitlessAllowed = false; |
| 875 | 875 | |
| 876 | - foreach ( $items as $item ) { |
|
| 877 | - $unit = $this->parseUnitItem( $item ); |
|
| 878 | - $unitItems = array_merge( $unitItems, $unit->getUnitItemIds() ); |
|
| 879 | - $unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() ); |
|
| 876 | + foreach ($items as $item) { |
|
| 877 | + $unit = $this->parseUnitItem($item); |
|
| 878 | + $unitItems = array_merge($unitItems, $unit->getUnitItemIds()); |
|
| 879 | + $unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities()); |
|
| 880 | 880 | $unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed(); |
| 881 | 881 | } |
| 882 | 882 | |
| 883 | - if ( $unitQuantities === [] && !$unitlessAllowed ) { |
|
| 883 | + if ($unitQuantities === [] && !$unitlessAllowed) { |
|
| 884 | 884 | throw new LogicException( |
| 885 | 885 | 'The "units" parameter is required, and yet we seem to be missing any allowed unit' |
| 886 | 886 | ); |
| 887 | 887 | } |
| 888 | 888 | |
| 889 | - return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed ); |
|
| 889 | + return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed); |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | private function getEntityTypeMapping(): array { |
| 893 | 893 | return [ |
| 894 | - $this->config->get( 'WBQualityConstraintsWikibaseItemId' ) => 'item', |
|
| 895 | - $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) => 'property', |
|
| 896 | - $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) => 'lexeme', |
|
| 897 | - $this->config->get( 'WBQualityConstraintsWikibaseFormId' ) => 'form', |
|
| 898 | - $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) => 'sense', |
|
| 899 | - $this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ) => 'mediainfo', |
|
| 894 | + $this->config->get('WBQualityConstraintsWikibaseItemId') => 'item', |
|
| 895 | + $this->config->get('WBQualityConstraintsWikibasePropertyId') => 'property', |
|
| 896 | + $this->config->get('WBQualityConstraintsWikibaseLexemeId') => 'lexeme', |
|
| 897 | + $this->config->get('WBQualityConstraintsWikibaseFormId') => 'form', |
|
| 898 | + $this->config->get('WBQualityConstraintsWikibaseSenseId') => 'sense', |
|
| 899 | + $this->config->get('WBQualityConstraintsWikibaseMediaInfoId') => 'mediainfo', |
|
| 900 | 900 | ]; |
| 901 | 901 | } |
| 902 | 902 | |
@@ -906,10 +906,10 @@ discard block |
||
| 906 | 906 | * @throws ConstraintParameterException if the parameter is invalid or missing |
| 907 | 907 | * @return EntityTypesParameter |
| 908 | 908 | */ |
| 909 | - public function parseEntityTypesParameter( array $constraintParameters, string $constraintTypeItemId ): EntityTypesParameter { |
|
| 909 | + public function parseEntityTypesParameter(array $constraintParameters, string $constraintTypeItemId): EntityTypesParameter { |
|
| 910 | 910 | $entityTypes = []; |
| 911 | 911 | $entityTypeItemIds = []; |
| 912 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
| 912 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
| 913 | 913 | $itemIds = $this->parseItemIdsParameter( |
| 914 | 914 | $constraintParameters, |
| 915 | 915 | $constraintTypeItemId, |
@@ -918,22 +918,22 @@ discard block |
||
| 918 | 918 | ); |
| 919 | 919 | |
| 920 | 920 | $mapping = $this->getEntityTypeMapping(); |
| 921 | - foreach ( $itemIds as $itemId ) { |
|
| 922 | - $entityType = $this->mapItemId( $itemId, $mapping, $parameterId ); |
|
| 921 | + foreach ($itemIds as $itemId) { |
|
| 922 | + $entityType = $this->mapItemId($itemId, $mapping, $parameterId); |
|
| 923 | 923 | $entityTypes[] = $entityType; |
| 924 | 924 | $entityTypeItemIds[] = $itemId; |
| 925 | 925 | } |
| 926 | 926 | |
| 927 | - if ( $entityTypes === [] ) { |
|
| 927 | + if ($entityTypes === []) { |
|
| 928 | 928 | // @codeCoverageIgnoreStart |
| 929 | 929 | throw new LogicException( |
| 930 | - 'The "entity types" parameter is required, ' . |
|
| 930 | + 'The "entity types" parameter is required, '. |
|
| 931 | 931 | 'and yet we seem to be missing any allowed entity type' |
| 932 | 932 | ); |
| 933 | 933 | // @codeCoverageIgnoreEnd |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | - return new EntityTypesParameter( $entityTypes, $entityTypeItemIds ); |
|
| 936 | + return new EntityTypesParameter($entityTypes, $entityTypeItemIds); |
|
| 937 | 937 | } |
| 938 | 938 | |
| 939 | 939 | /** |
@@ -941,18 +941,18 @@ discard block |
||
| 941 | 941 | * @throws ConstraintParameterException if the parameter is invalid |
| 942 | 942 | * @return PropertyId[] |
| 943 | 943 | */ |
| 944 | - public function parseSeparatorsParameter( array $constraintParameters ): array { |
|
| 945 | - $separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' ); |
|
| 944 | + public function parseSeparatorsParameter(array $constraintParameters): array { |
|
| 945 | + $separatorId = $this->config->get('WBQualityConstraintsSeparatorId'); |
|
| 946 | 946 | |
| 947 | - if ( !array_key_exists( $separatorId, $constraintParameters ) ) { |
|
| 947 | + if (!array_key_exists($separatorId, $constraintParameters)) { |
|
| 948 | 948 | return []; |
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | $parameters = $constraintParameters[$separatorId]; |
| 952 | 952 | $separators = []; |
| 953 | 953 | |
| 954 | - foreach ( $parameters as $parameter ) { |
|
| 955 | - $separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId ); |
|
| 954 | + foreach ($parameters as $parameter) { |
|
| 955 | + $separators[] = $this->parsePropertyIdParameter($parameter, $separatorId); |
|
| 956 | 956 | } |
| 957 | 957 | |
| 958 | 958 | return $separators; |
@@ -960,17 +960,17 @@ discard block |
||
| 960 | 960 | |
| 961 | 961 | private function getConstraintScopeContextTypeMapping(): array { |
| 962 | 962 | return [ |
| 963 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ) => Context::TYPE_STATEMENT, |
|
| 964 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ) => Context::TYPE_QUALIFIER, |
|
| 965 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ) => Context::TYPE_REFERENCE, |
|
| 963 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId') => Context::TYPE_STATEMENT, |
|
| 964 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId') => Context::TYPE_QUALIFIER, |
|
| 965 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId') => Context::TYPE_REFERENCE, |
|
| 966 | 966 | ]; |
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | private function getPropertyScopeContextTypeMapping(): array { |
| 970 | 970 | return [ |
| 971 | - $this->config->get( 'WBQualityConstraintsAsMainValueId' ) => Context::TYPE_STATEMENT, |
|
| 972 | - $this->config->get( 'WBQualityConstraintsAsQualifiersId' ) => Context::TYPE_QUALIFIER, |
|
| 973 | - $this->config->get( 'WBQualityConstraintsAsReferencesId' ) => Context::TYPE_REFERENCE, |
|
| 971 | + $this->config->get('WBQualityConstraintsAsMainValueId') => Context::TYPE_STATEMENT, |
|
| 972 | + $this->config->get('WBQualityConstraintsAsQualifiersId') => Context::TYPE_QUALIFIER, |
|
| 973 | + $this->config->get('WBQualityConstraintsAsReferencesId') => Context::TYPE_REFERENCE, |
|
| 974 | 974 | ]; |
| 975 | 975 | } |
| 976 | 976 | |
@@ -980,9 +980,9 @@ discard block |
||
| 980 | 980 | * @throws ConstraintParameterException if the parameter is invalid or missing |
| 981 | 981 | * @return string[] list of Context::TYPE_* constants |
| 982 | 982 | */ |
| 983 | - public function parsePropertyScopeParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
| 983 | + public function parsePropertyScopeParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
| 984 | 984 | $contextTypes = []; |
| 985 | - $parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' ); |
|
| 985 | + $parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId'); |
|
| 986 | 986 | $itemIds = $this->parseItemIdsParameter( |
| 987 | 987 | $constraintParameters, |
| 988 | 988 | $constraintTypeItemId, |
@@ -991,14 +991,14 @@ discard block |
||
| 991 | 991 | ); |
| 992 | 992 | |
| 993 | 993 | $mapping = $this->getPropertyScopeContextTypeMapping(); |
| 994 | - foreach ( $itemIds as $itemId ) { |
|
| 995 | - $contextTypes[] = $this->mapItemId( $itemId, $mapping, $parameterId ); |
|
| 994 | + foreach ($itemIds as $itemId) { |
|
| 995 | + $contextTypes[] = $this->mapItemId($itemId, $mapping, $parameterId); |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | - if ( $contextTypes === [] ) { |
|
| 998 | + if ($contextTypes === []) { |
|
| 999 | 999 | // @codeCoverageIgnoreStart |
| 1000 | 1000 | throw new LogicException( |
| 1001 | - 'The "property scope" parameter is required, ' . |
|
| 1001 | + 'The "property scope" parameter is required, '. |
|
| 1002 | 1002 | 'and yet we seem to be missing any allowed scope' |
| 1003 | 1003 | ); |
| 1004 | 1004 | // @codeCoverageIgnoreEnd |