Completed
Push — master ( a7fb9d...f6a477 )
by
unknown
02:56
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   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -97,17 +97,17 @@  discard block
 block discarded – undo
97 97
 	public function __construct(
98 98
 		$messageKey
99 99
 	) {
100
-		if ( strpos( $messageKey, self::MESSAGE_KEY_PREFIX ) !== 0 ) {
100
+		if (strpos($messageKey, self::MESSAGE_KEY_PREFIX) !== 0) {
101 101
 			throw new InvalidArgumentException(
102
-				'ViolationMessage key ⧼' .
103
-				$messageKey .
104
-				'⧽ should start with "' .
105
-				self::MESSAGE_KEY_PREFIX .
102
+				'ViolationMessage key ⧼'.
103
+				$messageKey.
104
+				'⧽ should start with "'.
105
+				self::MESSAGE_KEY_PREFIX.
106 106
 				'".'
107 107
 			);
108 108
 		}
109 109
 
110
-		$this->messageKeySuffix = substr( $messageKey, strlen( self::MESSAGE_KEY_PREFIX ) );
110
+		$this->messageKeySuffix = substr($messageKey, strlen(self::MESSAGE_KEY_PREFIX));
111 111
 		$this->arguments = [];
112 112
 	}
113 113
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 * @return string
117 117
 	 */
118 118
 	public function getMessageKey() {
119
-		return self::MESSAGE_KEY_PREFIX . $this->messageKeySuffix;
119
+		return self::MESSAGE_KEY_PREFIX.$this->messageKeySuffix;
120 120
 	}
121 121
 
122 122
 	/**
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 	 * @param mixed $value the value, which should match the $type
135 135
 	 * @return ViolationMessage
136 136
 	 */
137
-	private function withArgument( $type, $role, $value ) {
137
+	private function withArgument($type, $role, $value) {
138 138
 		$ret = clone $this;
139
-		$ret->arguments[] = [ 'type' => $type, 'role' => $role, 'value' => $value ];
139
+		$ret->arguments[] = ['type' => $type, 'role' => $role, 'value' => $value];
140 140
 		return $ret;
141 141
 	}
142 142
 
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
 	 * @param string|null $role one of the Role::* constants
149 149
 	 * @return ViolationMessage
150 150
 	 */
151
-	public function withEntityId( EntityId $entityId, $role = null ) {
152
-		return $this->withArgument( self::TYPE_ENTITY_ID, $role, $entityId );
151
+	public function withEntityId(EntityId $entityId, $role = null) {
152
+		return $this->withArgument(self::TYPE_ENTITY_ID, $role, $entityId);
153 153
 	}
154 154
 
155 155
 	/**
@@ -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 withEntityIdList( array $entityIdList, $role = null ) {
170
-		return $this->withArgument( self::TYPE_ENTITY_ID_LIST, $role, $entityIdList );
169
+	public function withEntityIdList(array $entityIdList, $role = null) {
170
+		return $this->withArgument(self::TYPE_ENTITY_ID_LIST, $role, $entityIdList);
171 171
 	}
172 172
 
173 173
 	/**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
 	 * @param string|null $role one of the Role::* constants
179 179
 	 * @return ViolationMessage
180 180
 	 */
181
-	public function withItemIdSnakValue( ItemIdSnakValue $value, $role = null ) {
182
-		return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value );
181
+	public function withItemIdSnakValue(ItemIdSnakValue $value, $role = null) {
182
+		return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value);
183 183
 	}
184 184
 
185 185
 	/**
@@ -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 withItemIdSnakValueList( array $valueList, $role = null ) {
200
-		return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList );
199
+	public function withItemIdSnakValueList(array $valueList, $role = null) {
200
+		return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList);
201 201
 	}
202 202
 
203 203
 	/**
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
 	 * @param string|null $role one of the Role::* constants
209 209
 	 * @return ViolationMessage
210 210
 	 */
211
-	public function withDataValue( DataValue $dataValue, $role = null ) {
212
-		return $this->withArgument( self::TYPE_DATA_VALUE, $role, $dataValue );
211
+	public function withDataValue(DataValue $dataValue, $role = null) {
212
+		return $this->withArgument(self::TYPE_DATA_VALUE, $role, $dataValue);
213 213
 	}
214 214
 
215 215
 	/**
@@ -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 withDataValueType( $dataValueType, $role = null ) {
228
-		return $this->withArgument( self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType );
227
+	public function withDataValueType($dataValueType, $role = null) {
228
+		return $this->withArgument(self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType);
229 229
 	}
230 230
 
231 231
 	/**
@@ -236,8 +236,8 @@  discard block
 block discarded – undo
236 236
 	 * @param string|null $role one of the Role::* constants
237 237
 	 * @return ViolationMessage
238 238
 	 */
239
-	public function withInlineCode( $code, $role = null ) {
240
-		return $this->withArgument( self::TYPE_INLINE_CODE, $role, $code );
239
+	public function withInlineCode($code, $role = null) {
240
+		return $this->withArgument(self::TYPE_INLINE_CODE, $role, $code);
241 241
 	}
242 242
 
243 243
 	/**
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	 * @param string|null $role one of the Role::* constants
249 249
 	 * @return ViolationMessage
250 250
 	 */
251
-	public function withConstraintScope( $scope, $role = null ) {
252
-		return $this->withArgument( self::TYPE_CONSTRAINT_SCOPE, $role, $scope );
251
+	public function withConstraintScope($scope, $role = null) {
252
+		return $this->withArgument(self::TYPE_CONSTRAINT_SCOPE, $role, $scope);
253 253
 	}
254 254
 
255 255
 	/**
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
 	 * @param string|null $role one of the Role::* constants
261 261
 	 * @return ViolationMessage
262 262
 	 */
263
-	public function withConstraintScopeList( array $scopeList, $role = null ) {
264
-		return $this->withArgument( self::TYPE_CONSTRAINT_SCOPE_LIST, $role, $scopeList );
263
+	public function withConstraintScopeList(array $scopeList, $role = null) {
264
+		return $this->withArgument(self::TYPE_CONSTRAINT_SCOPE_LIST, $role, $scopeList);
265 265
 	}
266 266
 
267 267
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/ViolationMessageRenderer.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -65,31 +65,31 @@  discard block
 block discarded – undo
65 65
 	 * (temporarily, pre-rendered strings are allowed and returned without changes)
66 66
 	 * @return string
67 67
 	 */
68
-	public function render( $violationMessage ) {
69
-		if ( is_string( $violationMessage ) ) {
68
+	public function render($violationMessage) {
69
+		if (is_string($violationMessage)) {
70 70
 			// TODO remove this once all checkers produce ViolationMessage objects
71 71
 			return $violationMessage;
72 72
 		}
73 73
 
74 74
 		$messageKey = $violationMessage->getMessageKey();
75
-		$paramsLists = [ [] ];
76
-		foreach ( $violationMessage->getArguments() as $argument ) {
77
-			$params = $this->renderArgument( $argument );
75
+		$paramsLists = [[]];
76
+		foreach ($violationMessage->getArguments() as $argument) {
77
+			$params = $this->renderArgument($argument);
78 78
 			$paramsLists[] = $params;
79 79
 		}
80
-		$allParams = call_user_func_array( 'array_merge', $paramsLists );
81
-		return ( new Message( $messageKey ) )
82
-			->params( $allParams )
80
+		$allParams = call_user_func_array('array_merge', $paramsLists);
81
+		return (new Message($messageKey))
82
+			->params($allParams)
83 83
 			->escaped();
84 84
 	}
85 85
 
86
-	private function addRole( $value, $role ) {
87
-		if ( $role === null ) {
86
+	private function addRole($value, $role) {
87
+		if ($role === null) {
88 88
 			return $value;
89 89
 		}
90 90
 
91
-		return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' .
92
-			$value .
91
+		return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'.
92
+			$value.
93 93
 			'</span>';
94 94
 	}
95 95
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 * @param array $argument
98 98
 	 * @return array params (for Message::params)
99 99
 	 */
100
-	private function renderArgument( array $argument ) {
100
+	private function renderArgument(array $argument) {
101 101
 		$methods = [
102 102
 			ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId',
103 103
 			ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList',
@@ -114,55 +114,55 @@  discard block
 block discarded – undo
114 114
 		$value = $argument['value'];
115 115
 		$role = $argument['role'];
116 116
 
117
-		if ( array_key_exists( $type, $methods ) ) {
117
+		if (array_key_exists($type, $methods)) {
118 118
 			$method = $methods[$type];
119
-			$params = $this->$method( $value, $role );
119
+			$params = $this->$method($value, $role);
120 120
 		} else {
121 121
 			throw new InvalidArgumentException(
122
-				'Unknown ViolationMessage argument type ' . $type . '!'
122
+				'Unknown ViolationMessage argument type '.$type.'!'
123 123
 			);
124 124
 		}
125 125
 
126
-		if ( !array_key_exists( 0, $params ) ) {
127
-			$params = [ $params ];
126
+		if (!array_key_exists(0, $params)) {
127
+			$params = [$params];
128 128
 		}
129 129
 		return $params;
130 130
 	}
131 131
 
132
-	private function renderList( array $list, $role, callable $render ) {
133
-		if ( $list === [] ) {
132
+	private function renderList(array $list, $role, callable $render) {
133
+		if ($list === []) {
134 134
 			return [
135
-				Message::numParam( 0 ),
136
-				Message::rawParam( '<ul></ul>' ),
135
+				Message::numParam(0),
136
+				Message::rawParam('<ul></ul>'),
137 137
 			];
138 138
 		}
139 139
 
140
-		if ( count( $list ) > $this->maxListLength ) {
141
-			$list = array_slice( $list, 0, $this->maxListLength );
140
+		if (count($list) > $this->maxListLength) {
141
+			$list = array_slice($list, 0, $this->maxListLength);
142 142
 			$truncated = true;
143 143
 		}
144 144
 
145 145
 		$renderedParams = array_map(
146 146
 			$render,
147 147
 			$list,
148
-			array_fill( 0, count( $list ), $role )
148
+			array_fill(0, count($list), $role)
149 149
 		);
150 150
 		$renderedElements = array_map(
151
-			function ( $param ) {
151
+			function($param) {
152 152
 				return $param['raw'];
153 153
 			},
154 154
 			$renderedParams
155 155
 		);
156
-		if ( isset( $truncated ) ) {
157
-			$renderedElements[] = wfMessage( 'ellipsis' )->escaped();
156
+		if (isset($truncated)) {
157
+			$renderedElements[] = wfMessage('ellipsis')->escaped();
158 158
 		}
159 159
 
160 160
 		return array_merge(
161 161
 			[
162
-				Message::numParam( count( $list ) ),
162
+				Message::numParam(count($list)),
163 163
 				Message::rawParam(
164
-					'<ul><li>' .
165
-					implode( '</li><li>', $renderedElements ) .
164
+					'<ul><li>'.
165
+					implode('</li><li>', $renderedElements).
166 166
 					'</li></ul>'
167 167
 				),
168 168
 			],
@@ -170,35 +170,35 @@  discard block
 block discarded – undo
170 170
 		);
171 171
 	}
172 172
 
173
-	private function renderEntityId( EntityId $entityId, $role ) {
174
-		return Message::rawParam( $this->addRole(
175
-			$this->entityIdFormatter->formatEntityId( $entityId ),
173
+	private function renderEntityId(EntityId $entityId, $role) {
174
+		return Message::rawParam($this->addRole(
175
+			$this->entityIdFormatter->formatEntityId($entityId),
176 176
 			$role
177
-		) );
177
+		));
178 178
 	}
179 179
 
180
-	private function renderEntityIdList( array $entityIdList, $role ) {
181
-		return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] );
180
+	private function renderEntityIdList(array $entityIdList, $role) {
181
+		return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']);
182 182
 	}
183 183
 
184
-	private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) {
185
-		switch ( true ) {
184
+	private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) {
185
+		switch (true) {
186 186
 			case $value->isValue():
187
-				return $this->renderEntityId( $value->getItemId(), $role );
187
+				return $this->renderEntityId($value->getItemId(), $role);
188 188
 			case $value->isSomeValue():
189
-				return Message::rawParam( $this->addRole(
190
-					'<span class="wikibase-snakview-variation-somevaluesnak">' .
191
-						wfMessage( 'wikibase-snakview-snaktypeselector-somevalue' )->escaped() .
189
+				return Message::rawParam($this->addRole(
190
+					'<span class="wikibase-snakview-variation-somevaluesnak">'.
191
+						wfMessage('wikibase-snakview-snaktypeselector-somevalue')->escaped().
192 192
 						'</span>',
193 193
 					$role
194
-				) );
194
+				));
195 195
 			case $value->isNoValue():
196
-				return Message::rawParam( $this->addRole(
197
-					'<span class="wikibase-snakview-variation-novaluesnak">' .
198
-						wfMessage( 'wikibase-snakview-snaktypeselector-novalue' )->escaped() .
196
+				return Message::rawParam($this->addRole(
197
+					'<span class="wikibase-snakview-variation-novaluesnak">'.
198
+						wfMessage('wikibase-snakview-snaktypeselector-novalue')->escaped().
199 199
 						'</span>',
200 200
 					$role
201
-				) );
201
+				));
202 202
 			default:
203 203
 				// @codeCoverageIgnoreStart
204 204
 				throw new LogicException(
@@ -208,47 +208,47 @@  discard block
 block discarded – undo
208 208
 		}
209 209
 	}
210 210
 
211
-	private function renderItemIdSnakValueList( array $valueList, $role ) {
212
-		return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] );
211
+	private function renderItemIdSnakValueList(array $valueList, $role) {
212
+		return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']);
213 213
 	}
214 214
 
215
-	private function renderDataValue( DataValue $dataValue, $role ) {
216
-		return Message::rawParam( $this->addRole(
217
-			$this->dataValueFormatter->format( $dataValue ),
215
+	private function renderDataValue(DataValue $dataValue, $role) {
216
+		return Message::rawParam($this->addRole(
217
+			$this->dataValueFormatter->format($dataValue),
218 218
 			$role
219
-		) );
219
+		));
220 220
 	}
221 221
 
222
-	private function renderDataValueType( $dataValueType, $role ) {
222
+	private function renderDataValueType($dataValueType, $role) {
223 223
 		$messageKeys = [
224 224
 			'string' => 'datatypes-type-string',
225 225
 			'monolingualtext' => 'datatypes-monolingualtext',
226 226
 			'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid',
227 227
 		];
228 228
 
229
-		if ( array_key_exists( $dataValueType, $messageKeys ) ) {
230
-			return Message::rawParam( $this->addRole(
231
-				wfMessage( $messageKeys[$dataValueType] )->escaped(),
229
+		if (array_key_exists($dataValueType, $messageKeys)) {
230
+			return Message::rawParam($this->addRole(
231
+				wfMessage($messageKeys[$dataValueType])->escaped(),
232 232
 				$role
233
-			) );
233
+			));
234 234
 		} else {
235 235
 			// @codeCoverageIgnoreStart
236 236
 			throw new LogicException(
237
-				'Unknown data value type ' . $dataValueType
237
+				'Unknown data value type '.$dataValueType
238 238
 			);
239 239
 			// @codeCoverageIgnoreEnd
240 240
 		}
241 241
 	}
242 242
 
243
-	private function renderInlineCode( $code, $role ) {
244
-		return Message::rawParam( $this->addRole(
245
-			'<code>' . htmlspecialchars( $code ) . '</code>',
243
+	private function renderInlineCode($code, $role) {
244
+		return Message::rawParam($this->addRole(
245
+			'<code>'.htmlspecialchars($code).'</code>',
246 246
 			$role
247
-		) );
247
+		));
248 248
 	}
249 249
 
250
-	private function renderConstraintScope( $scope, $role ) {
251
-		switch ( $scope ) {
250
+	private function renderConstraintScope($scope, $role) {
251
+		switch ($scope) {
252 252
 			case Context::TYPE_STATEMENT:
253 253
 				$itemId = $this->config->get(
254 254
 					'WBQualityConstraintsConstraintCheckedOnMainValueId'
@@ -268,14 +268,14 @@  discard block
 block discarded – undo
268 268
 				// callers should never let this happen, but if it does happen,
269 269
 				// showing “unknown value” seems reasonable
270 270
 				// @codeCoverageIgnoreStart
271
-				return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role );
271
+				return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role);
272 272
 				// @codeCoverageIgnoreEnd
273 273
 		}
274
-		return $this->renderEntityId( new ItemId( $itemId ), $role );
274
+		return $this->renderEntityId(new ItemId($itemId), $role);
275 275
 	}
276 276
 
277
-	private function renderConstraintScopeList( array $scopeList, $role ) {
278
-		return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] );
277
+	private function renderConstraintScopeList(array $scopeList, $role) {
278
+		return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']);
279 279
 	}
280 280
 
281 281
 }
Please login to merge, or discard this patch.