@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | * @throws ConstraintParameterException |
87 | 87 | * @return CheckResult |
88 | 88 | */ |
89 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
90 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
91 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
89 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
90 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
91 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | $parameters = []; |
@@ -96,28 +96,28 @@ discard block |
||
96 | 96 | |
97 | 97 | $snak = $context->getSnak(); |
98 | 98 | |
99 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
99 | + if (!$snak instanceof PropertyValueSnak) { |
|
100 | 100 | // nothing to check |
101 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
101 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $dataValue = $snak->getDataValue(); |
105 | 105 | |
106 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
106 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
107 | 107 | $constraintParameters, |
108 | 108 | $constraint->getConstraintTypeItemId(), |
109 | 109 | $dataValue->getType() |
110 | 110 | ); |
111 | 111 | $parameterKey = $dataValue->getType() === 'quantity' ? 'quantity' : 'date'; |
112 | - if ( $min !== null ) { |
|
113 | - $parameters['minimum_' . $parameterKey] = [ $min ]; |
|
112 | + if ($min !== null) { |
|
113 | + $parameters['minimum_'.$parameterKey] = [$min]; |
|
114 | 114 | } |
115 | - if ( $max !== null ) { |
|
116 | - $parameters['maximum_' . $parameterKey] = [ $max ]; |
|
115 | + if ($max !== null) { |
|
116 | + $parameters['maximum_'.$parameterKey] = [$max]; |
|
117 | 117 | } |
118 | 118 | |
119 | - if ( $this->rangeCheckerHelper->getComparison( $min, $dataValue ) > 0 || |
|
120 | - $this->rangeCheckerHelper->getComparison( $dataValue, $max ) > 0 |
|
119 | + if ($this->rangeCheckerHelper->getComparison($min, $dataValue) > 0 || |
|
120 | + $this->rangeCheckerHelper->getComparison($dataValue, $max) > 0 |
|
121 | 121 | ) { |
122 | 122 | // possible message keys: |
123 | 123 | // wbqc-violation-message-range-quantity-closed |
@@ -131,22 +131,22 @@ discard block |
||
131 | 131 | // wbqc-violation-message-range-time-rightopen |
132 | 132 | // wbqc-violation-message-range-time-rightopen-leftnow |
133 | 133 | $messageKey = 'wbqc-violation-message-range'; |
134 | - $messageKey .= '-' . $dataValue->getType(); |
|
134 | + $messageKey .= '-'.$dataValue->getType(); |
|
135 | 135 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
136 | - $messageKey .= '-' . ( $min !== null ? ( $max !== null ? 'closed' : 'rightopen' ) : 'leftopen' ); |
|
137 | - if ( $min instanceof NowValue ) { |
|
136 | + $messageKey .= '-'.($min !== null ? ($max !== null ? 'closed' : 'rightopen') : 'leftopen'); |
|
137 | + if ($min instanceof NowValue) { |
|
138 | 138 | $messageKey .= '-leftnow'; |
139 | - } elseif ( $max instanceof NowValue ) { |
|
139 | + } elseif ($max instanceof NowValue) { |
|
140 | 140 | $messageKey .= '-rightnow'; |
141 | 141 | } |
142 | - $message = ( new ViolationMessage( $messageKey ) ) |
|
143 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
144 | - ->withDataValue( $dataValue, Role::OBJECT ); |
|
145 | - if ( $min !== null && !( $min instanceof NowValue ) ) { |
|
146 | - $message = $message->withDataValue( $min, Role::OBJECT ); |
|
142 | + $message = (new ViolationMessage($messageKey)) |
|
143 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
144 | + ->withDataValue($dataValue, Role::OBJECT); |
|
145 | + if ($min !== null && !($min instanceof NowValue)) { |
|
146 | + $message = $message->withDataValue($min, Role::OBJECT); |
|
147 | 147 | } |
148 | - if ( $max !== null && !( $max instanceof NowValue ) ) { |
|
149 | - $message = $message->withDataValue( $max, Role::OBJECT ); |
|
148 | + if ($max !== null && !($max instanceof NowValue)) { |
|
149 | + $message = $message->withDataValue($max, Role::OBJECT); |
|
150 | 150 | } |
151 | 151 | $status = CheckResult::STATUS_VIOLATION; |
152 | 152 | } else { |
@@ -154,22 +154,22 @@ discard block |
||
154 | 154 | $status = CheckResult::STATUS_COMPLIANCE; |
155 | 155 | } |
156 | 156 | |
157 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
157 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
158 | 158 | } |
159 | 159 | |
160 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
160 | + public function checkConstraintParameters(Constraint $constraint) { |
|
161 | 161 | $constraintParameters = $constraint->getConstraintParameters(); |
162 | 162 | $exceptions = []; |
163 | 163 | try { |
164 | 164 | // we don’t have a data value here, so get the type from the property instead |
165 | 165 | // (the distinction between data type and data value type is irrelevant for 'quantity' and 'time') |
166 | - $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty( $constraint->getPropertyId() ); |
|
166 | + $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty($constraint->getPropertyId()); |
|
167 | 167 | $this->constraintParameterParser->parseRangeParameter( |
168 | 168 | $constraintParameters, |
169 | 169 | $constraint->getConstraintTypeItemId(), |
170 | 170 | $type |
171 | 171 | ); |
172 | - } catch ( ConstraintParameterException $e ) { |
|
172 | + } catch (ConstraintParameterException $e) { |
|
173 | 173 | $exceptions[] = $e; |
174 | 174 | } |
175 | 175 | return $exceptions; |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | * @param array $parameters |
78 | 78 | * @throws ConstraintParameterException |
79 | 79 | */ |
80 | - public function checkError( array $parameters ) { |
|
81 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
80 | + public function checkError(array $parameters) { |
|
81 | + if (array_key_exists('@error', $parameters)) { |
|
82 | 82 | $error = $parameters['@error']; |
83 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
83 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
84 | 84 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
85 | 85 | } else { |
86 | 86 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
87 | 87 | } |
88 | - throw new ConstraintParameterException( wfMessage( $msg )->escaped() ); |
|
88 | + throw new ConstraintParameterException(wfMessage($msg)->escaped()); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | * @param string $parameterId |
96 | 96 | * @throws ConstraintParameterException |
97 | 97 | */ |
98 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
99 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
98 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
99 | + if (count($parameters[$parameterId]) !== 1) { |
|
100 | 100 | throw new ConstraintParameterException( |
101 | - wfMessage( 'wbqc-violation-message-parameter-single' ) |
|
102 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
101 | + wfMessage('wbqc-violation-message-parameter-single') |
|
102 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
103 | 103 | ->escaped() |
104 | 104 | ); |
105 | 105 | } |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * @return void |
113 | 113 | * @throws ConstraintParameterException |
114 | 114 | */ |
115 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
116 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
115 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
116 | + if (!($snak instanceof PropertyValueSnak)) { |
|
117 | 117 | throw new ConstraintParameterException( |
118 | - wfMessage( 'wbqc-violation-message-parameter-value' ) |
|
119 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
118 | + wfMessage('wbqc-violation-message-parameter-value') |
|
119 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
120 | 120 | ->escaped() |
121 | 121 | ); |
122 | 122 | } |
@@ -129,18 +129,18 @@ discard block |
||
129 | 129 | * @throws ConstraintParameterException |
130 | 130 | * @return EntityId |
131 | 131 | */ |
132 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
133 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
134 | - $this->requireValueParameter( $snak, $parameterId ); |
|
132 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
133 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
134 | + $this->requireValueParameter($snak, $parameterId); |
|
135 | 135 | $value = $snak->getDataValue(); |
136 | - if ( $value instanceof EntityIdValue ) { |
|
136 | + if ($value instanceof EntityIdValue) { |
|
137 | 137 | return $value->getEntityId(); |
138 | 138 | } else { |
139 | 139 | throw new ConstraintParameterException( |
140 | - wfMessage( 'wbqc-violation-message-parameter-entity' ) |
|
140 | + wfMessage('wbqc-violation-message-parameter-entity') |
|
141 | 141 | ->rawParams( |
142 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
143 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
142 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
143 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
144 | 144 | ) |
145 | 145 | ->escaped() |
146 | 146 | ); |
@@ -153,21 +153,21 @@ discard block |
||
153 | 153 | * @throws ConstraintParameterException if the parameter is invalid or missing |
154 | 154 | * @return string[] class entity ID serializations |
155 | 155 | */ |
156 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
157 | - $this->checkError( $constraintParameters ); |
|
158 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
159 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
156 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
157 | + $this->checkError($constraintParameters); |
|
158 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
159 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
160 | 160 | throw new ConstraintParameterException( |
161 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
162 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
163 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $classId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
161 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
162 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
163 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($classId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
164 | 164 | ->escaped() |
165 | 165 | ); |
166 | 166 | } |
167 | 167 | |
168 | 168 | $classes = []; |
169 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
170 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
169 | + foreach ($constraintParameters[$classId] as $class) { |
|
170 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
171 | 171 | } |
172 | 172 | return $classes; |
173 | 173 | } |
@@ -178,24 +178,24 @@ discard block |
||
178 | 178 | * @throws ConstraintParameterException if the parameter is invalid or missing |
179 | 179 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
180 | 180 | */ |
181 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
182 | - $this->checkError( $constraintParameters ); |
|
183 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
184 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
181 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
182 | + $this->checkError($constraintParameters); |
|
183 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
184 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
185 | 185 | throw new ConstraintParameterException( |
186 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
187 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
188 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
186 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
187 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
188 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
189 | 189 | ->escaped() |
190 | 190 | ); |
191 | 191 | } |
192 | 192 | |
193 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
194 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
195 | - $instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ); |
|
196 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ); |
|
197 | - $instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ); |
|
198 | - switch ( $relationEntityId ) { |
|
193 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
194 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
195 | + $instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId'); |
|
196 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId'); |
|
197 | + $instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId'); |
|
198 | + switch ($relationEntityId) { |
|
199 | 199 | case $instanceId: |
200 | 200 | return 'instance'; |
201 | 201 | case $subclassId: |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | return 'instanceOrSubclass'; |
205 | 205 | default: |
206 | 206 | throw new ConstraintParameterException( |
207 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
208 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
209 | - ->numParams( 3 ) |
|
210 | - ->rawParams( $this->constraintParameterRenderer->formatItemIdList( |
|
211 | - [ $instanceId, $subclassId, $instanceOrSubclassId ], |
|
207 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
208 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
209 | + ->numParams(3) |
|
210 | + ->rawParams($this->constraintParameterRenderer->formatItemIdList( |
|
211 | + [$instanceId, $subclassId, $instanceOrSubclassId], |
|
212 | 212 | Role::CONSTRAINT_PARAMETER_VALUE |
213 | - ) ) |
|
213 | + )) |
|
214 | 214 | ->escaped() |
215 | 215 | ); |
216 | 216 | } |
@@ -223,21 +223,21 @@ discard block |
||
223 | 223 | * @throws ConstraintParameterException |
224 | 224 | * @return PropertyId |
225 | 225 | */ |
226 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
227 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
228 | - $this->requireValueParameter( $snak, $parameterId ); |
|
226 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
227 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
228 | + $this->requireValueParameter($snak, $parameterId); |
|
229 | 229 | $value = $snak->getDataValue(); |
230 | - if ( $value instanceof EntityIdValue ) { |
|
230 | + if ($value instanceof EntityIdValue) { |
|
231 | 231 | $id = $value->getEntityId(); |
232 | - if ( $id instanceof PropertyId ) { |
|
232 | + if ($id instanceof PropertyId) { |
|
233 | 233 | return $id; |
234 | 234 | } |
235 | 235 | } |
236 | 236 | throw new ConstraintParameterException( |
237 | - wfMessage( 'wbqc-violation-message-parameter-property' ) |
|
237 | + wfMessage('wbqc-violation-message-parameter-property') |
|
238 | 238 | ->rawParams( |
239 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
240 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
239 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
240 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
241 | 241 | ) |
242 | 242 | ->escaped() |
243 | 243 | ); |
@@ -250,34 +250,34 @@ discard block |
||
250 | 250 | * @throws ConstraintParameterException if the parameter is invalid or missing |
251 | 251 | * @return PropertyId |
252 | 252 | */ |
253 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
254 | - $this->checkError( $constraintParameters ); |
|
255 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
256 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
253 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
254 | + $this->checkError($constraintParameters); |
|
255 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
256 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
257 | 257 | throw new ConstraintParameterException( |
258 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
259 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
260 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
258 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
259 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
260 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
261 | 261 | ->escaped() |
262 | 262 | ); |
263 | 263 | } |
264 | 264 | |
265 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
266 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
265 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
266 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
267 | 267 | } |
268 | 268 | |
269 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
269 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
270 | 270 | $dataValue = $snak->getDataValue(); |
271 | - if ( $dataValue instanceof EntityIdValue && |
|
271 | + if ($dataValue instanceof EntityIdValue && |
|
272 | 272 | $dataValue->getEntityId() instanceof ItemId |
273 | 273 | ) { |
274 | - return ItemIdSnakValue::fromItemId( $dataValue->getEntityId() ); |
|
274 | + return ItemIdSnakValue::fromItemId($dataValue->getEntityId()); |
|
275 | 275 | } else { |
276 | 276 | throw new ConstraintParameterException( |
277 | - wfMessage( 'wbqc-violation-message-parameter-item' ) |
|
277 | + wfMessage('wbqc-violation-message-parameter-item') |
|
278 | 278 | ->rawParams( |
279 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
280 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
279 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
280 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
281 | 281 | ) |
282 | 282 | ->escaped() |
283 | 283 | ); |
@@ -291,15 +291,15 @@ discard block |
||
291 | 291 | * @throws ConstraintParameterException if the parameter is invalid or missing |
292 | 292 | * @return ItemIdSnakValue[] array of values |
293 | 293 | */ |
294 | - public function parseItemsParameter( array $constraintParameters, $constraintTypeItemId, $required ) { |
|
295 | - $this->checkError( $constraintParameters ); |
|
296 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
297 | - if ( !array_key_exists( $qualifierId, $constraintParameters ) ) { |
|
298 | - if ( $required ) { |
|
294 | + public function parseItemsParameter(array $constraintParameters, $constraintTypeItemId, $required) { |
|
295 | + $this->checkError($constraintParameters); |
|
296 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
297 | + if (!array_key_exists($qualifierId, $constraintParameters)) { |
|
298 | + if ($required) { |
|
299 | 299 | throw new ConstraintParameterException( |
300 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
301 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
302 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
300 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
301 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
302 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
303 | 303 | ->escaped() |
304 | 304 | ); |
305 | 305 | } else { |
@@ -308,11 +308,11 @@ discard block |
||
308 | 308 | } |
309 | 309 | |
310 | 310 | $values = []; |
311 | - foreach ( $constraintParameters[$qualifierId] as $parameter ) { |
|
312 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
313 | - switch ( true ) { |
|
311 | + foreach ($constraintParameters[$qualifierId] as $parameter) { |
|
312 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
313 | + switch (true) { |
|
314 | 314 | case $snak instanceof PropertyValueSnak: |
315 | - $values[] = $this->parseItemIdParameter( $snak, $qualifierId ); |
|
315 | + $values[] = $this->parseItemIdParameter($snak, $qualifierId); |
|
316 | 316 | break; |
317 | 317 | case $snak instanceof PropertySomeValueSnak: |
318 | 318 | $values[] = ItemIdSnakValue::someValue(); |
@@ -331,28 +331,28 @@ discard block |
||
331 | 331 | * @throws ConstraintParameterException if the parameter is invalid or missing |
332 | 332 | * @return PropertyId[] |
333 | 333 | */ |
334 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
335 | - $this->checkError( $constraintParameters ); |
|
336 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
337 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
334 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
335 | + $this->checkError($constraintParameters); |
|
336 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
337 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
338 | 338 | throw new ConstraintParameterException( |
339 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
340 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
341 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
339 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
340 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
341 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
342 | 342 | ->escaped() |
343 | 343 | ); |
344 | 344 | } |
345 | 345 | |
346 | 346 | $parameters = $constraintParameters[$propertyId]; |
347 | - if ( count( $parameters ) === 1 && |
|
348 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
347 | + if (count($parameters) === 1 && |
|
348 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
349 | 349 | ) { |
350 | 350 | return []; |
351 | 351 | } |
352 | 352 | |
353 | 353 | $properties = []; |
354 | - foreach ( $parameters as $parameter ) { |
|
355 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
354 | + foreach ($parameters as $parameter) { |
|
355 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
356 | 356 | } |
357 | 357 | return $properties; |
358 | 358 | } |
@@ -363,16 +363,16 @@ discard block |
||
363 | 363 | * @throws ConstraintParameterException |
364 | 364 | * @return DataValue|null |
365 | 365 | */ |
366 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
367 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
368 | - if ( $snak instanceof PropertyValueSnak ) { |
|
366 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
367 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
368 | + if ($snak instanceof PropertyValueSnak) { |
|
369 | 369 | return $snak->getDataValue(); |
370 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
370 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
371 | 371 | return null; |
372 | 372 | } else { |
373 | 373 | throw new ConstraintParameterException( |
374 | - wfMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) |
|
375 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
374 | + wfMessage('wbqc-violation-message-parameter-value-or-novalue') |
|
375 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
376 | 376 | ->escaped() |
377 | 377 | ); |
378 | 378 | } |
@@ -383,10 +383,10 @@ discard block |
||
383 | 383 | * @param string $parameterId |
384 | 384 | * @return DataValue|null |
385 | 385 | */ |
386 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
386 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
387 | 387 | try { |
388 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
389 | - } catch ( ConstraintParameterException $e ) { |
|
388 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
389 | + } catch (ConstraintParameterException $e) { |
|
390 | 390 | // unknown value means “now” |
391 | 391 | return new NowValue(); |
392 | 392 | } |
@@ -399,14 +399,14 @@ discard block |
||
399 | 399 | * @param string $unit |
400 | 400 | * @return bool |
401 | 401 | */ |
402 | - private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) { |
|
403 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
404 | - !( $max instanceof UnboundedQuantityValue ) |
|
402 | + private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) { |
|
403 | + if (!($min instanceof UnboundedQuantityValue) || |
|
404 | + !($max instanceof UnboundedQuantityValue) |
|
405 | 405 | ) { |
406 | 406 | return false; |
407 | 407 | } |
408 | 408 | |
409 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
409 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | /** |
@@ -417,9 +417,9 @@ discard block |
||
417 | 417 | * @throws ConstraintParameterException if the parameter is invalid or missing |
418 | 418 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
419 | 419 | */ |
420 | - public function parseRangeParameter( array $constraintParameters, $constraintTypeItemId, $type ) { |
|
421 | - $this->checkError( $constraintParameters ); |
|
422 | - switch ( $type ) { |
|
420 | + public function parseRangeParameter(array $constraintParameters, $constraintTypeItemId, $type) { |
|
421 | + $this->checkError($constraintParameters); |
|
422 | + switch ($type) { |
|
423 | 423 | case 'quantity': |
424 | 424 | $configKey = 'Quantity'; |
425 | 425 | break; |
@@ -428,58 +428,58 @@ discard block |
||
428 | 428 | break; |
429 | 429 | default: |
430 | 430 | throw new ConstraintParameterException( |
431 | - wfMessage( 'wbqc-violation-message-value-needed-of-types-2' ) |
|
431 | + wfMessage('wbqc-violation-message-value-needed-of-types-2') |
|
432 | 432 | ->rawParams( |
433 | - $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ), |
|
434 | - wfMessage( 'datatypes-type-quantity' )->escaped(), |
|
435 | - wfMessage( 'datatypes-type-time' )->escaped() |
|
433 | + $this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM), |
|
434 | + wfMessage('datatypes-type-quantity')->escaped(), |
|
435 | + wfMessage('datatypes-type-time')->escaped() |
|
436 | 436 | ) |
437 | 437 | ->escaped() |
438 | 438 | ); |
439 | 439 | } |
440 | - $minimumId = $this->config->get( 'WBQualityConstraintsMinimum' . $configKey . 'Id' ); |
|
441 | - $maximumId = $this->config->get( 'WBQualityConstraintsMaximum' . $configKey . 'Id' ); |
|
442 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
443 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
440 | + $minimumId = $this->config->get('WBQualityConstraintsMinimum'.$configKey.'Id'); |
|
441 | + $maximumId = $this->config->get('WBQualityConstraintsMaximum'.$configKey.'Id'); |
|
442 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
443 | + !array_key_exists($maximumId, $constraintParameters) |
|
444 | 444 | ) { |
445 | 445 | throw new ConstraintParameterException( |
446 | - wfMessage( 'wbqc-violation-message-range-parameters-needed' ) |
|
446 | + wfMessage('wbqc-violation-message-range-parameters-needed') |
|
447 | 447 | ->rawParams( |
448 | - wfMessage( 'datatypes-type-' . $type )->escaped(), |
|
449 | - $this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
450 | - $this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
448 | + wfMessage('datatypes-type-'.$type)->escaped(), |
|
449 | + $this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
450 | + $this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
451 | 451 | ) |
452 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
452 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
453 | 453 | ->escaped() |
454 | 454 | ); |
455 | 455 | } |
456 | 456 | |
457 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
458 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
457 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
458 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
459 | 459 | $parseFunction = $configKey === 'Date' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
460 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
461 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
460 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
461 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
462 | 462 | |
463 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
464 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
463 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
464 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
465 | 465 | throw new ConstraintParameterException( |
466 | - wfMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
466 | + wfMessage('wbqc-violation-message-range-parameters-one-year') |
|
467 | 467 | ->escaped() |
468 | 468 | ); |
469 | 469 | } |
470 | - if ( $min === null && $max === null || |
|
471 | - $min !== null && $max !== null && $min->equals( $max ) ) { |
|
470 | + if ($min === null && $max === null || |
|
471 | + $min !== null && $max !== null && $min->equals($max)) { |
|
472 | 472 | throw new ConstraintParameterException( |
473 | - wfMessage( 'wbqc-violation-message-range-parameters-same' ) |
|
473 | + wfMessage('wbqc-violation-message-range-parameters-same') |
|
474 | 474 | ->rawParams( |
475 | - $this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
476 | - $this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
475 | + $this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
476 | + $this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
477 | 477 | ) |
478 | 478 | ->escaped() |
479 | 479 | ); |
480 | 480 | } |
481 | 481 | |
482 | - return [ $min, $max ]; |
|
482 | + return [$min, $max]; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -489,18 +489,18 @@ discard block |
||
489 | 489 | * @throws ConstraintParameterException |
490 | 490 | * @return string |
491 | 491 | */ |
492 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
493 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
494 | - $this->requireValueParameter( $snak, $parameterId ); |
|
492 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
493 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
494 | + $this->requireValueParameter($snak, $parameterId); |
|
495 | 495 | $value = $snak->getDataValue(); |
496 | - if ( $value instanceof StringValue ) { |
|
496 | + if ($value instanceof StringValue) { |
|
497 | 497 | return $value->getValue(); |
498 | 498 | } else { |
499 | 499 | throw new ConstraintParameterException( |
500 | - wfMessage( 'wbqc-violation-message-parameter-string' ) |
|
500 | + wfMessage('wbqc-violation-message-parameter-string') |
|
501 | 501 | ->rawParams( |
502 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
503 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
502 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
503 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
504 | 504 | ) |
505 | 505 | ->escaped() |
506 | 506 | ); |
@@ -513,15 +513,15 @@ discard block |
||
513 | 513 | * @throws ConstraintParameterException if the parameter is invalid or missing |
514 | 514 | * @return string |
515 | 515 | */ |
516 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
517 | - $this->checkError( $constraintParameters ); |
|
518 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
519 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
516 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
517 | + $this->checkError($constraintParameters); |
|
518 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
519 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
520 | 520 | return ''; |
521 | 521 | } |
522 | 522 | |
523 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
524 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
523 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
524 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -530,20 +530,20 @@ discard block |
||
530 | 530 | * @throws ConstraintParameterException if the parameter is invalid or missing |
531 | 531 | * @return string |
532 | 532 | */ |
533 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
534 | - $this->checkError( $constraintParameters ); |
|
535 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
536 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
533 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
534 | + $this->checkError($constraintParameters); |
|
535 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
536 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
537 | 537 | throw new ConstraintParameterException( |
538 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
539 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
540 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $formatId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
538 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
539 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
540 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($formatId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
541 | 541 | ->escaped() |
542 | 542 | ); |
543 | 543 | } |
544 | 544 | |
545 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
546 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
545 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
546 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -551,16 +551,16 @@ discard block |
||
551 | 551 | * @throws ConstraintParameterException if the parameter is invalid |
552 | 552 | * @return EntityId[] |
553 | 553 | */ |
554 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
555 | - $this->checkError( $constraintParameters ); |
|
556 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
557 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
554 | + public function parseExceptionParameter(array $constraintParameters) { |
|
555 | + $this->checkError($constraintParameters); |
|
556 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
557 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
558 | 558 | return []; |
559 | 559 | } |
560 | 560 | |
561 | 561 | return array_map( |
562 | - function( $snakSerialization ) use ( $exceptionId ) { |
|
563 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
562 | + function($snakSerialization) use ($exceptionId) { |
|
563 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
564 | 564 | }, |
565 | 565 | $constraintParameters[$exceptionId] |
566 | 566 | ); |
@@ -571,27 +571,27 @@ discard block |
||
571 | 571 | * @throws ConstraintParameterException if the parameter is invalid |
572 | 572 | * @return string|null 'mandatory' or null |
573 | 573 | */ |
574 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
575 | - $this->checkError( $constraintParameters ); |
|
576 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
577 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
574 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
575 | + $this->checkError($constraintParameters); |
|
576 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
577 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
578 | 578 | return null; |
579 | 579 | } |
580 | 580 | |
581 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
582 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
583 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
584 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
581 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
582 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
583 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
584 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
585 | 585 | $statusId = $snak->getDataValue()->getEntityId()->getSerialization(); |
586 | 586 | |
587 | - if ( $statusId === $mandatoryId ) { |
|
587 | + if ($statusId === $mandatoryId) { |
|
588 | 588 | return 'mandatory'; |
589 | 589 | } else { |
590 | 590 | throw new ConstraintParameterException( |
591 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
592 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
593 | - ->numParams( 1 ) |
|
594 | - ->rawParams( $this->constraintParameterRenderer->formatItemIdList( [ $mandatoryId ], Role::CONSTRAINT_PARAMETER_VALUE ) ) |
|
591 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
592 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
593 | + ->numParams(1) |
|
594 | + ->rawParams($this->constraintParameterRenderer->formatItemIdList([$mandatoryId], Role::CONSTRAINT_PARAMETER_VALUE)) |
|
595 | 595 | ->escaped() |
596 | 596 | ); |
597 | 597 | } |
@@ -604,13 +604,13 @@ discard block |
||
604 | 604 | * @return void |
605 | 605 | * @throws ConstraintParameterException |
606 | 606 | */ |
607 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
608 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
607 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
608 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
609 | 609 | throw new ConstraintParameterException( |
610 | - wfMessage( 'wbqc-violation-message-parameter-monolingualtext' ) |
|
610 | + wfMessage('wbqc-violation-message-parameter-monolingualtext') |
|
611 | 611 | ->rawParams( |
612 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
613 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
612 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
613 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
614 | 614 | ) |
615 | 615 | ->escaped() |
616 | 616 | ); |
@@ -625,26 +625,26 @@ discard block |
||
625 | 625 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
626 | 626 | * @return MultilingualTextValue |
627 | 627 | */ |
628 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
628 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
629 | 629 | $result = []; |
630 | 630 | |
631 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
632 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
633 | - $this->requireValueParameter( $snak, $parameterId ); |
|
631 | + foreach ($snakSerializations as $snakSerialization) { |
|
632 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
633 | + $this->requireValueParameter($snak, $parameterId); |
|
634 | 634 | |
635 | 635 | $value = $snak->getDataValue(); |
636 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
636 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
637 | 637 | /** @var MonolingualTextValue $value */ |
638 | 638 | |
639 | 639 | $code = $value->getLanguageCode(); |
640 | - if ( array_key_exists( $code, $result ) ) { |
|
640 | + if (array_key_exists($code, $result)) { |
|
641 | 641 | throw new ConstraintParameterException( |
642 | - wfMessage( 'wbqc-violation-message-parameter-single-per-language' ) |
|
642 | + wfMessage('wbqc-violation-message-parameter-single-per-language') |
|
643 | 643 | ->rawParams( |
644 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
644 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
645 | 645 | ) |
646 | 646 | ->plaintextParams( |
647 | - Language::fetchLanguageName( $code ), |
|
647 | + Language::fetchLanguageName($code), |
|
648 | 648 | $code |
649 | 649 | ) |
650 | 650 | ->escaped() |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | $result[$code] = $value; |
655 | 655 | } |
656 | 656 | |
657 | - return new MultilingualTextValue( $result ); |
|
657 | + return new MultilingualTextValue($result); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -662,11 +662,11 @@ discard block |
||
662 | 662 | * @throws ConstraintParameterException if the parameter is invalid |
663 | 663 | * @return MultilingualTextValue |
664 | 664 | */ |
665 | - public function parseSyntaxClarificationParameter( array $constraintParameters ) { |
|
666 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
665 | + public function parseSyntaxClarificationParameter(array $constraintParameters) { |
|
666 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
667 | 667 | |
668 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
669 | - return new MultilingualTextValue( [] ); |
|
668 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
669 | + return new MultilingualTextValue([]); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -685,20 +685,20 @@ discard block |
||
685 | 685 | * @throws ConstraintParameterException if the parameter is invalid |
686 | 686 | * @return string[]|null Context::TYPE_* constants |
687 | 687 | */ |
688 | - public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) { |
|
689 | - $constraintScopeId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
690 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ); |
|
691 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ); |
|
692 | - $referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ); |
|
688 | + public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) { |
|
689 | + $constraintScopeId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
690 | + $mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId'); |
|
691 | + $qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId'); |
|
692 | + $referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId'); |
|
693 | 693 | |
694 | - if ( !array_key_exists( $constraintScopeId, $constraintParameters ) ) { |
|
694 | + if (!array_key_exists($constraintScopeId, $constraintParameters)) { |
|
695 | 695 | return null; |
696 | 696 | } |
697 | 697 | |
698 | 698 | $contextTypes = []; |
699 | - foreach ( $constraintParameters[$constraintScopeId] as $snakSerialization ) { |
|
700 | - $scopeEntityId = $this->parseEntityIdParameter( $snakSerialization, $constraintScopeId ); |
|
701 | - switch ( $scopeEntityId->getSerialization() ) { |
|
699 | + foreach ($constraintParameters[$constraintScopeId] as $snakSerialization) { |
|
700 | + $scopeEntityId = $this->parseEntityIdParameter($snakSerialization, $constraintScopeId); |
|
701 | + switch ($scopeEntityId->getSerialization()) { |
|
702 | 702 | case $mainSnakId: |
703 | 703 | $contextTypes[] = Context::TYPE_STATEMENT; |
704 | 704 | break; |
@@ -710,14 +710,14 @@ discard block |
||
710 | 710 | break; |
711 | 711 | default: |
712 | 712 | throw new ConstraintParameterException( |
713 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
713 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
714 | 714 | ->rawParams( |
715 | 715 | $this->constraintParameterRenderer->formatPropertyId( |
716 | 716 | $constraintScopeId, |
717 | 717 | Role::CONSTRAINT_PARAMETER_PROPERTY |
718 | 718 | ) |
719 | 719 | ) |
720 | - ->numParams( 3 ) |
|
720 | + ->numParams(3) |
|
721 | 721 | ->rawParams( |
722 | 722 | $this->constraintParameterRenderer->formatItemIdList( |
723 | 723 | [ |
@@ -733,12 +733,12 @@ discard block |
||
733 | 733 | } |
734 | 734 | } |
735 | 735 | |
736 | - if ( $validScopes !== null ) { |
|
737 | - $invalidScopes = array_diff( $contextTypes, $validScopes ); |
|
738 | - if ( $invalidScopes !== [] ) { |
|
739 | - $invalidScope = array_pop( $invalidScopes ); |
|
736 | + if ($validScopes !== null) { |
|
737 | + $invalidScopes = array_diff($contextTypes, $validScopes); |
|
738 | + if ($invalidScopes !== []) { |
|
739 | + $invalidScope = array_pop($invalidScopes); |
|
740 | 740 | throw new ConstraintParameterException( |
741 | - wfMessage( 'wbqc-violation-message-invalid-scope' ) |
|
741 | + wfMessage('wbqc-violation-message-invalid-scope') |
|
742 | 742 | ->rawParams( |
743 | 743 | $this->constraintParameterRenderer->formatConstraintScope( |
744 | 744 | $invalidScope, |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | Role::CONSTRAINT_TYPE_ITEM |
750 | 750 | ) |
751 | 751 | ) |
752 | - ->numParams( count( $validScopes ) ) |
|
752 | + ->numParams(count($validScopes)) |
|
753 | 753 | ->rawParams( |
754 | 754 | $this->constraintParameterRenderer->formatConstraintScopeList( |
755 | 755 | $validScopes, |
@@ -28,15 +28,15 @@ |
||
28 | 28 | * @return string |
29 | 29 | */ |
30 | 30 | public function getTime() { |
31 | - return gmdate( '+Y-m-d\TH:i:s\Z' ); |
|
31 | + return gmdate('+Y-m-d\TH:i:s\Z'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | public function getArrayValue() { |
35 | - throw new LogicException( 'NowValue should never be serialized' ); |
|
35 | + throw new LogicException('NowValue should never be serialized'); |
|
36 | 36 | } |
37 | 37 | |
38 | - public function equals( $value ) { |
|
39 | - return get_class( $value ) === self::class; |
|
38 | + public function equals($value) { |
|
39 | + return get_class($value) === self::class; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |