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