Completed
Push — master ( a2235a...50f3c2 )
by
unknown
02:48
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 ) && $minuend->getType() === 'time' ?
169
-					$this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) :
170
-					$this->rangeCheckerHelper->getDifference( $minuend, $subtrahend );
167
+			if ($subtrahend->getType() === $minuend->getType()) {
168
+				$diff = $this->rangeInYears($min, $max) && $minuend->getType() === 'time' ?
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/Helper/TypeCheckerHelper.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -89,23 +89,23 @@  discard block
 block discarded – undo
89 89
 	 * @return bool
90 90
 	 * @throws OverflowException if $entitiesChecked exceeds the configured limit
91 91
 	 */
92
-	private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) {
93
-		$maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' );
92
+	private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) {
93
+		$maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities');
94 94
 		if ( ++$entitiesChecked > $maxEntities ) {
95
-			throw new OverflowException( 'Too many entities to check' );
95
+			throw new OverflowException('Too many entities to check');
96 96
 		}
97 97
 
98
-		$item = $this->entityLookup->getEntity( $comparativeClass );
99
-		if ( !( $item instanceof StatementListProvider ) ) {
98
+		$item = $this->entityLookup->getEntity($comparativeClass);
99
+		if (!($item instanceof StatementListProvider)) {
100 100
 			return false; // lookup failed, probably because item doesn't exist
101 101
 		}
102 102
 
103
-		$subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
103
+		$subclassId = $this->config->get('WBQualityConstraintsSubclassOfId');
104 104
 		/** @var Statement $statement */
105
-		foreach ( $item->getStatements()->getByPropertyId( new PropertyId( $subclassId ) ) as $statement ) {
105
+		foreach ($item->getStatements()->getByPropertyId(new PropertyId($subclassId)) as $statement) {
106 106
 			$mainSnak = $statement->getMainSnak();
107 107
 
108
-			if ( !( $this->hasCorrectType( $mainSnak ) ) ) {
108
+			if (!($this->hasCorrectType($mainSnak))) {
109 109
 				continue;
110 110
 			}
111 111
 			/** @var PropertyValueSnak $mainSnak */
@@ -114,11 +114,11 @@  discard block
 block discarded – undo
114 114
 			$dataValue = $mainSnak->getDataValue();
115 115
 			$comparativeClass = $dataValue->getEntityId();
116 116
 
117
-			if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) {
117
+			if (in_array($comparativeClass->getSerialization(), $classesToCheck)) {
118 118
 				return true;
119 119
 			}
120 120
 
121
-			if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) {
121
+			if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) {
122 122
 				return true;
123 123
 			}
124 124
 		}
@@ -139,14 +139,14 @@  discard block
 block discarded – undo
139 139
 	 * @return CachedBool
140 140
 	 * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs
141 141
 	 */
142
-	public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) {
142
+	public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) {
143 143
 		try {
144 144
 			return new CachedBool(
145
-				$this->isSubclassOf( $comparativeClass, $classesToCheck ),
145
+				$this->isSubclassOf($comparativeClass, $classesToCheck),
146 146
 				Metadata::blank()
147 147
 			);
148
-		} catch ( OverflowException $e ) {
149
-			if ( $this->sparqlHelper !== null ) {
148
+		} catch (OverflowException $e) {
149
+			if ($this->sparqlHelper !== null) {
150 150
 				$this->dataFactory->increment(
151 151
 					'wikibase.quality.constraints.sparql.typeFallback'
152 152
 				);
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 					/* withInstance = */ false
157 157
 				);
158 158
 			} else {
159
-				return new CachedBool( false, Metadata::blank() );
159
+				return new CachedBool(false, Metadata::blank());
160 160
 			}
161 161
 		}
162 162
 	}
@@ -174,13 +174,13 @@  discard block
 block discarded – undo
174 174
 	 * @return CachedBool
175 175
 	 * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs
176 176
 	 */
177
-	public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) {
177
+	public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) {
178 178
 		$metadatas = [];
179 179
 
180
-		foreach ( $this->getStatementsByPropertyIds( $statements, $relationIds ) as $statement ) {
180
+		foreach ($this->getStatementsByPropertyIds($statements, $relationIds) as $statement) {
181 181
 			$mainSnak = $statement->getMainSnak();
182 182
 
183
-			if ( !$this->hasCorrectType( $mainSnak ) ) {
183
+			if (!$this->hasCorrectType($mainSnak)) {
184 184
 				continue;
185 185
 			}
186 186
 			/** @var PropertyValueSnak $mainSnak */
@@ -189,28 +189,28 @@  discard block
 block discarded – undo
189 189
 			$dataValue = $mainSnak->getDataValue();
190 190
 			$comparativeClass = $dataValue->getEntityId();
191 191
 
192
-			if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) {
192
+			if (in_array($comparativeClass->getSerialization(), $classesToCheck)) {
193 193
 				// discard $metadatas, we know this is fresh
194
-				return new CachedBool( true, Metadata::blank() );
194
+				return new CachedBool(true, Metadata::blank());
195 195
 			}
196 196
 
197
-			$result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck );
197
+			$result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck);
198 198
 			$metadatas[] = $result->getMetadata();
199
-			if ( $result->getBool() ) {
199
+			if ($result->getBool()) {
200 200
 				return new CachedBool(
201 201
 					true,
202
-					Metadata::merge( $metadatas )
202
+					Metadata::merge($metadatas)
203 203
 				);
204 204
 			}
205 205
 		}
206 206
 
207 207
 		return new CachedBool(
208 208
 			false,
209
-			Metadata::merge( $metadatas )
209
+			Metadata::merge($metadatas)
210 210
 		);
211 211
 	}
212 212
 
213
-	private function hasCorrectType( Snak $mainSnak ) {
213
+	private function hasCorrectType(Snak $mainSnak) {
214 214
 		return $mainSnak instanceof PropertyValueSnak
215 215
 			&& $mainSnak->getDataValue()->getType() === 'wikibase-entityid';
216 216
 	}
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
 	) {
228 228
 		$statementArrays = [];
229 229
 
230
-		foreach ( $propertyIdSerializations as $propertyIdSerialization ) {
231
-			$propertyId = new PropertyId( $propertyIdSerialization );
232
-			$statementArrays[] = $statements->getByPropertyId( $propertyId )->toArray();
230
+		foreach ($propertyIdSerializations as $propertyIdSerialization) {
231
+			$propertyId = new PropertyId($propertyIdSerialization);
232
+			$statementArrays[] = $statements->getByPropertyId($propertyId)->toArray();
233 233
 		}
234 234
 
235
-		return call_user_func_array( 'array_merge', $statementArrays );
235
+		return call_user_func_array('array_merge', $statementArrays);
236 236
 	}
237 237
 
238 238
 	/**
@@ -244,10 +244,10 @@  discard block
 block discarded – undo
244 244
 	 *
245 245
 	 * @return ViolationMessage
246 246
 	 */
247
-	public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) {
247
+	public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) {
248 248
 		$classes = array_map(
249
-			function( $itemIdSerialization ) {
250
-				return new ItemId( $itemIdSerialization );
249
+			function($itemIdSerialization) {
250
+				return new ItemId($itemIdSerialization);
251 251
 			},
252 252
 			$classes
253 253
 		);
@@ -259,10 +259,10 @@  discard block
 block discarded – undo
259 259
 		// wbqc-violation-message-valueType-instance
260 260
 		// wbqc-violation-message-valueType-subclass
261 261
 		// wbqc-violation-message-valueType-instanceOrSubclass
262
-		return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) )
263
-			->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY )
264
-			->withEntityId( $entityId, Role::SUBJECT )
265
-			->withEntityIdList( $classes, Role::OBJECT );
262
+		return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation))
263
+			->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY)
264
+			->withEntityId($entityId, Role::SUBJECT)
265
+			->withEntityIdList($classes, Role::OBJECT);
266 266
 	}
267 267
 
268 268
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/ViolationMessage.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -85,17 +85,17 @@  discard block
 block discarded – undo
85 85
 	public function __construct(
86 86
 		$messageKey
87 87
 	) {
88
-		if ( strpos( $messageKey, self::MESSAGE_KEY_PREFIX ) !== 0 ) {
88
+		if (strpos($messageKey, self::MESSAGE_KEY_PREFIX) !== 0) {
89 89
 			throw new InvalidArgumentException(
90
-				'ViolationMessage key ⧼' .
91
-				$messageKey .
92
-				'⧽ should start with "' .
93
-				self::MESSAGE_KEY_PREFIX .
90
+				'ViolationMessage key ⧼'.
91
+				$messageKey.
92
+				'⧽ should start with "'.
93
+				self::MESSAGE_KEY_PREFIX.
94 94
 				'".'
95 95
 			);
96 96
 		}
97 97
 
98
-		$this->messageKeySuffix = substr( $messageKey, strlen( self::MESSAGE_KEY_PREFIX ) );
98
+		$this->messageKeySuffix = substr($messageKey, strlen(self::MESSAGE_KEY_PREFIX));
99 99
 		$this->arguments = [];
100 100
 	}
101 101
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 * @return string
105 105
 	 */
106 106
 	public function getMessageKey() {
107
-		return self::MESSAGE_KEY_PREFIX . $this->messageKeySuffix;
107
+		return self::MESSAGE_KEY_PREFIX.$this->messageKeySuffix;
108 108
 	}
109 109
 
110 110
 	/**
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 	 * @param mixed $value the value, which should match the $type
123 123
 	 * @return ViolationMessage
124 124
 	 */
125
-	private function withArgument( $type, $role, $value ) {
125
+	private function withArgument($type, $role, $value) {
126 126
 		$ret = clone $this;
127
-		$ret->arguments[] = [ 'type' => $type, 'role' => $role, 'value' => $value ];
127
+		$ret->arguments[] = ['type' => $type, 'role' => $role, 'value' => $value];
128 128
 		return $ret;
129 129
 	}
130 130
 
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 	 * @param string|null $role one of the Role::* constants
137 137
 	 * @return ViolationMessage
138 138
 	 */
139
-	public function withEntityId( EntityId $entityId, $role = null ) {
140
-		return $this->withArgument( self::TYPE_ENTITY_ID, $role, $entityId );
139
+	public function withEntityId(EntityId $entityId, $role = null) {
140
+		return $this->withArgument(self::TYPE_ENTITY_ID, $role, $entityId);
141 141
 	}
142 142
 
143 143
 	/**
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
 	 * @param string|null $role one of the Role::* constants
155 155
 	 * @return ViolationMessage
156 156
 	 */
157
-	public function withEntityIdList( array $entityIdList, $role = null ) {
158
-		return $this->withArgument( self::TYPE_ENTITY_ID_LIST, $role, $entityIdList );
157
+	public function withEntityIdList(array $entityIdList, $role = null) {
158
+		return $this->withArgument(self::TYPE_ENTITY_ID_LIST, $role, $entityIdList);
159 159
 	}
160 160
 
161 161
 	/**
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
 	 * @param string|null $role one of the Role::* constants
167 167
 	 * @return ViolationMessage
168 168
 	 */
169
-	public function withItemIdSnakValue( ItemIdSnakValue $value, $role = null ) {
170
-		return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value );
169
+	public function withItemIdSnakValue(ItemIdSnakValue $value, $role = null) {
170
+		return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value);
171 171
 	}
172 172
 
173 173
 	/**
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 	 * @param string|null $role one of the Role::* constants
185 185
 	 * @return ViolationMessage
186 186
 	 */
187
-	public function withItemIdSnakValueList( array $valueList, $role = null ) {
188
-		return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList );
187
+	public function withItemIdSnakValueList(array $valueList, $role = null) {
188
+		return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList);
189 189
 	}
190 190
 
191 191
 	/**
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 	 * @param string|null $role one of the Role::* constants
197 197
 	 * @return ViolationMessage
198 198
 	 */
199
-	public function withDataValue( DataValue $dataValue, $role = null ) {
200
-		return $this->withArgument( self::TYPE_DATA_VALUE, $role, $dataValue );
199
+	public function withDataValue(DataValue $dataValue, $role = null) {
200
+		return $this->withArgument(self::TYPE_DATA_VALUE, $role, $dataValue);
201 201
 	}
202 202
 
203 203
 	/**
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
 	 * @param string|null $role one of the Role::* constants
213 213
 	 * @return ViolationMessage
214 214
 	 */
215
-	public function withDataValueType( $dataValueType, $role = null ) {
216
-		return $this->withArgument( self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType );
215
+	public function withDataValueType($dataValueType, $role = null) {
216
+		return $this->withArgument(self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType);
217 217
 	}
218 218
 
219 219
 	/**
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
 	 * @param string|null $role one of the Role::* constants
225 225
 	 * @return ViolationMessage
226 226
 	 */
227
-	public function withInlineCode( $code, $role = null ) {
228
-		return $this->withArgument( self::TYPE_INLINE_CODE, $role, $code );
227
+	public function withInlineCode($code, $role = null) {
228
+		return $this->withArgument(self::TYPE_INLINE_CODE, $role, $code);
229 229
 	}
230 230
 
231 231
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/ViolationMessageRenderer.php 1 patch
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -54,96 +54,96 @@  discard block
 block discarded – undo
54 54
 	 * (temporarily, pre-rendered strings are allowed and returned without changes)
55 55
 	 * @return string
56 56
 	 */
57
-	public function render( $violationMessage ) {
58
-		if ( is_string( $violationMessage ) ) {
57
+	public function render($violationMessage) {
58
+		if (is_string($violationMessage)) {
59 59
 			// TODO remove this once all checkers produce ViolationMessage objects
60 60
 			return $violationMessage;
61 61
 		}
62
-		$message = new Message( $violationMessage->getMessageKey() );
63
-		foreach ( $violationMessage->getArguments() as $argument ) {
64
-			$this->renderArgument( $argument, $message );
62
+		$message = new Message($violationMessage->getMessageKey());
63
+		foreach ($violationMessage->getArguments() as $argument) {
64
+			$this->renderArgument($argument, $message);
65 65
 		}
66 66
 		return $message->escaped();
67 67
 	}
68 68
 
69
-	private function addRole( $value, $role ) {
70
-		if ( $role === null ) {
69
+	private function addRole($value, $role) {
70
+		if ($role === null) {
71 71
 			return $value;
72 72
 		}
73 73
 
74
-		return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' .
75
-			$value .
74
+		return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'.
75
+			$value.
76 76
 			'</span>';
77 77
 	}
78 78
 
79
-	private function renderArgument( array $argument, Message $message ) {
79
+	private function renderArgument(array $argument, Message $message) {
80 80
 		$type = $argument['type'];
81 81
 		$value = $argument['value'];
82 82
 		$role = $argument['role'];
83
-		switch ( $type ) {
83
+		switch ($type) {
84 84
 			case ViolationMessage::TYPE_ENTITY_ID:
85
-				$params = $this->renderEntityId( $value, $role );
85
+				$params = $this->renderEntityId($value, $role);
86 86
 				break;
87 87
 			case ViolationMessage::TYPE_ENTITY_ID_LIST:
88
-				$params = $this->renderEntityIdList( $value, $role );
88
+				$params = $this->renderEntityIdList($value, $role);
89 89
 				break;
90 90
 			case ViolationMessage::TYPE_ITEM_ID_SNAK_VALUE:
91
-				$params = $this->renderItemIdSnakValue( $value, $role );
91
+				$params = $this->renderItemIdSnakValue($value, $role);
92 92
 				break;
93 93
 			case ViolationMessage::TYPE_ITEM_ID_SNAK_VALUE_LIST:
94
-				$params = $this->renderItemIdSnakValueList( $value, $role );
94
+				$params = $this->renderItemIdSnakValueList($value, $role);
95 95
 				break;
96 96
 			case ViolationMessage::TYPE_DATA_VALUE:
97
-				$params = $this->renderDataValue( $value, $role );
97
+				$params = $this->renderDataValue($value, $role);
98 98
 				break;
99 99
 			case ViolationMessage::TYPE_DATA_VALUE_TYPE:
100
-				$params = $this->renderDataValueType( $value, $role );
100
+				$params = $this->renderDataValueType($value, $role);
101 101
 				break;
102 102
 			case ViolationMessage::TYPE_INLINE_CODE:
103
-				$params = $this->renderInlineCode( $value, $role );
103
+				$params = $this->renderInlineCode($value, $role);
104 104
 				break;
105 105
 			default:
106 106
 				throw new InvalidArgumentException(
107
-					'Unknown ViolationMessage argument type ' . $type . '!'
107
+					'Unknown ViolationMessage argument type '.$type.'!'
108 108
 				);
109 109
 		}
110
-		$message->params( $params );
110
+		$message->params($params);
111 111
 	}
112 112
 
113
-	private function renderList( array $list, $role, callable $render ) {
114
-		if ( $list === [] ) {
113
+	private function renderList(array $list, $role, callable $render) {
114
+		if ($list === []) {
115 115
 			return [
116
-				Message::numParam( 0 ),
117
-				Message::rawParam( '<ul></ul>' ),
116
+				Message::numParam(0),
117
+				Message::rawParam('<ul></ul>'),
118 118
 			];
119 119
 		}
120 120
 
121
-		if ( count( $list ) > $this->maxListLength ) {
122
-			$list = array_slice( $list, 0, $this->maxListLength );
121
+		if (count($list) > $this->maxListLength) {
122
+			$list = array_slice($list, 0, $this->maxListLength);
123 123
 			$truncated = true;
124 124
 		}
125 125
 
126 126
 		$renderedParams = array_map(
127 127
 			$render,
128 128
 			$list,
129
-			array_fill( 0, count( $list ), $role )
129
+			array_fill(0, count($list), $role)
130 130
 		);
131 131
 		$renderedElements = array_map(
132
-			function ( $param ) {
132
+			function($param) {
133 133
 				return $param['raw'];
134 134
 			},
135 135
 			$renderedParams
136 136
 		);
137
-		if ( isset( $truncated ) ) {
138
-			$renderedElements[] = wfMessage( 'ellipsis' )->escaped();
137
+		if (isset($truncated)) {
138
+			$renderedElements[] = wfMessage('ellipsis')->escaped();
139 139
 		}
140 140
 
141 141
 		return array_merge(
142 142
 			[
143
-				Message::numParam( count( $list ) ),
143
+				Message::numParam(count($list)),
144 144
 				Message::rawParam(
145
-					'<ul><li>' .
146
-					implode( '</li><li>', $renderedElements ) .
145
+					'<ul><li>'.
146
+					implode('</li><li>', $renderedElements).
147 147
 					'</li></ul>'
148 148
 				),
149 149
 			],
@@ -151,35 +151,35 @@  discard block
 block discarded – undo
151 151
 		);
152 152
 	}
153 153
 
154
-	private function renderEntityId( EntityId $entityId, $role ) {
155
-		return Message::rawParam( $this->addRole(
156
-			$this->entityIdFormatter->formatEntityId( $entityId ),
154
+	private function renderEntityId(EntityId $entityId, $role) {
155
+		return Message::rawParam($this->addRole(
156
+			$this->entityIdFormatter->formatEntityId($entityId),
157 157
 			$role
158
-		) );
158
+		));
159 159
 	}
160 160
 
161
-	private function renderEntityIdList( array $entityIdList, $role ) {
162
-		return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] );
161
+	private function renderEntityIdList(array $entityIdList, $role) {
162
+		return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']);
163 163
 	}
164 164
 
165
-	private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) {
166
-		switch ( true ) {
165
+	private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) {
166
+		switch (true) {
167 167
 			case $value->isValue():
168
-				return $this->renderEntityId( $value->getItemId(), $role );
168
+				return $this->renderEntityId($value->getItemId(), $role);
169 169
 			case $value->isSomeValue():
170
-				return Message::rawParam( $this->addRole(
171
-					'<span class="wikibase-snakview-variation-somevaluesnak">' .
172
-						wfMessage( 'wikibase-snakview-snaktypeselector-somevalue' )->escaped() .
170
+				return Message::rawParam($this->addRole(
171
+					'<span class="wikibase-snakview-variation-somevaluesnak">'.
172
+						wfMessage('wikibase-snakview-snaktypeselector-somevalue')->escaped().
173 173
 						'</span>',
174 174
 					$role
175
-				) );
175
+				));
176 176
 			case $value->isNoValue():
177
-				return Message::rawParam( $this->addRole(
178
-					'<span class="wikibase-snakview-variation-novaluesnak">' .
179
-						wfMessage( 'wikibase-snakview-snaktypeselector-novalue' )->escaped() .
177
+				return Message::rawParam($this->addRole(
178
+					'<span class="wikibase-snakview-variation-novaluesnak">'.
179
+						wfMessage('wikibase-snakview-snaktypeselector-novalue')->escaped().
180 180
 						'</span>',
181 181
 					$role
182
-				) );
182
+				));
183 183
 			default:
184 184
 				// @codeCoverageIgnoreStart
185 185
 				throw new LogicException(
@@ -189,43 +189,43 @@  discard block
 block discarded – undo
189 189
 		}
190 190
 	}
191 191
 
192
-	private function renderItemIdSnakValueList( array $valueList, $role ) {
193
-		return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] );
192
+	private function renderItemIdSnakValueList(array $valueList, $role) {
193
+		return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']);
194 194
 	}
195 195
 
196
-	private function renderDataValue( DataValue $dataValue, $role ) {
197
-		return Message::rawParam( $this->addRole(
198
-			$this->dataValueFormatter->format( $dataValue ),
196
+	private function renderDataValue(DataValue $dataValue, $role) {
197
+		return Message::rawParam($this->addRole(
198
+			$this->dataValueFormatter->format($dataValue),
199 199
 			$role
200
-		) );
200
+		));
201 201
 	}
202 202
 
203
-	private function renderDataValueType( $dataValueType, $role ) {
203
+	private function renderDataValueType($dataValueType, $role) {
204 204
 		$messageKeys = [
205 205
 			'string' => 'datatypes-type-string',
206 206
 			'monolingualtext' => 'datatypes-monolingualtext',
207 207
 			'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid',
208 208
 		];
209 209
 
210
-		if ( array_key_exists( $dataValueType, $messageKeys ) ) {
211
-			return Message::rawParam( $this->addRole(
212
-				wfMessage( $messageKeys[$dataValueType] )->escaped(),
210
+		if (array_key_exists($dataValueType, $messageKeys)) {
211
+			return Message::rawParam($this->addRole(
212
+				wfMessage($messageKeys[$dataValueType])->escaped(),
213 213
 				$role
214
-			) );
214
+			));
215 215
 		} else {
216 216
 			// @codeCoverageIgnoreStart
217 217
 			throw new LogicException(
218
-				'Unknown data value type ' . $dataValueType
218
+				'Unknown data value type '.$dataValueType
219 219
 			);
220 220
 			// @codeCoverageIgnoreEnd
221 221
 		}
222 222
 	}
223 223
 
224
-	private function renderInlineCode( $code, $role ) {
225
-		return Message::rawParam( $this->addRole(
226
-			'<code>' . htmlspecialchars( $code ) . '</code>',
224
+	private function renderInlineCode($code, $role) {
225
+		return Message::rawParam($this->addRole(
226
+			'<code>'.htmlspecialchars($code).'</code>',
227 227
 			$role
228
-		) );
228
+		));
229 229
 	}
230 230
 
231 231
 }
Please login to merge, or discard this patch.