@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | * @throws ConstraintParameterException |
92 | 92 | * @return CheckResult |
93 | 93 | */ |
94 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
95 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
96 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
94 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
95 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
96 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | $parameters = []; |
@@ -101,28 +101,28 @@ discard block |
||
101 | 101 | |
102 | 102 | $snak = $context->getSnak(); |
103 | 103 | |
104 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
104 | + if (!$snak instanceof PropertyValueSnak) { |
|
105 | 105 | // nothing to check |
106 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
106 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | $dataValue = $snak->getDataValue(); |
110 | 110 | |
111 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
111 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
112 | 112 | $constraintParameters, |
113 | 113 | $constraint->getConstraintTypeItemId(), |
114 | 114 | $dataValue->getType() |
115 | 115 | ); |
116 | 116 | $parameterKey = $dataValue->getType() === 'quantity' ? 'quantity' : 'date'; |
117 | - if ( $min !== null ) { |
|
118 | - $parameters['minimum_' . $parameterKey] = [ $min ]; |
|
117 | + if ($min !== null) { |
|
118 | + $parameters['minimum_'.$parameterKey] = [$min]; |
|
119 | 119 | } |
120 | - if ( $max !== null ) { |
|
121 | - $parameters['maximum_' . $parameterKey] = [ $max ]; |
|
120 | + if ($max !== null) { |
|
121 | + $parameters['maximum_'.$parameterKey] = [$max]; |
|
122 | 122 | } |
123 | 123 | |
124 | - if ( $this->rangeCheckerHelper->getComparison( $min, $dataValue ) > 0 || |
|
125 | - $this->rangeCheckerHelper->getComparison( $dataValue, $max ) > 0 |
|
124 | + if ($this->rangeCheckerHelper->getComparison($min, $dataValue) > 0 || |
|
125 | + $this->rangeCheckerHelper->getComparison($dataValue, $max) > 0 |
|
126 | 126 | ) { |
127 | 127 | $message = $this->getViolationMessage( |
128 | 128 | $context->getSnak()->getPropertyId(), |
@@ -138,16 +138,16 @@ discard block |
||
138 | 138 | |
139 | 139 | if ( |
140 | 140 | $dataValue instanceof TimeValue && |
141 | - ( $min instanceof NowValue || $max instanceof NowValue ) && |
|
142 | - $this->rangeCheckerHelper->isFutureTime( $dataValue ) |
|
141 | + ($min instanceof NowValue || $max instanceof NowValue) && |
|
142 | + $this->rangeCheckerHelper->isFutureTime($dataValue) |
|
143 | 143 | ) { |
144 | - $dependencyMetadata = DependencyMetadata::ofFutureTime( $dataValue ); |
|
144 | + $dependencyMetadata = DependencyMetadata::ofFutureTime($dataValue); |
|
145 | 145 | } else { |
146 | 146 | $dependencyMetadata = DependencyMetadata::blank(); |
147 | 147 | } |
148 | 148 | |
149 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
150 | - ->withMetadata( Metadata::ofDependencyMetadata( $dependencyMetadata ) ); |
|
149 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
150 | + ->withMetadata(Metadata::ofDependencyMetadata($dependencyMetadata)); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @return ViolationMessage |
160 | 160 | */ |
161 | - private function getViolationMessage( PropertyId $predicate, DataValue $value, $min, $max ) { |
|
161 | + private function getViolationMessage(PropertyId $predicate, DataValue $value, $min, $max) { |
|
162 | 162 | // possible message keys: |
163 | 163 | // wbqc-violation-message-range-quantity-closed |
164 | 164 | // wbqc-violation-message-range-quantity-leftopen |
@@ -171,39 +171,39 @@ discard block |
||
171 | 171 | // wbqc-violation-message-range-time-rightopen |
172 | 172 | // wbqc-violation-message-range-time-rightopen-leftnow |
173 | 173 | $messageKey = 'wbqc-violation-message-range'; |
174 | - $messageKey .= '-' . $value->getType(); |
|
174 | + $messageKey .= '-'.$value->getType(); |
|
175 | 175 | // at least one of $min, $max is set, otherwise there could be no violation |
176 | - $messageKey .= '-' . ( $min !== null ? ( $max !== null ? 'closed' : 'rightopen' ) : 'leftopen' ); |
|
177 | - if ( $min instanceof NowValue ) { |
|
176 | + $messageKey .= '-'.($min !== null ? ($max !== null ? 'closed' : 'rightopen') : 'leftopen'); |
|
177 | + if ($min instanceof NowValue) { |
|
178 | 178 | $messageKey .= '-leftnow'; |
179 | - } elseif ( $max instanceof NowValue ) { |
|
179 | + } elseif ($max instanceof NowValue) { |
|
180 | 180 | $messageKey .= '-rightnow'; |
181 | 181 | } |
182 | - $message = ( new ViolationMessage( $messageKey ) ) |
|
183 | - ->withEntityId( $predicate, Role::PREDICATE ) |
|
184 | - ->withDataValue( $value, Role::OBJECT ); |
|
185 | - if ( $min !== null && !( $min instanceof NowValue ) ) { |
|
186 | - $message = $message->withDataValue( $min, Role::OBJECT ); |
|
182 | + $message = (new ViolationMessage($messageKey)) |
|
183 | + ->withEntityId($predicate, Role::PREDICATE) |
|
184 | + ->withDataValue($value, Role::OBJECT); |
|
185 | + if ($min !== null && !($min instanceof NowValue)) { |
|
186 | + $message = $message->withDataValue($min, Role::OBJECT); |
|
187 | 187 | } |
188 | - if ( $max !== null && !( $max instanceof NowValue ) ) { |
|
189 | - $message = $message->withDataValue( $max, Role::OBJECT ); |
|
188 | + if ($max !== null && !($max instanceof NowValue)) { |
|
189 | + $message = $message->withDataValue($max, Role::OBJECT); |
|
190 | 190 | } |
191 | 191 | return $message; |
192 | 192 | } |
193 | 193 | |
194 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
194 | + public function checkConstraintParameters(Constraint $constraint) { |
|
195 | 195 | $constraintParameters = $constraint->getConstraintParameters(); |
196 | 196 | $exceptions = []; |
197 | 197 | try { |
198 | 198 | // we don’t have a data value here, so get the type from the property instead |
199 | 199 | // (the distinction between data type and data value type is irrelevant for 'quantity' and 'time') |
200 | - $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty( $constraint->getPropertyId() ); |
|
200 | + $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty($constraint->getPropertyId()); |
|
201 | 201 | $this->constraintParameterParser->parseRangeParameter( |
202 | 202 | $constraintParameters, |
203 | 203 | $constraint->getConstraintTypeItemId(), |
204 | 204 | $type |
205 | 205 | ); |
206 | - } catch ( ConstraintParameterException $e ) { |
|
206 | + } catch (ConstraintParameterException $e) { |
|
207 | 207 | $exceptions[] = $e; |
208 | 208 | } |
209 | 209 | return $exceptions; |