Completed
Push — master ( 363ad0...db1fd4 )
by
unknown
01:57
created
src/ConstraintCheck/Checker/EntityTypeChecker.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 		];
52 52
 	}
53 53
 
54
-	public function checkConstraint( Context $context, Constraint $constraint ) {
55
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
56
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
54
+	public function checkConstraint(Context $context, Constraint $constraint) {
55
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
56
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
57 57
 		}
58 58
 
59 59
 		$constraintParameters = $constraint->getConstraintParameters();
@@ -65,10 +65,10 @@  discard block
 block discarded – undo
65 65
 			'item' => $entityTypes->getEntityTypes(),
66 66
 		];
67 67
 
68
-		if ( !in_array( $context->getEntity()->getType(), $entityTypes->getEntityTypes() ) ) {
69
-			$message = ( new ViolationMessage( 'wbqc-violation-message-entityType' ) )
70
-				->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY )
71
-				->withEntityIdList( $entityTypes->getEntityTypeItemIds(), Role::CONSTRAINT_PARAMETER_VALUE );
68
+		if (!in_array($context->getEntity()->getType(), $entityTypes->getEntityTypes())) {
69
+			$message = (new ViolationMessage('wbqc-violation-message-entityType'))
70
+				->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY)
71
+				->withEntityIdList($entityTypes->getEntityTypeItemIds(), Role::CONSTRAINT_PARAMETER_VALUE);
72 72
 
73 73
 			return new CheckResult(
74 74
 				$context,
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
 			);
80 80
 		}
81 81
 
82
-		return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
82
+		return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
83 83
 	}
84 84
 
85
-	public function checkConstraintParameters( Constraint $constraint ) {
85
+	public function checkConstraintParameters(Constraint $constraint) {
86 86
 		$constraintParameters = $constraint->getConstraintParameters();
87 87
 		$exceptions = [];
88 88
 		try {
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 				$constraintParameters,
91 91
 				$constraint->getConstraintTypeItemId()
92 92
 			);
93
-		} catch ( ConstraintParameterException $e ) {
93
+		} catch (ConstraintParameterException $e) {
94 94
 			$exceptions[] = $e;
95 95
 		}
96 96
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/DiffWithinRangeChecker.php 1 patch
Spacing   +41 added lines, -42 removed lines patch added patch discarded remove patch
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
 	 * @throws ConstraintParameterException
77 77
 	 * @return array [ DataValue|null $min, DataValue|null $max, PropertyId $property, array $parameters ]
78 78
 	 */
79
-	private function parseConstraintParameters( Constraint $constraint ) {
80
-		list( $min, $max ) = $this->constraintParameterParser->parseQuantityRangeParameter(
79
+	private function parseConstraintParameters(Constraint $constraint) {
80
+		list($min, $max) = $this->constraintParameterParser->parseQuantityRangeParameter(
81 81
 			$constraint->getConstraintParameters(),
82 82
 			$constraint->getConstraintTypeItemId()
83 83
 		);
@@ -87,15 +87,15 @@  discard block
 block discarded – undo
87 87
 		);
88 88
 
89 89
 		$parameters = [];
90
-		if ( $min !== null ) {
91
-			$parameters['minimum_quantity'] = [ $min ];
90
+		if ($min !== null) {
91
+			$parameters['minimum_quantity'] = [$min];
92 92
 		}
93
-		if ( $max !== null ) {
94
-			$parameters['maximum_quantity'] = [ $max ];
93
+		if ($max !== null) {
94
+			$parameters['maximum_quantity'] = [$max];
95 95
 		}
96
-		$parameters['property'] = [ $property ];
96
+		$parameters['property'] = [$property];
97 97
 
98
-		return [ $min, $max, $property, $parameters ];
98
+		return [$min, $max, $property, $parameters];
99 99
 	}
100 100
 
101 101
 	/**
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
 	 *
106 106
 	 * @return bool
107 107
 	 */
108
-	private function rangeInYears( $min, $max ) {
109
-		$yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' );
108
+	private function rangeInYears($min, $max) {
109
+		$yearUnit = $this->config->get('WBQualityConstraintsYearUnit');
110 110
 
111
-		if ( $min !== null && $min->getUnit() === $yearUnit ) {
111
+		if ($min !== null && $min->getUnit() === $yearUnit) {
112 112
 			return true;
113 113
 		}
114
-		if ( $max !== null && $max->getUnit() === $yearUnit ) {
114
+		if ($max !== null && $max->getUnit() === $yearUnit) {
115 115
 			return true;
116 116
 		}
117 117
 
@@ -127,59 +127,58 @@  discard block
 block discarded – undo
127 127
 	 * @throws ConstraintParameterException
128 128
 	 * @return CheckResult
129 129
 	 */
130
-	public function checkConstraint( Context $context, Constraint $constraint ) {
131
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
132
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
130
+	public function checkConstraint(Context $context, Constraint $constraint) {
131
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
132
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
133 133
 		}
134 134
 
135 135
 		$parameters = [];
136 136
 
137 137
 		$snak = $context->getSnak();
138 138
 
139
-		if ( !$snak instanceof PropertyValueSnak ) {
139
+		if (!$snak instanceof PropertyValueSnak) {
140 140
 			// nothing to check
141
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
141
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
142 142
 		}
143 143
 
144 144
 		$minuend = $snak->getDataValue();
145 145
 
146 146
 		/** @var PropertyId $property */
147
-		list( $min, $max, $property, $parameters ) = $this->parseConstraintParameters( $constraint );
147
+		list($min, $max, $property, $parameters) = $this->parseConstraintParameters($constraint);
148 148
 
149 149
 		// checks only the first occurrence of the referenced property
150
-		foreach ( $context->getSnakGroup( Context::GROUP_NON_DEPRECATED ) as $otherSnak ) {
150
+		foreach ($context->getSnakGroup(Context::GROUP_NON_DEPRECATED) as $otherSnak) {
151 151
 			if (
152
-				!$property->equals( $otherSnak->getPropertyId() ) ||
152
+				!$property->equals($otherSnak->getPropertyId()) ||
153 153
 				!$otherSnak instanceof PropertyValueSnak
154 154
 			) {
155 155
 				continue;
156 156
 			}
157 157
 
158 158
 			$subtrahend = $otherSnak->getDataValue();
159
-			if ( $subtrahend->getType() === $minuend->getType() ) {
160
-				$diff = $this->rangeInYears( $min, $max ) && $minuend->getType() === 'time' ?
161
-					$this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) :
162
-					$this->rangeCheckerHelper->getDifference( $minuend, $subtrahend );
159
+			if ($subtrahend->getType() === $minuend->getType()) {
160
+				$diff = $this->rangeInYears($min, $max) && $minuend->getType() === 'time' ?
161
+					$this->rangeCheckerHelper->getDifferenceInYears($minuend, $subtrahend) : $this->rangeCheckerHelper->getDifference($minuend, $subtrahend);
163 162
 
164
-				if ( $this->rangeCheckerHelper->getComparison( $min, $diff ) > 0 ||
165
-					$this->rangeCheckerHelper->getComparison( $diff, $max ) > 0
163
+				if ($this->rangeCheckerHelper->getComparison($min, $diff) > 0 ||
164
+					$this->rangeCheckerHelper->getComparison($diff, $max) > 0
166 165
 				) {
167 166
 					// at least one of $min, $max is set at this point, otherwise there could be no violation
168
-					$openness = $min !== null ? ( $max !== null ? '' : '-rightopen' ) : '-leftopen';
167
+					$openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen';
169 168
 					// possible message keys:
170 169
 					// wbqc-violation-message-diff-within-range
171 170
 					// wbqc-violation-message-diff-within-range-leftopen
172 171
 					// wbqc-violation-message-diff-within-range-rightopen
173
-					$message = ( new ViolationMessage( "wbqc-violation-message-diff-within-range$openness" ) )
174
-						->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE )
175
-						->withDataValue( $minuend, Role::OBJECT )
176
-						->withEntityId( $otherSnak->getPropertyId(), Role::PREDICATE )
177
-						->withDataValue( $subtrahend, Role::OBJECT );
178
-					if ( $min !== null ) {
179
-						$message = $message->withDataValue( $min, Role::OBJECT );
172
+					$message = (new ViolationMessage("wbqc-violation-message-diff-within-range$openness"))
173
+						->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE)
174
+						->withDataValue($minuend, Role::OBJECT)
175
+						->withEntityId($otherSnak->getPropertyId(), Role::PREDICATE)
176
+						->withDataValue($subtrahend, Role::OBJECT);
177
+					if ($min !== null) {
178
+						$message = $message->withDataValue($min, Role::OBJECT);
180 179
 					}
181
-					if ( $max !== null ) {
182
-						$message = $message->withDataValue( $max, Role::OBJECT );
180
+					if ($max !== null) {
181
+						$message = $message->withDataValue($max, Role::OBJECT);
183 182
 					}
184 183
 					$status = CheckResult::STATUS_VIOLATION;
185 184
 				} else {
@@ -187,17 +186,17 @@  discard block
 block discarded – undo
187 186
 					$status = CheckResult::STATUS_COMPLIANCE;
188 187
 				}
189 188
 			} else {
190
-				$message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-must-have-equal-types' );
189
+				$message = new ViolationMessage('wbqc-violation-message-diff-within-range-must-have-equal-types');
191 190
 				$status = CheckResult::STATUS_VIOLATION;
192 191
 			}
193 192
 
194
-			return new CheckResult( $context, $constraint, $parameters, $status, $message );
193
+			return new CheckResult($context, $constraint, $parameters, $status, $message);
195 194
 		}
196 195
 
197
-		return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
196
+		return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
198 197
 	}
199 198
 
200
-	public function checkConstraintParameters( Constraint $constraint ) {
199
+	public function checkConstraintParameters(Constraint $constraint) {
201 200
 		$constraintParameters = $constraint->getConstraintParameters();
202 201
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
203 202
 		$exceptions = [];
@@ -206,7 +205,7 @@  discard block
 block discarded – undo
206 205
 				$constraintParameters,
207 206
 				$constraintTypeItemId
208 207
 			);
209
-		} catch ( ConstraintParameterException $e ) {
208
+		} catch (ConstraintParameterException $e) {
210 209
 			$exceptions[] = $e;
211 210
 		}
212 211
 		try {
@@ -214,7 +213,7 @@  discard block
 block discarded – undo
214 213
 				$constraintParameters,
215 214
 				$constraintTypeItemId
216 215
 			);
217
-		} catch ( ConstraintParameterException $e ) {
216
+		} catch (ConstraintParameterException $e) {
218 217
 			$exceptions[] = $e;
219 218
 		}
220 219
 		return $exceptions;
Please login to merge, or discard this patch.