Completed
Push — master ( 3baf63...df640b )
by
unknown
07:44
created
src/ConstraintCheck/Checker/ValueTypeChecker.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -98,37 +98,37 @@  discard block
 block discarded – undo
98 98
 	 * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs
99 99
 	 * @return CheckResult
100 100
 	 */
101
-	public function checkConstraint( Context $context, Constraint $constraint ) {
102
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
103
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
101
+	public function checkConstraint(Context $context, Constraint $constraint) {
102
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
103
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
104 104
 		}
105 105
 
106 106
 		$parameters = [];
107 107
 		$constraintParameters = $constraint->getConstraintParameters();
108 108
 
109
-		$classes = $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
109
+		$classes = $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId());
110 110
 		$parameters['class'] = array_map(
111
-			function( $id ) {
112
-				return new ItemId( $id );
111
+			function($id) {
112
+				return new ItemId($id);
113 113
 			},
114 114
 			$classes
115 115
 		);
116 116
 
117
-		$relation = $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
117
+		$relation = $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId());
118 118
 		$relationIds = [];
119
-		if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) {
120
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' );
119
+		if ($relation === 'instance' || $relation === 'instanceOrSubclass') {
120
+			$relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId');
121 121
 		}
122
-		if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) {
123
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
122
+		if ($relation === 'subclass' || $relation === 'instanceOrSubclass') {
123
+			$relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId');
124 124
 		}
125
-		$parameters['relation'] = [ $relation ];
125
+		$parameters['relation'] = [$relation];
126 126
 
127 127
 		$snak = $context->getSnak();
128 128
 
129
-		if ( !$snak instanceof PropertyValueSnak ) {
129
+		if (!$snak instanceof PropertyValueSnak) {
130 130
 			// nothing to check
131
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
131
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
132 132
 		}
133 133
 
134 134
 		$dataValue = $snak->getDataValue();
@@ -137,22 +137,22 @@  discard block
 block discarded – undo
137 137
 		 * error handling:
138 138
 		 *   type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid'
139 139
 		 */
140
-		if ( $dataValue->getType() !== 'wikibase-entityid' ) {
141
-			$message = wfMessage( "wbqc-violation-message-value-needed-of-type" )
140
+		if ($dataValue->getType() !== 'wikibase-entityid') {
141
+			$message = wfMessage("wbqc-violation-message-value-needed-of-type")
142 142
 				->rawParams(
143
-					$this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ),
143
+					$this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM),
144 144
 					'wikibase-entityid' // TODO is there a message for this type so we can localize it?
145 145
 				)
146 146
 				->escaped();
147
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
147
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
148 148
 		}
149 149
 		/** @var EntityIdValue $dataValue */
150 150
 
151
-		$item = $this->entityLookup->getEntity( $dataValue->getEntityId() );
151
+		$item = $this->entityLookup->getEntity($dataValue->getEntityId());
152 152
 
153
-		if ( !( $item instanceof StatementListProvider ) ) {
154
-			$message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' );
155
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
153
+		if (!($item instanceof StatementListProvider)) {
154
+			$message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist');
155
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
156 156
 		}
157 157
 
158 158
 		$statements = $item->getStatements();
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 			$classes
164 164
 		);
165 165
 
166
-		if ( $result->getBool() ) {
166
+		if ($result->getBool()) {
167 167
 			$message = null;
168 168
 			$status = CheckResult::STATUS_COMPLIANCE;
169 169
 		} else {
@@ -177,21 +177,21 @@  discard block
 block discarded – undo
177 177
 			$status = CheckResult::STATUS_VIOLATION;
178 178
 		}
179 179
 
180
-		return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) )
181
-			->withMetadata( $result->getMetadata() );
180
+		return (new CheckResult($context, $constraint, $parameters, $status, $message))
181
+			->withMetadata($result->getMetadata());
182 182
 	}
183 183
 
184
-	public function checkConstraintParameters( Constraint $constraint ) {
184
+	public function checkConstraintParameters(Constraint $constraint) {
185 185
 		$constraintParameters = $constraint->getConstraintParameters();
186 186
 		$exceptions = [];
187 187
 		try {
188
-			$this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
189
-		} catch ( ConstraintParameterException $e ) {
188
+			$this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId());
189
+		} catch (ConstraintParameterException $e) {
190 190
 			$exceptions[] = $e;
191 191
 		}
192 192
 		try {
193
-			$this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
194
-		} catch ( ConstraintParameterException $e ) {
193
+			$this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId());
194
+		} catch (ConstraintParameterException $e) {
195 195
 			$exceptions[] = $e;
196 196
 		}
197 197
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/QualifierChecker.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -47,16 +47,16 @@
 block discarded – undo
47 47
 	 *
48 48
 	 * @return CheckResult
49 49
 	 */
50
-	public function checkConstraint( Context $context, Constraint $constraint ) {
51
-		if ( $context->getType() === Context::TYPE_QUALIFIER ) {
52
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE );
50
+	public function checkConstraint(Context $context, Constraint $constraint) {
51
+		if ($context->getType() === Context::TYPE_QUALIFIER) {
52
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE);
53 53
 		} else {
54
-			$message = new ViolationMessage( 'wbqc-violation-message-qualifier' );
55
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message );
54
+			$message = new ViolationMessage('wbqc-violation-message-qualifier');
55
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message);
56 56
 		}
57 57
 	}
58 58
 
59
-	public function checkConstraintParameters( Constraint $constraint ) {
59
+	public function checkConstraintParameters(Constraint $constraint) {
60 60
 		// no parameters
61 61
 		return [];
62 62
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/MultiValueChecker.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 	 *
56 56
 	 * @return CheckResult
57 57
 	 */
58
-	public function checkConstraint( Context $context, Constraint $constraint ) {
59
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
60
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
58
+	public function checkConstraint(Context $context, Constraint $constraint) {
59
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
60
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
61 61
 		}
62 62
 
63 63
 		$propertyId = $context->getSnak()->getPropertyId();
@@ -69,18 +69,18 @@  discard block
 block discarded – undo
69 69
 			$propertyId
70 70
 		);
71 71
 
72
-		if ( $propertyCount <= 1 ) {
73
-			$message = new ViolationMessage( 'wbqc-violation-message-multi-value' );
72
+		if ($propertyCount <= 1) {
73
+			$message = new ViolationMessage('wbqc-violation-message-multi-value');
74 74
 			$status = CheckResult::STATUS_VIOLATION;
75 75
 		} else {
76 76
 			$message = null;
77 77
 			$status = CheckResult::STATUS_COMPLIANCE;
78 78
 		}
79 79
 
80
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
80
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
81 81
 	}
82 82
 
83
-	public function checkConstraintParameters( Constraint $constraint ) {
83
+	public function checkConstraintParameters(Constraint $constraint) {
84 84
 		// no parameters
85 85
 		return [];
86 86
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/ValueOnlyChecker.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -36,16 +36,16 @@
 block discarded – undo
36 36
 		];
37 37
 	}
38 38
 
39
-	public function checkConstraint( Context $context, Constraint $constraint ) {
40
-		if ( $context->getType() === Context::TYPE_STATEMENT ) {
41
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE );
39
+	public function checkConstraint(Context $context, Constraint $constraint) {
40
+		if ($context->getType() === Context::TYPE_STATEMENT) {
41
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE);
42 42
 		} else {
43
-			$message = new ViolationMessage( 'wbqc-violation-message-valueOnly' );
44
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message );
43
+			$message = new ViolationMessage('wbqc-violation-message-valueOnly');
44
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message);
45 45
 		}
46 46
 	}
47 47
 
48
-	public function checkConstraintParameters( Constraint $constraint ) {
48
+	public function checkConstraintParameters(Constraint $constraint) {
49 49
 		// no parameters
50 50
 		return [];
51 51
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/ReferenceChecker.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -36,16 +36,16 @@
 block discarded – undo
36 36
 		];
37 37
 	}
38 38
 
39
-	public function checkConstraint( Context $context, Constraint $constraint ) {
40
-		if ( $context->getType() === Context::TYPE_REFERENCE ) {
41
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE );
39
+	public function checkConstraint(Context $context, Constraint $constraint) {
40
+		if ($context->getType() === Context::TYPE_REFERENCE) {
41
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE);
42 42
 		} else {
43
-			$message = new ViolationMessage( 'wbqc-violation-message-reference' );
44
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message );
43
+			$message = new ViolationMessage('wbqc-violation-message-reference');
44
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message);
45 45
 		}
46 46
 	}
47 47
 
48
-	public function checkConstraintParameters( Constraint $constraint ) {
48
+	public function checkConstraintParameters(Constraint $constraint) {
49 49
 		// no parameters
50 50
 		return [];
51 51
 	}
Please login to merge, or discard this patch.
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,57 +135,56 @@  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';
177
-					$message = wfMessage( "wbqc-violation-message-diff-within-range$openness" );
175
+					$openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen';
176
+					$message = wfMessage("wbqc-violation-message-diff-within-range$openness");
178 177
 					$message->rawParams(
179
-						$this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ),
180
-						$this->constraintParameterRenderer->formatDataValue( $minuend, Role::OBJECT ),
181
-						$this->constraintParameterRenderer->formatEntityId( $otherSnak->getPropertyId(), Role::PREDICATE ),
182
-						$this->constraintParameterRenderer->formatDataValue( $subtrahend, Role::OBJECT )
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)
183 182
 					);
184
-					if ( $min !== null ) {
185
-						$message->rawParams( $this->constraintParameterRenderer->formatDataValue( $min, Role::OBJECT ) );
183
+					if ($min !== null) {
184
+						$message->rawParams($this->constraintParameterRenderer->formatDataValue($min, Role::OBJECT));
186 185
 					}
187
-					if ( $max !== null ) {
188
-						$message->rawParams( $this->constraintParameterRenderer->formatDataValue( $max, Role::OBJECT ) );
186
+					if ($max !== null) {
187
+						$message->rawParams($this->constraintParameterRenderer->formatDataValue($max, Role::OBJECT));
189 188
 					}
190 189
 					$message = $message->escaped();
191 190
 					$status = CheckResult::STATUS_VIOLATION;
@@ -194,19 +193,19 @@  discard block
 block discarded – undo
194 193
 					$status = CheckResult::STATUS_COMPLIANCE;
195 194
 				}
196 195
 			} else {
197
-				$message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-must-have-equal-types' );
196
+				$message = new ViolationMessage('wbqc-violation-message-diff-within-range-must-have-equal-types');
198 197
 				$status = CheckResult::STATUS_VIOLATION;
199 198
 			}
200 199
 
201
-			return new CheckResult( $context, $constraint, $parameters, $status, $message );
200
+			return new CheckResult($context, $constraint, $parameters, $status, $message);
202 201
 		}
203 202
 
204
-		$message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-property-must-exist' );
203
+		$message = new ViolationMessage('wbqc-violation-message-diff-within-range-property-must-exist');
205 204
 		$status = CheckResult::STATUS_VIOLATION;
206
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
205
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
207 206
 	}
208 207
 
209
-	public function checkConstraintParameters( Constraint $constraint ) {
208
+	public function checkConstraintParameters(Constraint $constraint) {
210 209
 		$constraintParameters = $constraint->getConstraintParameters();
211 210
 		$exceptions = [];
212 211
 		try {
@@ -215,12 +214,12 @@  discard block
 block discarded – undo
215 214
 				$constraint->getConstraintTypeItemId(),
216 215
 				'quantity'
217 216
 			);
218
-		} catch ( ConstraintParameterException $e ) {
217
+		} catch (ConstraintParameterException $e) {
219 218
 			$exceptions[] = $e;
220 219
 		}
221 220
 		try {
222
-			$this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
223
-		} catch ( ConstraintParameterException $e ) {
221
+			$this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId());
222
+		} catch (ConstraintParameterException $e) {
224 223
 			$exceptions[] = $e;
225 224
 		}
226 225
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/SingleValueChecker.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 	 *
56 56
 	 * @return CheckResult
57 57
 	 */
58
-	public function checkConstraint( Context $context, Constraint $constraint ) {
59
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
60
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
58
+	public function checkConstraint(Context $context, Constraint $constraint) {
59
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
60
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
61 61
 		}
62 62
 
63 63
 		$propertyId = $context->getSnak()->getPropertyId();
@@ -69,18 +69,18 @@  discard block
 block discarded – undo
69 69
 			$propertyId
70 70
 		);
71 71
 
72
-		if ( $propertyCount > 1 ) {
73
-			$message = new ViolationMessage( 'wbqc-violation-message-single-value' );
72
+		if ($propertyCount > 1) {
73
+			$message = new ViolationMessage('wbqc-violation-message-single-value');
74 74
 			$status = CheckResult::STATUS_VIOLATION;
75 75
 		} else {
76 76
 			$message = null;
77 77
 			$status = CheckResult::STATUS_COMPLIANCE;
78 78
 		}
79 79
 
80
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
80
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
81 81
 	}
82 82
 
83
-	public function checkConstraintParameters( Constraint $constraint ) {
83
+	public function checkConstraintParameters(Constraint $constraint) {
84 84
 		// no parameters
85 85
 		return [];
86 86
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/CommonsLinkChecker.php 1 patch
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -78,22 +78,22 @@  discard block
 block discarded – undo
78 78
 	 * @return array first element is the namespace number (default namespace for TitleParser),
79 79
 	 * second element is a string to prepend to the title before giving it to the TitleParser
80 80
 	 */
81
-	private function getCommonsNamespace( $namespace ) {
81
+	private function getCommonsNamespace($namespace) {
82 82
 		// for namespace numbers see mediawiki-config repo, wmf-config/InitialiseSettings.php,
83 83
 		// 'wgExtraNamespaces' key, 'commonswiki' subkey
84
-		switch ( $namespace ) {
84
+		switch ($namespace) {
85 85
 			case '':
86
-				return [ NS_MAIN, '' ];
86
+				return [NS_MAIN, ''];
87 87
 			case 'Creator':
88
-				return [ 100, '' ];
88
+				return [100, ''];
89 89
 			case 'TimedText':
90
-				return [ 102, '' ];
90
+				return [102, ''];
91 91
 			case 'Sequence':
92
-				return [ 104, '' ];
92
+				return [104, ''];
93 93
 			case 'Institution':
94
-				return [ 106, '' ];
94
+				return [106, ''];
95 95
 			default:
96
-				return [ NS_MAIN, $namespace . ':' ];
96
+				return [NS_MAIN, $namespace.':'];
97 97
 		}
98 98
 	}
99 99
 
@@ -106,17 +106,17 @@  discard block
 block discarded – undo
106 106
 	 * @throws ConstraintParameterException
107 107
 	 * @return CheckResult
108 108
 	 */
109
-	public function checkConstraint( Context $context, Constraint $constraint ) {
109
+	public function checkConstraint(Context $context, Constraint $constraint) {
110 110
 		$parameters = [];
111 111
 		$constraintParameters = $constraint->getConstraintParameters();
112
-		$namespace = $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
113
-		$parameters['namespace'] = [ $namespace ];
112
+		$namespace = $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId());
113
+		$parameters['namespace'] = [$namespace];
114 114
 
115 115
 		$snak = $context->getSnak();
116 116
 
117
-		if ( !$snak instanceof PropertyValueSnak ) {
117
+		if (!$snak instanceof PropertyValueSnak) {
118 118
 			// nothing to check
119
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
119
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
120 120
 		}
121 121
 
122 122
 		$dataValue = $snak->getDataValue();
@@ -126,49 +126,49 @@  discard block
 block discarded – undo
126 126
 		 *   type of $dataValue for properties with 'Commons link' constraint has to be 'string'
127 127
 		 *   parameter $namespace can be null, works for commons galleries
128 128
 		 */
129
-		if ( $dataValue->getType() !== 'string' ) {
130
-			$message = wfMessage( "wbqc-violation-message-value-needed-of-type" )
129
+		if ($dataValue->getType() !== 'string') {
130
+			$message = wfMessage("wbqc-violation-message-value-needed-of-type")
131 131
 					 ->rawParams(
132
-						 $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ),
133
-						 wfMessage( 'datatypes-type-string' )->escaped()
132
+						 $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM),
133
+						 wfMessage('datatypes-type-string')->escaped()
134 134
 					 )
135 135
 					 ->escaped();
136
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
136
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
137 137
 		}
138 138
 
139 139
 		$commonsLink = $dataValue->getValue();
140 140
 
141 141
 		try {
142
-			if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) {
143
-				throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below
142
+			if (!$this->commonsLinkIsWellFormed($commonsLink)) {
143
+				throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below
144 144
 			}
145
-			list( $defaultNamespace, $prefix ) = $this->getCommonsNamespace( $namespace );
146
-			$title = $this->titleParser->parseTitle( $prefix . $commonsLink, $defaultNamespace );
147
-			if ( $this->pageExists( $title ) ) {
145
+			list($defaultNamespace, $prefix) = $this->getCommonsNamespace($namespace);
146
+			$title = $this->titleParser->parseTitle($prefix.$commonsLink, $defaultNamespace);
147
+			if ($this->pageExists($title)) {
148 148
 				$message = null;
149 149
 				$status = CheckResult::STATUS_COMPLIANCE;
150 150
 			} else {
151
-				if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) {
152
-					throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below
151
+				if ($this->valueIncludesNamespace($commonsLink, $namespace)) {
152
+					throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below
153 153
 				} else {
154
-					$message = new ViolationMessage( 'wbqc-violation-message-commons-link-no-existent' );
154
+					$message = new ViolationMessage('wbqc-violation-message-commons-link-no-existent');
155 155
 					$status = CheckResult::STATUS_VIOLATION;
156 156
 				}
157 157
 			}
158
-		} catch ( MalformedTitleException $e ) {
159
-			$message = new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' );
158
+		} catch (MalformedTitleException $e) {
159
+			$message = new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed');
160 160
 			$status = CheckResult::STATUS_VIOLATION;
161 161
 		}
162 162
 
163
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
163
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
164 164
 	}
165 165
 
166
-	public function checkConstraintParameters( Constraint $constraint ) {
166
+	public function checkConstraintParameters(Constraint $constraint) {
167 167
 		$constraintParameters = $constraint->getConstraintParameters();
168 168
 		$exceptions = [];
169 169
 		try {
170
-			$this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
171
-		} catch ( ConstraintParameterException $e ) {
170
+			$this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId());
171
+		} catch (ConstraintParameterException $e) {
172 172
 			$exceptions[] = $e;
173 173
 		}
174 174
 		return $exceptions;
@@ -179,19 +179,19 @@  discard block
 block discarded – undo
179 179
 	 *
180 180
 	 * @return bool
181 181
 	 */
182
-	private function pageExists( TitleValue $title ) {
182
+	private function pageExists(TitleValue $title) {
183 183
 		$commonsWikiId = 'commonswiki';
184
-		if ( defined( 'MW_PHPUNIT_TEST' ) ) {
184
+		if (defined('MW_PHPUNIT_TEST')) {
185 185
 			$commonsWikiId = false;
186 186
 		}
187 187
 
188
-		$dbLoadBalancer = wfGetLB( $commonsWikiId );
188
+		$dbLoadBalancer = wfGetLB($commonsWikiId);
189 189
 		$dbConnection = $dbLoadBalancer->getConnection(
190 190
 			DB_REPLICA, false, $commonsWikiId );
191
-		$row = $dbConnection->selectRow( 'page', '*', [
191
+		$row = $dbConnection->selectRow('page', '*', [
192 192
 			'page_title' => $title->getDBkey(),
193 193
 			'page_namespace' => $title->getNamespace()
194
-		] );
194
+		]);
195 195
 
196 196
 		return $row !== false;
197 197
 	}
@@ -201,9 +201,9 @@  discard block
 block discarded – undo
201 201
 	 *
202 202
 	 * @return bool
203 203
 	 */
204
-	private function commonsLinkIsWellFormed( $commonsLink ) {
205
-		$toReplace = [ "_", "%20" ];
206
-		$compareString = trim( str_replace( $toReplace, '', $commonsLink ) );
204
+	private function commonsLinkIsWellFormed($commonsLink) {
205
+		$toReplace = ["_", "%20"];
206
+		$compareString = trim(str_replace($toReplace, '', $commonsLink));
207 207
 		return $commonsLink === $compareString;
208 208
 	}
209 209
 
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 	 *
217 217
 	 * @return bool
218 218
 	 */
219
-	private function valueIncludesNamespace( $value, $namespace ) {
219
+	private function valueIncludesNamespace($value, $namespace) {
220 220
 		return $namespace !== '' &&
221
-			strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0;
221
+			strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0;
222 222
 	}
223 223
 
224 224
 }
Please login to merge, or discard this patch.
src/Api/CheckConstraints.php 1 patch
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -77,21 +77,21 @@  discard block
 block discarded – undo
77 77
 	 *
78 78
 	 * @return self
79 79
 	 */
80
-	public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) {
80
+	public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') {
81 81
 		$repo = WikibaseRepo::getDefaultInstance();
82 82
 
83 83
 		$language = $repo->getUserLanguage();
84 84
 		$formatterOptions = new FormatterOptions();
85
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
85
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
86 86
 		$valueFormatterFactory = $repo->getValueFormatterFactory();
87
-		$valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
87
+		$valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
88 88
 
89 89
 		$languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory();
90
-		$labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language );
90
+		$labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language);
91 91
 		$entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory();
92
-		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup );
92
+		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup);
93 93
 		$entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory();
94
-		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup );
94
+		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup);
95 95
 		$config = MediaWikiServices::getInstance()->getMainConfig();
96 96
 		$titleParser = MediaWikiServices::getInstance()->getTitleParser();
97 97
 		$unitConverter = $repo->getUnitConverter();
@@ -124,10 +124,10 @@  discard block
 block discarded – undo
124 124
 			$repo->getEntityTitleLookup(),
125 125
 			$entityIdLabelFormatter,
126 126
 			$constraintParameterRenderer,
127
-			new ViolationMessageRenderer( $entityIdHtmlLinkFormatter ),
127
+			new ViolationMessageRenderer($entityIdHtmlLinkFormatter),
128 128
 			$config
129 129
 		);
130
-		if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) {
130
+		if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) {
131 131
 			$wikiPageEntityMetaDataAccessor = new WikiPageEntityMetaDataLookup(
132 132
 				$repo->getEntityNamespaceLookup()
133 133
 			);
@@ -138,12 +138,12 @@  discard block
 block discarded – undo
138 138
 				ResultsCache::getDefaultInstance(),
139 139
 				$wikiPageEntityMetaDataAccessor,
140 140
 				$entityIdParser,
141
-				$config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ),
141
+				$config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'),
142 142
 				[
143
-					$config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ),
144
-					$config->get( 'WBQualityConstraintsTypeConstraintId' ),
145
-					$config->get( 'WBQualityConstraintsValueTypeConstraintId' ),
146
-					$config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ),
143
+					$config->get('WBQualityConstraintsCommonsLinkConstraintId'),
144
+					$config->get('WBQualityConstraintsTypeConstraintId'),
145
+					$config->get('WBQualityConstraintsValueTypeConstraintId'),
146
+					$config->get('WBQualityConstraintsDistinctValuesConstraintId'),
147 147
 				],
148 148
 				$dataFactory
149 149
 			);
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 			$prefix,
156 156
 			$repo->getEntityIdParser(),
157 157
 			$repo->getStatementGuidValidator(),
158
-			$repo->getApiHelperFactory( RequestContext::getMain() ),
158
+			$repo->getApiHelperFactory(RequestContext::getMain()),
159 159
 			$resultsBuilder,
160 160
 			$dataFactory
161 161
 		);
@@ -181,11 +181,11 @@  discard block
 block discarded – undo
181 181
 		ResultsBuilder $resultsBuilder,
182 182
 		IBufferingStatsdDataFactory $dataFactory
183 183
 	) {
184
-		parent::__construct( $main, $name, $prefix );
184
+		parent::__construct($main, $name, $prefix);
185 185
 		$this->entityIdParser = $entityIdParser;
186 186
 		$this->statementGuidValidator = $statementGuidValidator;
187
-		$this->resultBuilder = $apiHelperFactory->getResultBuilder( $this );
188
-		$this->errorReporter = $apiHelperFactory->getErrorReporter( $this );
187
+		$this->resultBuilder = $apiHelperFactory->getResultBuilder($this);
188
+		$this->errorReporter = $apiHelperFactory->getErrorReporter($this);
189 189
 		$this->resultsBuilder = $resultsBuilder;
190 190
 		$this->dataFactory = $dataFactory;
191 191
 	}
@@ -200,9 +200,9 @@  discard block
 block discarded – undo
200 200
 
201 201
 		$params = $this->extractRequestParams();
202 202
 
203
-		$this->validateParameters( $params );
204
-		$entityIds = $this->parseEntityIds( $params );
205
-		$claimIds = $this->parseClaimIds( $params );
203
+		$this->validateParameters($params);
204
+		$entityIds = $this->parseEntityIds($params);
205
+		$claimIds = $this->parseClaimIds($params);
206 206
 		$constraintIDs = $params[self::PARAM_CONSTRAINT_ID];
207 207
 		$statuses = $params[self::PARAM_STATUS];
208 208
 
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 			)->getArray()
218 218
 		);
219 219
 		// ensure that result contains the given entity IDs even if they have no statements
220
-		foreach ( $entityIds as $entityId ) {
220
+		foreach ($entityIds as $entityId) {
221 221
 			$this->getResult()->addArrayType(
222
-				[ $this->getModuleName(), $entityId->getSerialization() ],
222
+				[$this->getModuleName(), $entityId->getSerialization()],
223 223
 				'assoc'
224 224
 			);
225 225
 		}
226
-		$this->resultBuilder->markSuccess( 1 );
226
+		$this->resultBuilder->markSuccess(1);
227 227
 	}
228 228
 
229 229
 	/**
@@ -231,24 +231,24 @@  discard block
 block discarded – undo
231 231
 	 *
232 232
 	 * @return EntityId[]
233 233
 	 */
234
-	private function parseEntityIds( array $params ) {
234
+	private function parseEntityIds(array $params) {
235 235
 		$ids = $params[self::PARAM_ID];
236 236
 
237
-		if ( $ids === null ) {
237
+		if ($ids === null) {
238 238
 			return [];
239
-		} elseif ( $ids === [] ) {
239
+		} elseif ($ids === []) {
240 240
 			$this->errorReporter->dieError(
241
-				'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' );
241
+				'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' );
242 242
 		}
243 243
 
244
-		return array_map( function ( $id ) {
244
+		return array_map(function($id) {
245 245
 			try {
246
-				return $this->entityIdParser->parse( $id );
247
-			} catch ( EntityIdParsingException $e ) {
246
+				return $this->entityIdParser->parse($id);
247
+			} catch (EntityIdParsingException $e) {
248 248
 				$this->errorReporter->dieError(
249
-					"Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] );
249
+					"Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] );
250 250
 			}
251
-		}, $ids );
251
+		}, $ids);
252 252
 	}
253 253
 
254 254
 	/**
@@ -256,35 +256,35 @@  discard block
 block discarded – undo
256 256
 	 *
257 257
 	 * @return string[]
258 258
 	 */
259
-	private function parseClaimIds( array $params ) {
259
+	private function parseClaimIds(array $params) {
260 260
 		$ids = $params[self::PARAM_CLAIM_ID];
261 261
 
262
-		if ( $ids === null ) {
262
+		if ($ids === null) {
263 263
 			return [];
264
-		} elseif ( $ids === [] ) {
264
+		} elseif ($ids === []) {
265 265
 			$this->errorReporter->dieError(
266
-				'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' );
266
+				'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' );
267 267
 		}
268 268
 
269
-		foreach ( $ids as $id ) {
270
-			if ( !$this->statementGuidValidator->validate( $id ) ) {
269
+		foreach ($ids as $id) {
270
+			if (!$this->statementGuidValidator->validate($id)) {
271 271
 				$this->errorReporter->dieError(
272
-					"Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] );
272
+					"Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] );
273 273
 			}
274 274
 		}
275 275
 
276 276
 		return $ids;
277 277
 	}
278 278
 
279
-	private function validateParameters( array $params ) {
280
-		if ( $params[self::PARAM_CONSTRAINT_ID] !== null
281
-			 && empty( $params[self::PARAM_CONSTRAINT_ID] )
279
+	private function validateParameters(array $params) {
280
+		if ($params[self::PARAM_CONSTRAINT_ID] !== null
281
+			 && empty($params[self::PARAM_CONSTRAINT_ID])
282 282
 		) {
283 283
 			$paramConstraintId = self::PARAM_CONSTRAINT_ID;
284 284
 			$this->errorReporter->dieError(
285 285
 				"If $paramConstraintId is specified, it must be nonempty.", 'no-data' );
286 286
 		}
287
-		if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) {
287
+		if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) {
288 288
 			$paramId = self::PARAM_ID;
289 289
 			$paramClaimId = self::PARAM_CLAIM_ID;
290 290
 			$this->errorReporter->dieError(
Please login to merge, or discard this patch.