Completed
Push — master ( 97f202...77971f )
by
unknown
02:40
created
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/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, $valueFormatter, $config ),
127
+			new ViolationMessageRenderer($entityIdHtmlLinkFormatter, $valueFormatter, $config),
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.
src/ConstraintCheck/Message/ViolationMessage.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -103,17 +103,17 @@  discard block
 block discarded – undo
103 103
 	public function __construct(
104 104
 		$messageKey
105 105
 	) {
106
-		if ( strpos( $messageKey, self::MESSAGE_KEY_PREFIX ) !== 0 ) {
106
+		if (strpos($messageKey, self::MESSAGE_KEY_PREFIX) !== 0) {
107 107
 			throw new InvalidArgumentException(
108
-				'ViolationMessage key ⧼' .
109
-				$messageKey .
110
-				'⧽ should start with "' .
111
-				self::MESSAGE_KEY_PREFIX .
108
+				'ViolationMessage key ⧼'.
109
+				$messageKey.
110
+				'⧽ should start with "'.
111
+				self::MESSAGE_KEY_PREFIX.
112 112
 				'".'
113 113
 			);
114 114
 		}
115 115
 
116
-		$this->messageKeySuffix = substr( $messageKey, strlen( self::MESSAGE_KEY_PREFIX ) );
116
+		$this->messageKeySuffix = substr($messageKey, strlen(self::MESSAGE_KEY_PREFIX));
117 117
 		$this->arguments = [];
118 118
 	}
119 119
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 * @return string
123 123
 	 */
124 124
 	public function getMessageKey() {
125
-		return self::MESSAGE_KEY_PREFIX . $this->messageKeySuffix;
125
+		return self::MESSAGE_KEY_PREFIX.$this->messageKeySuffix;
126 126
 	}
127 127
 
128 128
 	/**
@@ -140,9 +140,9 @@  discard block
 block discarded – undo
140 140
 	 * @param mixed $value the value, which should match the $type
141 141
 	 * @return ViolationMessage
142 142
 	 */
143
-	private function withArgument( $type, $role, $value ) {
143
+	private function withArgument($type, $role, $value) {
144 144
 		$ret = clone $this;
145
-		$ret->arguments[] = [ 'type' => $type, 'role' => $role, 'value' => $value ];
145
+		$ret->arguments[] = ['type' => $type, 'role' => $role, 'value' => $value];
146 146
 		return $ret;
147 147
 	}
148 148
 
@@ -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 withEntityId( EntityId $entityId, $role = null ) {
158
-		return $this->withArgument( self::TYPE_ENTITY_ID, $role, $entityId );
157
+	public function withEntityId(EntityId $entityId, $role = null) {
158
+		return $this->withArgument(self::TYPE_ENTITY_ID, $role, $entityId);
159 159
 	}
160 160
 
161 161
 	/**
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 	 * @param string|null $role one of the Role::* constants
173 173
 	 * @return ViolationMessage
174 174
 	 */
175
-	public function withEntityIdList( array $entityIdList, $role = null ) {
176
-		return $this->withArgument( self::TYPE_ENTITY_ID_LIST, $role, $entityIdList );
175
+	public function withEntityIdList(array $entityIdList, $role = null) {
176
+		return $this->withArgument(self::TYPE_ENTITY_ID_LIST, $role, $entityIdList);
177 177
 	}
178 178
 
179 179
 	/**
@@ -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 withItemIdSnakValue( ItemIdSnakValue $value, $role = null ) {
188
-		return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value );
187
+	public function withItemIdSnakValue(ItemIdSnakValue $value, $role = null) {
188
+		return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value);
189 189
 	}
190 190
 
191 191
 	/**
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
 	 * @param string|null $role one of the Role::* constants
203 203
 	 * @return ViolationMessage
204 204
 	 */
205
-	public function withItemIdSnakValueList( array $valueList, $role = null ) {
206
-		return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList );
205
+	public function withItemIdSnakValueList(array $valueList, $role = null) {
206
+		return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList);
207 207
 	}
208 208
 
209 209
 	/**
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
 	 * @param string|null $role one of the Role::* constants
215 215
 	 * @return ViolationMessage
216 216
 	 */
217
-	public function withDataValue( DataValue $dataValue, $role = null ) {
218
-		return $this->withArgument( self::TYPE_DATA_VALUE, $role, $dataValue );
217
+	public function withDataValue(DataValue $dataValue, $role = null) {
218
+		return $this->withArgument(self::TYPE_DATA_VALUE, $role, $dataValue);
219 219
 	}
220 220
 
221 221
 	/**
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
 	 * @param string|null $role one of the Role::* constants
231 231
 	 * @return ViolationMessage
232 232
 	 */
233
-	public function withDataValueType( $dataValueType, $role = null ) {
234
-		return $this->withArgument( self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType );
233
+	public function withDataValueType($dataValueType, $role = null) {
234
+		return $this->withArgument(self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType);
235 235
 	}
236 236
 
237 237
 	/**
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
 	 * @param string|null $role one of the Role::* constants
243 243
 	 * @return ViolationMessage
244 244
 	 */
245
-	public function withInlineCode( $code, $role = null ) {
246
-		return $this->withArgument( self::TYPE_INLINE_CODE, $role, $code );
245
+	public function withInlineCode($code, $role = null) {
246
+		return $this->withArgument(self::TYPE_INLINE_CODE, $role, $code);
247 247
 	}
248 248
 
249 249
 	/**
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
 	 * @param string|null $role one of the Role::* constants
255 255
 	 * @return ViolationMessage
256 256
 	 */
257
-	public function withConstraintScope( $scope, $role = null ) {
258
-		return $this->withArgument( self::TYPE_CONSTRAINT_SCOPE, $role, $scope );
257
+	public function withConstraintScope($scope, $role = null) {
258
+		return $this->withArgument(self::TYPE_CONSTRAINT_SCOPE, $role, $scope);
259 259
 	}
260 260
 
261 261
 	/**
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
 	 * @param string|null $role one of the Role::* constants
267 267
 	 * @return ViolationMessage
268 268
 	 */
269
-	public function withConstraintScopeList( array $scopeList, $role = null ) {
270
-		return $this->withArgument( self::TYPE_CONSTRAINT_SCOPE_LIST, $role, $scopeList );
269
+	public function withConstraintScopeList(array $scopeList, $role = null) {
270
+		return $this->withArgument(self::TYPE_CONSTRAINT_SCOPE_LIST, $role, $scopeList);
271 271
 	}
272 272
 
273 273
 	/**
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
 	 * @param string $languageCode
283 283
 	 * @return ViolationMessage
284 284
 	 */
285
-	public function withLanguage( $languageCode ) {
286
-		return $this->withArgument( self::TYPE_LANGUAGE, null, $languageCode );
285
+	public function withLanguage($languageCode) {
286
+		return $this->withArgument(self::TYPE_LANGUAGE, null, $languageCode);
287 287
 	}
288 288
 
289 289
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/ViolationMessageRenderer.php 1 patch
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -66,21 +66,21 @@  discard block
 block discarded – undo
66 66
 	 * (temporarily, pre-rendered strings are allowed and returned without changes)
67 67
 	 * @return string
68 68
 	 */
69
-	public function render( $violationMessage ) {
70
-		if ( is_string( $violationMessage ) ) {
69
+	public function render($violationMessage) {
70
+		if (is_string($violationMessage)) {
71 71
 			// TODO remove this once all checkers produce ViolationMessage objects
72 72
 			return $violationMessage;
73 73
 		}
74 74
 
75 75
 		$messageKey = $violationMessage->getMessageKey();
76
-		$paramsLists = [ [] ];
77
-		foreach ( $violationMessage->getArguments() as $argument ) {
78
-			$params = $this->renderArgument( $argument );
76
+		$paramsLists = [[]];
77
+		foreach ($violationMessage->getArguments() as $argument) {
78
+			$params = $this->renderArgument($argument);
79 79
 			$paramsLists[] = $params;
80 80
 		}
81
-		$allParams = call_user_func_array( 'array_merge', $paramsLists );
82
-		return ( new Message( $messageKey ) )
83
-			->params( $allParams )
81
+		$allParams = call_user_func_array('array_merge', $paramsLists);
82
+		return (new Message($messageKey))
83
+			->params($allParams)
84 84
 			->escaped();
85 85
 	}
86 86
 
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
 	 * @param string|null $role one of the Role::* constants
90 90
 	 * @return string HTML
91 91
 	 */
92
-	private function addRole( $value, $role ) {
93
-		if ( $role === null ) {
92
+	private function addRole($value, $role) {
93
+		if ($role === null) {
94 94
 			return $value;
95 95
 		}
96 96
 
97
-		return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' .
98
-			$value .
97
+		return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'.
98
+			$value.
99 99
 			'</span>';
100 100
 	}
101 101
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	 * @param array $argument
104 104
 	 * @return array[] params (for Message::params)
105 105
 	 */
106
-	private function renderArgument( array $argument ) {
106
+	private function renderArgument(array $argument) {
107 107
 		$methods = [
108 108
 			ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId',
109 109
 			ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList',
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
 		$value = $argument['value'];
122 122
 		$role = $argument['role'];
123 123
 
124
-		if ( array_key_exists( $type, $methods ) ) {
124
+		if (array_key_exists($type, $methods)) {
125 125
 			$method = $methods[$type];
126
-			$params = $this->$method( $value, $role );
126
+			$params = $this->$method($value, $role);
127 127
 		} else {
128 128
 			throw new InvalidArgumentException(
129
-				'Unknown ViolationMessage argument type ' . $type . '!'
129
+				'Unknown ViolationMessage argument type '.$type.'!'
130 130
 			);
131 131
 		}
132 132
 
@@ -140,46 +140,46 @@  discard block
 block discarded – undo
140 140
 	 * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ])
141 141
 	 * @return array[] list of parameters as accepted by Message::params()
142 142
 	 */
143
-	private function renderList( array $list, $role, callable $render ) {
144
-		if ( $list === [] ) {
143
+	private function renderList(array $list, $role, callable $render) {
144
+		if ($list === []) {
145 145
 			return [
146
-				Message::numParam( 0 ),
147
-				Message::rawParam( '<ul></ul>' ),
146
+				Message::numParam(0),
147
+				Message::rawParam('<ul></ul>'),
148 148
 			];
149 149
 		}
150 150
 
151
-		if ( count( $list ) > $this->maxListLength ) {
152
-			$list = array_slice( $list, 0, $this->maxListLength );
151
+		if (count($list) > $this->maxListLength) {
152
+			$list = array_slice($list, 0, $this->maxListLength);
153 153
 			$truncated = true;
154 154
 		}
155 155
 
156 156
 		$renderedParamsLists = array_map(
157 157
 			$render,
158 158
 			$list,
159
-			array_fill( 0, count( $list ), $role )
159
+			array_fill(0, count($list), $role)
160 160
 		);
161 161
 		$renderedParams = array_map(
162
-			function ( $params ) {
162
+			function($params) {
163 163
 				return $params[0];
164 164
 			},
165 165
 			$renderedParamsLists
166 166
 		);
167 167
 		$renderedElements = array_map(
168
-			function ( $param ) {
168
+			function($param) {
169 169
 				return $param['raw'];
170 170
 			},
171 171
 			$renderedParams
172 172
 		);
173
-		if ( isset( $truncated ) ) {
174
-			$renderedElements[] = wfMessage( 'ellipsis' )->escaped();
173
+		if (isset($truncated)) {
174
+			$renderedElements[] = wfMessage('ellipsis')->escaped();
175 175
 		}
176 176
 
177 177
 		return array_merge(
178 178
 			[
179
-				Message::numParam( count( $list ) ),
179
+				Message::numParam(count($list)),
180 180
 				Message::rawParam(
181
-					'<ul><li>' .
182
-					implode( '</li><li>', $renderedElements ) .
181
+					'<ul><li>'.
182
+					implode('</li><li>', $renderedElements).
183 183
 					'</li></ul>'
184 184
 				),
185 185
 			],
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
 	 * @param string|null $role one of the Role::* constants
193 193
 	 * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
194 194
 	 */
195
-	private function renderEntityId( EntityId $entityId, $role ) {
196
-		return [ Message::rawParam( $this->addRole(
197
-			$this->entityIdFormatter->formatEntityId( $entityId ),
195
+	private function renderEntityId(EntityId $entityId, $role) {
196
+		return [Message::rawParam($this->addRole(
197
+			$this->entityIdFormatter->formatEntityId($entityId),
198 198
 			$role
199
-		) ) ];
199
+		))];
200 200
 	}
201 201
 
202 202
 	/**
@@ -204,8 +204,8 @@  discard block
 block discarded – undo
204 204
 	 * @param string|null $role one of the Role::* constants
205 205
 	 * @return array[] list of parameters as accepted by Message::params()
206 206
 	 */
207
-	private function renderEntityIdList( array $entityIdList, $role ) {
208
-		return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] );
207
+	private function renderEntityIdList(array $entityIdList, $role) {
208
+		return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']);
209 209
 	}
210 210
 
211 211
 	/**
@@ -213,24 +213,24 @@  discard block
 block discarded – undo
213 213
 	 * @param string|null $role one of the Role::* constants
214 214
 	 * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
215 215
 	 */
216
-	private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) {
217
-		switch ( true ) {
216
+	private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) {
217
+		switch (true) {
218 218
 			case $value->isValue():
219
-				return $this->renderEntityId( $value->getItemId(), $role );
219
+				return $this->renderEntityId($value->getItemId(), $role);
220 220
 			case $value->isSomeValue():
221
-				return [ Message::rawParam( $this->addRole(
222
-					'<span class="wikibase-snakview-variation-somevaluesnak">' .
223
-						wfMessage( 'wikibase-snakview-snaktypeselector-somevalue' )->escaped() .
221
+				return [Message::rawParam($this->addRole(
222
+					'<span class="wikibase-snakview-variation-somevaluesnak">'.
223
+						wfMessage('wikibase-snakview-snaktypeselector-somevalue')->escaped().
224 224
 						'</span>',
225 225
 					$role
226
-				) ) ];
226
+				))];
227 227
 			case $value->isNoValue():
228
-				return [ Message::rawParam( $this->addRole(
229
-					'<span class="wikibase-snakview-variation-novaluesnak">' .
230
-						wfMessage( 'wikibase-snakview-snaktypeselector-novalue' )->escaped() .
228
+				return [Message::rawParam($this->addRole(
229
+					'<span class="wikibase-snakview-variation-novaluesnak">'.
230
+						wfMessage('wikibase-snakview-snaktypeselector-novalue')->escaped().
231 231
 						'</span>',
232 232
 					$role
233
-				) ) ];
233
+				))];
234 234
 			default:
235 235
 				// @codeCoverageIgnoreStart
236 236
 				throw new LogicException(
@@ -245,8 +245,8 @@  discard block
 block discarded – undo
245 245
 	 * @param string|null $role one of the Role::* constants
246 246
 	 * @return array[] list of parameters as accepted by Message::params()
247 247
 	 */
248
-	private function renderItemIdSnakValueList( array $valueList, $role ) {
249
-		return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] );
248
+	private function renderItemIdSnakValueList(array $valueList, $role) {
249
+		return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']);
250 250
 	}
251 251
 
252 252
 	/**
@@ -254,11 +254,11 @@  discard block
 block discarded – undo
254 254
 	 * @param string|null $role one of the Role::* constants
255 255
 	 * @return array[] list of parameters as accepted by Message::params()
256 256
 	 */
257
-	private function renderDataValue( DataValue $dataValue, $role ) {
258
-		return [ Message::rawParam( $this->addRole(
259
-			$this->dataValueFormatter->format( $dataValue ),
257
+	private function renderDataValue(DataValue $dataValue, $role) {
258
+		return [Message::rawParam($this->addRole(
259
+			$this->dataValueFormatter->format($dataValue),
260 260
 			$role
261
-		) ) ];
261
+		))];
262 262
 	}
263 263
 
264 264
 	/**
@@ -266,22 +266,22 @@  discard block
 block discarded – undo
266 266
 	 * @param string|null $role one of the Role::* constants
267 267
 	 * @return array[] list of parameters as accepted by Message::params()
268 268
 	 */
269
-	private function renderDataValueType( $dataValueType, $role ) {
269
+	private function renderDataValueType($dataValueType, $role) {
270 270
 		$messageKeys = [
271 271
 			'string' => 'datatypes-type-string',
272 272
 			'monolingualtext' => 'datatypes-monolingualtext',
273 273
 			'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid',
274 274
 		];
275 275
 
276
-		if ( array_key_exists( $dataValueType, $messageKeys ) ) {
277
-			return [ Message::rawParam( $this->addRole(
278
-				wfMessage( $messageKeys[$dataValueType] )->escaped(),
276
+		if (array_key_exists($dataValueType, $messageKeys)) {
277
+			return [Message::rawParam($this->addRole(
278
+				wfMessage($messageKeys[$dataValueType])->escaped(),
279 279
 				$role
280
-			) ) ];
280
+			))];
281 281
 		} else {
282 282
 			// @codeCoverageIgnoreStart
283 283
 			throw new LogicException(
284
-				'Unknown data value type ' . $dataValueType
284
+				'Unknown data value type '.$dataValueType
285 285
 			);
286 286
 			// @codeCoverageIgnoreEnd
287 287
 		}
@@ -292,11 +292,11 @@  discard block
 block discarded – undo
292 292
 	 * @param string|null $role one of the Role::* constants
293 293
 	 * @return array[] list of parameters as accepted by Message::params()
294 294
 	 */
295
-	private function renderInlineCode( $code, $role ) {
296
-		return [ Message::rawParam( $this->addRole(
297
-			'<code>' . htmlspecialchars( $code ) . '</code>',
295
+	private function renderInlineCode($code, $role) {
296
+		return [Message::rawParam($this->addRole(
297
+			'<code>'.htmlspecialchars($code).'</code>',
298 298
 			$role
299
-		) ) ];
299
+		))];
300 300
 	}
301 301
 
302 302
 	/**
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
 	 * @param string|null $role one of the Role::* constants
305 305
 	 * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ])
306 306
 	 */
307
-	private function renderConstraintScope( $scope, $role ) {
308
-		switch ( $scope ) {
307
+	private function renderConstraintScope($scope, $role) {
308
+		switch ($scope) {
309 309
 			case Context::TYPE_STATEMENT:
310 310
 				$itemId = $this->config->get(
311 311
 					'WBQualityConstraintsConstraintCheckedOnMainValueId'
@@ -325,10 +325,10 @@  discard block
 block discarded – undo
325 325
 				// callers should never let this happen, but if it does happen,
326 326
 				// showing “unknown value” seems reasonable
327 327
 				// @codeCoverageIgnoreStart
328
-				return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role );
328
+				return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role);
329 329
 				// @codeCoverageIgnoreEnd
330 330
 		}
331
-		return $this->renderEntityId( new ItemId( $itemId ), $role );
331
+		return $this->renderEntityId(new ItemId($itemId), $role);
332 332
 	}
333 333
 
334 334
 	/**
@@ -336,8 +336,8 @@  discard block
 block discarded – undo
336 336
 	 * @param string|null $role one of the Role::* constants
337 337
 	 * @return array[] list of parameters as accepted by Message::params()
338 338
 	 */
339
-	private function renderConstraintScopeList( array $scopeList, $role ) {
340
-		return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] );
339
+	private function renderConstraintScopeList(array $scopeList, $role) {
340
+		return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']);
341 341
 	}
342 342
 
343 343
 	/**
@@ -345,10 +345,10 @@  discard block
 block discarded – undo
345 345
 	 * @param string|null $role one of the Role::* constants
346 346
 	 * @return array[] list of parameters as accepted by Message::params()
347 347
 	 */
348
-	private function renderLanguage( $languageCode, $role ) {
348
+	private function renderLanguage($languageCode, $role) {
349 349
 		return [
350
-			Message::plaintextParam( Language::fetchLanguageName( $languageCode ) ),
351
-			Message::plaintextParam( $languageCode ),
350
+			Message::plaintextParam(Language::fetchLanguageName($languageCode)),
351
+			Message::plaintextParam($languageCode),
352 352
 		];
353 353
 	}
354 354
 
Please login to merge, or discard this patch.