Completed
Push — master ( f6a477...97f202 )
by
unknown
04:20
created
src/ConstraintCheck/Message/ViolationMessageRenderer.php 1 patch
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -66,31 +66,31 @@  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
 
87
-	private function addRole( $value, $role ) {
88
-		if ( $role === null ) {
87
+	private function addRole($value, $role) {
88
+		if ($role === null) {
89 89
 			return $value;
90 90
 		}
91 91
 
92
-		return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' .
93
-			$value .
92
+		return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'.
93
+			$value.
94 94
 			'</span>';
95 95
 	}
96 96
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 * @param array $argument
99 99
 	 * @return array params (for Message::params)
100 100
 	 */
101
-	private function renderArgument( array $argument ) {
101
+	private function renderArgument(array $argument) {
102 102
 		$methods = [
103 103
 			ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId',
104 104
 			ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList',
@@ -116,55 +116,55 @@  discard block
 block discarded – undo
116 116
 		$value = $argument['value'];
117 117
 		$role = $argument['role'];
118 118
 
119
-		if ( array_key_exists( $type, $methods ) ) {
119
+		if (array_key_exists($type, $methods)) {
120 120
 			$method = $methods[$type];
121
-			$params = $this->$method( $value, $role );
121
+			$params = $this->$method($value, $role);
122 122
 		} else {
123 123
 			throw new InvalidArgumentException(
124
-				'Unknown ViolationMessage argument type ' . $type . '!'
124
+				'Unknown ViolationMessage argument type '.$type.'!'
125 125
 			);
126 126
 		}
127 127
 
128
-		if ( !array_key_exists( 0, $params ) ) {
129
-			$params = [ $params ];
128
+		if (!array_key_exists(0, $params)) {
129
+			$params = [$params];
130 130
 		}
131 131
 		return $params;
132 132
 	}
133 133
 
134
-	private function renderList( array $list, $role, callable $render ) {
135
-		if ( $list === [] ) {
134
+	private function renderList(array $list, $role, callable $render) {
135
+		if ($list === []) {
136 136
 			return [
137
-				Message::numParam( 0 ),
138
-				Message::rawParam( '<ul></ul>' ),
137
+				Message::numParam(0),
138
+				Message::rawParam('<ul></ul>'),
139 139
 			];
140 140
 		}
141 141
 
142
-		if ( count( $list ) > $this->maxListLength ) {
143
-			$list = array_slice( $list, 0, $this->maxListLength );
142
+		if (count($list) > $this->maxListLength) {
143
+			$list = array_slice($list, 0, $this->maxListLength);
144 144
 			$truncated = true;
145 145
 		}
146 146
 
147 147
 		$renderedParams = array_map(
148 148
 			$render,
149 149
 			$list,
150
-			array_fill( 0, count( $list ), $role )
150
+			array_fill(0, count($list), $role)
151 151
 		);
152 152
 		$renderedElements = array_map(
153
-			function ( $param ) {
153
+			function($param) {
154 154
 				return $param['raw'];
155 155
 			},
156 156
 			$renderedParams
157 157
 		);
158
-		if ( isset( $truncated ) ) {
159
-			$renderedElements[] = wfMessage( 'ellipsis' )->escaped();
158
+		if (isset($truncated)) {
159
+			$renderedElements[] = wfMessage('ellipsis')->escaped();
160 160
 		}
161 161
 
162 162
 		return array_merge(
163 163
 			[
164
-				Message::numParam( count( $list ) ),
164
+				Message::numParam(count($list)),
165 165
 				Message::rawParam(
166
-					'<ul><li>' .
167
-					implode( '</li><li>', $renderedElements ) .
166
+					'<ul><li>'.
167
+					implode('</li><li>', $renderedElements).
168 168
 					'</li></ul>'
169 169
 				),
170 170
 			],
@@ -172,35 +172,35 @@  discard block
 block discarded – undo
172 172
 		);
173 173
 	}
174 174
 
175
-	private function renderEntityId( EntityId $entityId, $role ) {
176
-		return Message::rawParam( $this->addRole(
177
-			$this->entityIdFormatter->formatEntityId( $entityId ),
175
+	private function renderEntityId(EntityId $entityId, $role) {
176
+		return Message::rawParam($this->addRole(
177
+			$this->entityIdFormatter->formatEntityId($entityId),
178 178
 			$role
179
-		) );
179
+		));
180 180
 	}
181 181
 
182
-	private function renderEntityIdList( array $entityIdList, $role ) {
183
-		return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] );
182
+	private function renderEntityIdList(array $entityIdList, $role) {
183
+		return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']);
184 184
 	}
185 185
 
186
-	private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) {
187
-		switch ( true ) {
186
+	private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) {
187
+		switch (true) {
188 188
 			case $value->isValue():
189
-				return $this->renderEntityId( $value->getItemId(), $role );
189
+				return $this->renderEntityId($value->getItemId(), $role);
190 190
 			case $value->isSomeValue():
191
-				return Message::rawParam( $this->addRole(
192
-					'<span class="wikibase-snakview-variation-somevaluesnak">' .
193
-						wfMessage( 'wikibase-snakview-snaktypeselector-somevalue' )->escaped() .
191
+				return Message::rawParam($this->addRole(
192
+					'<span class="wikibase-snakview-variation-somevaluesnak">'.
193
+						wfMessage('wikibase-snakview-snaktypeselector-somevalue')->escaped().
194 194
 						'</span>',
195 195
 					$role
196
-				) );
196
+				));
197 197
 			case $value->isNoValue():
198
-				return Message::rawParam( $this->addRole(
199
-					'<span class="wikibase-snakview-variation-novaluesnak">' .
200
-						wfMessage( 'wikibase-snakview-snaktypeselector-novalue' )->escaped() .
198
+				return Message::rawParam($this->addRole(
199
+					'<span class="wikibase-snakview-variation-novaluesnak">'.
200
+						wfMessage('wikibase-snakview-snaktypeselector-novalue')->escaped().
201 201
 						'</span>',
202 202
 					$role
203
-				) );
203
+				));
204 204
 			default:
205 205
 				// @codeCoverageIgnoreStart
206 206
 				throw new LogicException(
@@ -210,47 +210,47 @@  discard block
 block discarded – undo
210 210
 		}
211 211
 	}
212 212
 
213
-	private function renderItemIdSnakValueList( array $valueList, $role ) {
214
-		return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] );
213
+	private function renderItemIdSnakValueList(array $valueList, $role) {
214
+		return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']);
215 215
 	}
216 216
 
217
-	private function renderDataValue( DataValue $dataValue, $role ) {
218
-		return Message::rawParam( $this->addRole(
219
-			$this->dataValueFormatter->format( $dataValue ),
217
+	private function renderDataValue(DataValue $dataValue, $role) {
218
+		return Message::rawParam($this->addRole(
219
+			$this->dataValueFormatter->format($dataValue),
220 220
 			$role
221
-		) );
221
+		));
222 222
 	}
223 223
 
224
-	private function renderDataValueType( $dataValueType, $role ) {
224
+	private function renderDataValueType($dataValueType, $role) {
225 225
 		$messageKeys = [
226 226
 			'string' => 'datatypes-type-string',
227 227
 			'monolingualtext' => 'datatypes-monolingualtext',
228 228
 			'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid',
229 229
 		];
230 230
 
231
-		if ( array_key_exists( $dataValueType, $messageKeys ) ) {
232
-			return Message::rawParam( $this->addRole(
233
-				wfMessage( $messageKeys[$dataValueType] )->escaped(),
231
+		if (array_key_exists($dataValueType, $messageKeys)) {
232
+			return Message::rawParam($this->addRole(
233
+				wfMessage($messageKeys[$dataValueType])->escaped(),
234 234
 				$role
235
-			) );
235
+			));
236 236
 		} else {
237 237
 			// @codeCoverageIgnoreStart
238 238
 			throw new LogicException(
239
-				'Unknown data value type ' . $dataValueType
239
+				'Unknown data value type '.$dataValueType
240 240
 			);
241 241
 			// @codeCoverageIgnoreEnd
242 242
 		}
243 243
 	}
244 244
 
245
-	private function renderInlineCode( $code, $role ) {
246
-		return Message::rawParam( $this->addRole(
247
-			'<code>' . htmlspecialchars( $code ) . '</code>',
245
+	private function renderInlineCode($code, $role) {
246
+		return Message::rawParam($this->addRole(
247
+			'<code>'.htmlspecialchars($code).'</code>',
248 248
 			$role
249
-		) );
249
+		));
250 250
 	}
251 251
 
252
-	private function renderConstraintScope( $scope, $role ) {
253
-		switch ( $scope ) {
252
+	private function renderConstraintScope($scope, $role) {
253
+		switch ($scope) {
254 254
 			case Context::TYPE_STATEMENT:
255 255
 				$itemId = $this->config->get(
256 256
 					'WBQualityConstraintsConstraintCheckedOnMainValueId'
@@ -270,20 +270,20 @@  discard block
 block discarded – undo
270 270
 				// callers should never let this happen, but if it does happen,
271 271
 				// showing “unknown value” seems reasonable
272 272
 				// @codeCoverageIgnoreStart
273
-				return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role );
273
+				return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role);
274 274
 				// @codeCoverageIgnoreEnd
275 275
 		}
276
-		return $this->renderEntityId( new ItemId( $itemId ), $role );
276
+		return $this->renderEntityId(new ItemId($itemId), $role);
277 277
 	}
278 278
 
279
-	private function renderConstraintScopeList( array $scopeList, $role ) {
280
-		return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] );
279
+	private function renderConstraintScopeList(array $scopeList, $role) {
280
+		return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']);
281 281
 	}
282 282
 
283
-	private function renderLanguage( $languageCode, $role ) {
283
+	private function renderLanguage($languageCode, $role) {
284 284
 		return [
285
-			Message::plaintextParam( Language::fetchLanguageName( $languageCode ) ),
286
-			Message::plaintextParam( $languageCode ),
285
+			Message::plaintextParam(Language::fetchLanguageName($languageCode)),
286
+			Message::plaintextParam($languageCode),
287 287
 		];
288 288
 	}
289 289
 
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.