Completed
Push — master ( da1419...363a80 )
by
unknown
05:28
created
src/ConstraintCheck/Checker/DiffWithinRangeChecker.php 1 patch
Spacing   +43 added lines, -44 removed lines patch added patch discarded remove patch
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 ) ?
169
-					$this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) :
170
-					$this->rangeCheckerHelper->getDifference( $minuend, $subtrahend );
167
+			if ($subtrahend->getType() === $minuend->getType()) {
168
+				$diff = $this->rangeInYears($min, $max) ?
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/RangeChecker.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	 * @throws ConstraintParameterException
86 86
 	 * @return CheckResult
87 87
 	 */
88
-	public function checkConstraint( Context $context, Constraint $constraint ) {
89
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
90
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
88
+	public function checkConstraint(Context $context, Constraint $constraint) {
89
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
90
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
91 91
 		}
92 92
 
93 93
 		$parameters = [];
@@ -95,32 +95,32 @@  discard block
 block discarded – undo
95 95
 
96 96
 		$snak = $context->getSnak();
97 97
 
98
-		if ( !$snak instanceof PropertyValueSnak ) {
98
+		if (!$snak instanceof PropertyValueSnak) {
99 99
 			// nothing to check
100
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
100
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
101 101
 		}
102 102
 
103 103
 		$dataValue = $snak->getDataValue();
104 104
 
105
-		list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter(
105
+		list($min, $max) = $this->constraintParameterParser->parseRangeParameter(
106 106
 			$constraintParameters,
107 107
 			$constraint->getConstraintTypeItemId(),
108 108
 			$dataValue->getType()
109 109
 		);
110 110
 		$parameterKey = $dataValue->getType() === 'quantity' ? 'quantity' : 'date';
111
-		if ( $min !== null ) {
112
-			$parameters['minimum_' . $parameterKey] = [ $min ];
111
+		if ($min !== null) {
112
+			$parameters['minimum_'.$parameterKey] = [$min];
113 113
 		}
114
-		if ( $max !== null ) {
115
-			$parameters['maximum_' . $parameterKey] = [ $max ];
114
+		if ($max !== null) {
115
+			$parameters['maximum_'.$parameterKey] = [$max];
116 116
 		}
117 117
 
118
-		if ( $this->rangeCheckerHelper->getComparison( $min, $dataValue ) > 0 ||
119
-			 $this->rangeCheckerHelper->getComparison( $dataValue, $max ) > 0
118
+		if ($this->rangeCheckerHelper->getComparison($min, $dataValue) > 0 ||
119
+			 $this->rangeCheckerHelper->getComparison($dataValue, $max) > 0
120 120
 		) {
121 121
 			// at least one of $min, $max is set at this point, otherwise there could be no violation
122 122
 			$type = $dataValue->getType();
123
-			$openness = $min !== null ? ( $max !== null ? 'closed' : 'rightopen' ) : 'leftopen';
123
+			$openness = $min !== null ? ($max !== null ? 'closed' : 'rightopen') : 'leftopen';
124 124
 			// possible message keys:
125 125
 			// wbqc-violation-message-range-quantity-closed
126 126
 			// wbqc-violation-message-range-quantity-leftopen
@@ -128,14 +128,14 @@  discard block
 block discarded – undo
128 128
 			// wbqc-violation-message-range-time-closed
129 129
 			// wbqc-violation-message-range-time-leftopen
130 130
 			// wbqc-violation-message-range-time-rightopen
131
-			$message = ( new ViolationMessage( "wbqc-violation-message-range-$type-$openness" ) )
132
-				->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE )
133
-				->withDataValue( $dataValue, Role::OBJECT );
134
-			if ( $min !== null ) {
135
-				$message = $message->withDataValue( $min, Role::OBJECT );
131
+			$message = (new ViolationMessage("wbqc-violation-message-range-$type-$openness"))
132
+				->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE)
133
+				->withDataValue($dataValue, Role::OBJECT);
134
+			if ($min !== null) {
135
+				$message = $message->withDataValue($min, Role::OBJECT);
136 136
 			}
137
-			if ( $max !== null ) {
138
-				$message = $message->withDataValue( $max, Role::OBJECT );
137
+			if ($max !== null) {
138
+				$message = $message->withDataValue($max, Role::OBJECT);
139 139
 			}
140 140
 			$status = CheckResult::STATUS_VIOLATION;
141 141
 		} else {
@@ -143,22 +143,22 @@  discard block
 block discarded – undo
143 143
 			$status = CheckResult::STATUS_COMPLIANCE;
144 144
 		}
145 145
 
146
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
146
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
147 147
 	}
148 148
 
149
-	public function checkConstraintParameters( Constraint $constraint ) {
149
+	public function checkConstraintParameters(Constraint $constraint) {
150 150
 		$constraintParameters = $constraint->getConstraintParameters();
151 151
 		$exceptions = [];
152 152
 		try {
153 153
 			// we don’t have a data value here, so get the type from the property instead
154 154
 			// (the distinction between data type and data value type is irrelevant for 'quantity' and 'time')
155
-			$type = $this->propertyDataTypeLookup->getDataTypeIdForProperty( $constraint->getPropertyId() );
155
+			$type = $this->propertyDataTypeLookup->getDataTypeIdForProperty($constraint->getPropertyId());
156 156
 			$this->constraintParameterParser->parseRangeParameter(
157 157
 				$constraintParameters,
158 158
 				$constraint->getConstraintTypeItemId(),
159 159
 				$type
160 160
 			);
161
-		} catch ( ConstraintParameterException $e ) {
161
+		} catch (ConstraintParameterException $e) {
162 162
 			$exceptions[] = $e;
163 163
 		}
164 164
 		return $exceptions;
Please login to merge, or discard this patch.