@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * @throws ConstraintParameterException |
85 | 85 | * @return array [ DataValue|null $min, DataValue|null $max, PropertyId $property, array $parameters ] |
86 | 86 | */ |
87 | - private function parseConstraintParameters( Constraint $constraint ) { |
|
88 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
87 | + private function parseConstraintParameters(Constraint $constraint) { |
|
88 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
89 | 89 | $constraint->getConstraintParameters(), |
90 | 90 | $constraint->getConstraintTypeItemId(), |
91 | 91 | 'quantity' |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | $constraint->getConstraintTypeItemId() |
96 | 96 | ); |
97 | 97 | |
98 | - if ( $min !== null ) { |
|
99 | - $parameters['minimum_quantity'] = [ $min ]; |
|
98 | + if ($min !== null) { |
|
99 | + $parameters['minimum_quantity'] = [$min]; |
|
100 | 100 | } |
101 | - if ( $max !== null ) { |
|
102 | - $parameters['maximum_quantity'] = [ $max ]; |
|
101 | + if ($max !== null) { |
|
102 | + $parameters['maximum_quantity'] = [$max]; |
|
103 | 103 | } |
104 | - $parameters['property'] = [ $property ]; |
|
104 | + $parameters['property'] = [$property]; |
|
105 | 105 | |
106 | - return [ $min, $max, $property, $parameters ]; |
|
106 | + return [$min, $max, $property, $parameters]; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return bool |
115 | 115 | */ |
116 | - private function rangeInYears( $min, $max ) { |
|
117 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
116 | + private function rangeInYears($min, $max) { |
|
117 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
118 | 118 | |
119 | - if ( $min !== null && $min->getUnit() === $yearUnit ) { |
|
119 | + if ($min !== null && $min->getUnit() === $yearUnit) { |
|
120 | 120 | return true; |
121 | 121 | } |
122 | - if ( $max !== null && $max->getUnit() === $yearUnit ) { |
|
122 | + if ($max !== null && $max->getUnit() === $yearUnit) { |
|
123 | 123 | return true; |
124 | 124 | } |
125 | 125 | |
@@ -135,59 +135,58 @@ discard block |
||
135 | 135 | * @throws ConstraintParameterException |
136 | 136 | * @return CheckResult |
137 | 137 | */ |
138 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
139 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
140 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
138 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
139 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
140 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | $parameters = []; |
144 | 144 | |
145 | 145 | $snak = $context->getSnak(); |
146 | 146 | |
147 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
147 | + if (!$snak instanceof PropertyValueSnak) { |
|
148 | 148 | // nothing to check |
149 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
149 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | $minuend = $snak->getDataValue(); |
153 | 153 | |
154 | 154 | /** @var PropertyId $property */ |
155 | - list( $min, $max, $property, $parameters ) = $this->parseConstraintParameters( $constraint ); |
|
155 | + list($min, $max, $property, $parameters) = $this->parseConstraintParameters($constraint); |
|
156 | 156 | |
157 | 157 | // checks only the first occurrence of the referenced property (this constraint implies a single value constraint on that property) |
158 | - foreach ( $context->getSnakGroup() as $otherSnak ) { |
|
158 | + foreach ($context->getSnakGroup() as $otherSnak) { |
|
159 | 159 | if ( |
160 | - !$property->equals( $otherSnak->getPropertyId() ) || |
|
160 | + !$property->equals($otherSnak->getPropertyId()) || |
|
161 | 161 | !$otherSnak instanceof PropertyValueSnak |
162 | 162 | ) { |
163 | 163 | continue; |
164 | 164 | } |
165 | 165 | |
166 | 166 | $subtrahend = $otherSnak->getDataValue(); |
167 | - if ( $subtrahend->getType() === $minuend->getType() ) { |
|
168 | - $diff = $this->rangeInYears( $min, $max ) && $minuend->getType() === 'time' ? |
|
169 | - $this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) : |
|
170 | - $this->rangeCheckerHelper->getDifference( $minuend, $subtrahend ); |
|
167 | + if ($subtrahend->getType() === $minuend->getType()) { |
|
168 | + $diff = $this->rangeInYears($min, $max) && $minuend->getType() === 'time' ? |
|
169 | + $this->rangeCheckerHelper->getDifferenceInYears($minuend, $subtrahend) : $this->rangeCheckerHelper->getDifference($minuend, $subtrahend); |
|
171 | 170 | |
172 | - if ( $this->rangeCheckerHelper->getComparison( $min, $diff ) > 0 || |
|
173 | - $this->rangeCheckerHelper->getComparison( $diff, $max ) > 0 |
|
171 | + if ($this->rangeCheckerHelper->getComparison($min, $diff) > 0 || |
|
172 | + $this->rangeCheckerHelper->getComparison($diff, $max) > 0 |
|
174 | 173 | ) { |
175 | 174 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
176 | - $openness = $min !== null ? ( $max !== null ? '' : '-rightopen' ) : '-leftopen'; |
|
175 | + $openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen'; |
|
177 | 176 | // possible message keys: |
178 | 177 | // wbqc-violation-message-diff-within-range |
179 | 178 | // wbqc-violation-message-diff-within-range-leftopen |
180 | 179 | // wbqc-violation-message-diff-within-range-rightopen |
181 | - $message = ( new ViolationMessage( "wbqc-violation-message-diff-within-range$openness" ) ) |
|
182 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
183 | - ->withDataValue( $minuend, Role::OBJECT ) |
|
184 | - ->withEntityId( $otherSnak->getPropertyId(), Role::PREDICATE ) |
|
185 | - ->withDataValue( $subtrahend, Role::OBJECT ); |
|
186 | - if ( $min !== null ) { |
|
187 | - $message = $message->withDataValue( $min, Role::OBJECT ); |
|
180 | + $message = (new ViolationMessage("wbqc-violation-message-diff-within-range$openness")) |
|
181 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
182 | + ->withDataValue($minuend, Role::OBJECT) |
|
183 | + ->withEntityId($otherSnak->getPropertyId(), Role::PREDICATE) |
|
184 | + ->withDataValue($subtrahend, Role::OBJECT); |
|
185 | + if ($min !== null) { |
|
186 | + $message = $message->withDataValue($min, Role::OBJECT); |
|
188 | 187 | } |
189 | - if ( $max !== null ) { |
|
190 | - $message = $message->withDataValue( $max, Role::OBJECT ); |
|
188 | + if ($max !== null) { |
|
189 | + $message = $message->withDataValue($max, Role::OBJECT); |
|
191 | 190 | } |
192 | 191 | $status = CheckResult::STATUS_VIOLATION; |
193 | 192 | } else { |
@@ -195,19 +194,19 @@ discard block |
||
195 | 194 | $status = CheckResult::STATUS_COMPLIANCE; |
196 | 195 | } |
197 | 196 | } else { |
198 | - $message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-must-have-equal-types' ); |
|
197 | + $message = new ViolationMessage('wbqc-violation-message-diff-within-range-must-have-equal-types'); |
|
199 | 198 | $status = CheckResult::STATUS_VIOLATION; |
200 | 199 | } |
201 | 200 | |
202 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
201 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
203 | 202 | } |
204 | 203 | |
205 | - $message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-property-must-exist' ); |
|
204 | + $message = new ViolationMessage('wbqc-violation-message-diff-within-range-property-must-exist'); |
|
206 | 205 | $status = CheckResult::STATUS_VIOLATION; |
207 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
206 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
208 | 207 | } |
209 | 208 | |
210 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
209 | + public function checkConstraintParameters(Constraint $constraint) { |
|
211 | 210 | $constraintParameters = $constraint->getConstraintParameters(); |
212 | 211 | $exceptions = []; |
213 | 212 | try { |
@@ -216,12 +215,12 @@ discard block |
||
216 | 215 | $constraint->getConstraintTypeItemId(), |
217 | 216 | 'quantity' |
218 | 217 | ); |
219 | - } catch ( ConstraintParameterException $e ) { |
|
218 | + } catch (ConstraintParameterException $e) { |
|
220 | 219 | $exceptions[] = $e; |
221 | 220 | } |
222 | 221 | try { |
223 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
224 | - } catch ( ConstraintParameterException $e ) { |
|
222 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
223 | + } catch (ConstraintParameterException $e) { |
|
225 | 224 | $exceptions[] = $e; |
226 | 225 | } |
227 | 226 | return $exceptions; |