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