Completed
Push — master ( a2235a...50f3c2 )
by
unknown
02:48
created
src/ConstraintCheck/Message/ViolationMessage.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -85,17 +85,17 @@  discard block
 block discarded – undo
85 85
 	public function __construct(
86 86
 		$messageKey
87 87
 	) {
88
-		if ( strpos( $messageKey, self::MESSAGE_KEY_PREFIX ) !== 0 ) {
88
+		if (strpos($messageKey, self::MESSAGE_KEY_PREFIX) !== 0) {
89 89
 			throw new InvalidArgumentException(
90
-				'ViolationMessage key ⧼' .
91
-				$messageKey .
92
-				'⧽ should start with "' .
93
-				self::MESSAGE_KEY_PREFIX .
90
+				'ViolationMessage key ⧼'.
91
+				$messageKey.
92
+				'⧽ should start with "'.
93
+				self::MESSAGE_KEY_PREFIX.
94 94
 				'".'
95 95
 			);
96 96
 		}
97 97
 
98
-		$this->messageKeySuffix = substr( $messageKey, strlen( self::MESSAGE_KEY_PREFIX ) );
98
+		$this->messageKeySuffix = substr($messageKey, strlen(self::MESSAGE_KEY_PREFIX));
99 99
 		$this->arguments = [];
100 100
 	}
101 101
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 * @return string
105 105
 	 */
106 106
 	public function getMessageKey() {
107
-		return self::MESSAGE_KEY_PREFIX . $this->messageKeySuffix;
107
+		return self::MESSAGE_KEY_PREFIX.$this->messageKeySuffix;
108 108
 	}
109 109
 
110 110
 	/**
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 	 * @param mixed $value the value, which should match the $type
123 123
 	 * @return ViolationMessage
124 124
 	 */
125
-	private function withArgument( $type, $role, $value ) {
125
+	private function withArgument($type, $role, $value) {
126 126
 		$ret = clone $this;
127
-		$ret->arguments[] = [ 'type' => $type, 'role' => $role, 'value' => $value ];
127
+		$ret->arguments[] = ['type' => $type, 'role' => $role, 'value' => $value];
128 128
 		return $ret;
129 129
 	}
130 130
 
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 	 * @param string|null $role one of the Role::* constants
137 137
 	 * @return ViolationMessage
138 138
 	 */
139
-	public function withEntityId( EntityId $entityId, $role = null ) {
140
-		return $this->withArgument( self::TYPE_ENTITY_ID, $role, $entityId );
139
+	public function withEntityId(EntityId $entityId, $role = null) {
140
+		return $this->withArgument(self::TYPE_ENTITY_ID, $role, $entityId);
141 141
 	}
142 142
 
143 143
 	/**
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
 	 * @param string|null $role one of the Role::* constants
155 155
 	 * @return ViolationMessage
156 156
 	 */
157
-	public function withEntityIdList( array $entityIdList, $role = null ) {
158
-		return $this->withArgument( self::TYPE_ENTITY_ID_LIST, $role, $entityIdList );
157
+	public function withEntityIdList(array $entityIdList, $role = null) {
158
+		return $this->withArgument(self::TYPE_ENTITY_ID_LIST, $role, $entityIdList);
159 159
 	}
160 160
 
161 161
 	/**
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
 	 * @param string|null $role one of the Role::* constants
167 167
 	 * @return ViolationMessage
168 168
 	 */
169
-	public function withItemIdSnakValue( ItemIdSnakValue $value, $role = null ) {
170
-		return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value );
169
+	public function withItemIdSnakValue(ItemIdSnakValue $value, $role = null) {
170
+		return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value);
171 171
 	}
172 172
 
173 173
 	/**
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 	 * @param string|null $role one of the Role::* constants
185 185
 	 * @return ViolationMessage
186 186
 	 */
187
-	public function withItemIdSnakValueList( array $valueList, $role = null ) {
188
-		return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList );
187
+	public function withItemIdSnakValueList(array $valueList, $role = null) {
188
+		return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList);
189 189
 	}
190 190
 
191 191
 	/**
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 	 * @param string|null $role one of the Role::* constants
197 197
 	 * @return ViolationMessage
198 198
 	 */
199
-	public function withDataValue( DataValue $dataValue, $role = null ) {
200
-		return $this->withArgument( self::TYPE_DATA_VALUE, $role, $dataValue );
199
+	public function withDataValue(DataValue $dataValue, $role = null) {
200
+		return $this->withArgument(self::TYPE_DATA_VALUE, $role, $dataValue);
201 201
 	}
202 202
 
203 203
 	/**
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
 	 * @param string|null $role one of the Role::* constants
213 213
 	 * @return ViolationMessage
214 214
 	 */
215
-	public function withDataValueType( $dataValueType, $role = null ) {
216
-		return $this->withArgument( self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType );
215
+	public function withDataValueType($dataValueType, $role = null) {
216
+		return $this->withArgument(self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType);
217 217
 	}
218 218
 
219 219
 	/**
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
 	 * @param string|null $role one of the Role::* constants
225 225
 	 * @return ViolationMessage
226 226
 	 */
227
-	public function withInlineCode( $code, $role = null ) {
228
-		return $this->withArgument( self::TYPE_INLINE_CODE, $role, $code );
227
+	public function withInlineCode($code, $role = null) {
228
+		return $this->withArgument(self::TYPE_INLINE_CODE, $role, $code);
229 229
 	}
230 230
 
231 231
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/ViolationMessageRenderer.php 1 patch
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -54,96 +54,96 @@  discard block
 block discarded – undo
54 54
 	 * (temporarily, pre-rendered strings are allowed and returned without changes)
55 55
 	 * @return string
56 56
 	 */
57
-	public function render( $violationMessage ) {
58
-		if ( is_string( $violationMessage ) ) {
57
+	public function render($violationMessage) {
58
+		if (is_string($violationMessage)) {
59 59
 			// TODO remove this once all checkers produce ViolationMessage objects
60 60
 			return $violationMessage;
61 61
 		}
62
-		$message = new Message( $violationMessage->getMessageKey() );
63
-		foreach ( $violationMessage->getArguments() as $argument ) {
64
-			$this->renderArgument( $argument, $message );
62
+		$message = new Message($violationMessage->getMessageKey());
63
+		foreach ($violationMessage->getArguments() as $argument) {
64
+			$this->renderArgument($argument, $message);
65 65
 		}
66 66
 		return $message->escaped();
67 67
 	}
68 68
 
69
-	private function addRole( $value, $role ) {
70
-		if ( $role === null ) {
69
+	private function addRole($value, $role) {
70
+		if ($role === null) {
71 71
 			return $value;
72 72
 		}
73 73
 
74
-		return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' .
75
-			$value .
74
+		return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'.
75
+			$value.
76 76
 			'</span>';
77 77
 	}
78 78
 
79
-	private function renderArgument( array $argument, Message $message ) {
79
+	private function renderArgument(array $argument, Message $message) {
80 80
 		$type = $argument['type'];
81 81
 		$value = $argument['value'];
82 82
 		$role = $argument['role'];
83
-		switch ( $type ) {
83
+		switch ($type) {
84 84
 			case ViolationMessage::TYPE_ENTITY_ID:
85
-				$params = $this->renderEntityId( $value, $role );
85
+				$params = $this->renderEntityId($value, $role);
86 86
 				break;
87 87
 			case ViolationMessage::TYPE_ENTITY_ID_LIST:
88
-				$params = $this->renderEntityIdList( $value, $role );
88
+				$params = $this->renderEntityIdList($value, $role);
89 89
 				break;
90 90
 			case ViolationMessage::TYPE_ITEM_ID_SNAK_VALUE:
91
-				$params = $this->renderItemIdSnakValue( $value, $role );
91
+				$params = $this->renderItemIdSnakValue($value, $role);
92 92
 				break;
93 93
 			case ViolationMessage::TYPE_ITEM_ID_SNAK_VALUE_LIST:
94
-				$params = $this->renderItemIdSnakValueList( $value, $role );
94
+				$params = $this->renderItemIdSnakValueList($value, $role);
95 95
 				break;
96 96
 			case ViolationMessage::TYPE_DATA_VALUE:
97
-				$params = $this->renderDataValue( $value, $role );
97
+				$params = $this->renderDataValue($value, $role);
98 98
 				break;
99 99
 			case ViolationMessage::TYPE_DATA_VALUE_TYPE:
100
-				$params = $this->renderDataValueType( $value, $role );
100
+				$params = $this->renderDataValueType($value, $role);
101 101
 				break;
102 102
 			case ViolationMessage::TYPE_INLINE_CODE:
103
-				$params = $this->renderInlineCode( $value, $role );
103
+				$params = $this->renderInlineCode($value, $role);
104 104
 				break;
105 105
 			default:
106 106
 				throw new InvalidArgumentException(
107
-					'Unknown ViolationMessage argument type ' . $type . '!'
107
+					'Unknown ViolationMessage argument type '.$type.'!'
108 108
 				);
109 109
 		}
110
-		$message->params( $params );
110
+		$message->params($params);
111 111
 	}
112 112
 
113
-	private function renderList( array $list, $role, callable $render ) {
114
-		if ( $list === [] ) {
113
+	private function renderList(array $list, $role, callable $render) {
114
+		if ($list === []) {
115 115
 			return [
116
-				Message::numParam( 0 ),
117
-				Message::rawParam( '<ul></ul>' ),
116
+				Message::numParam(0),
117
+				Message::rawParam('<ul></ul>'),
118 118
 			];
119 119
 		}
120 120
 
121
-		if ( count( $list ) > $this->maxListLength ) {
122
-			$list = array_slice( $list, 0, $this->maxListLength );
121
+		if (count($list) > $this->maxListLength) {
122
+			$list = array_slice($list, 0, $this->maxListLength);
123 123
 			$truncated = true;
124 124
 		}
125 125
 
126 126
 		$renderedParams = array_map(
127 127
 			$render,
128 128
 			$list,
129
-			array_fill( 0, count( $list ), $role )
129
+			array_fill(0, count($list), $role)
130 130
 		);
131 131
 		$renderedElements = array_map(
132
-			function ( $param ) {
132
+			function($param) {
133 133
 				return $param['raw'];
134 134
 			},
135 135
 			$renderedParams
136 136
 		);
137
-		if ( isset( $truncated ) ) {
138
-			$renderedElements[] = wfMessage( 'ellipsis' )->escaped();
137
+		if (isset($truncated)) {
138
+			$renderedElements[] = wfMessage('ellipsis')->escaped();
139 139
 		}
140 140
 
141 141
 		return array_merge(
142 142
 			[
143
-				Message::numParam( count( $list ) ),
143
+				Message::numParam(count($list)),
144 144
 				Message::rawParam(
145
-					'<ul><li>' .
146
-					implode( '</li><li>', $renderedElements ) .
145
+					'<ul><li>'.
146
+					implode('</li><li>', $renderedElements).
147 147
 					'</li></ul>'
148 148
 				),
149 149
 			],
@@ -151,35 +151,35 @@  discard block
 block discarded – undo
151 151
 		);
152 152
 	}
153 153
 
154
-	private function renderEntityId( EntityId $entityId, $role ) {
155
-		return Message::rawParam( $this->addRole(
156
-			$this->entityIdFormatter->formatEntityId( $entityId ),
154
+	private function renderEntityId(EntityId $entityId, $role) {
155
+		return Message::rawParam($this->addRole(
156
+			$this->entityIdFormatter->formatEntityId($entityId),
157 157
 			$role
158
-		) );
158
+		));
159 159
 	}
160 160
 
161
-	private function renderEntityIdList( array $entityIdList, $role ) {
162
-		return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] );
161
+	private function renderEntityIdList(array $entityIdList, $role) {
162
+		return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']);
163 163
 	}
164 164
 
165
-	private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) {
166
-		switch ( true ) {
165
+	private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) {
166
+		switch (true) {
167 167
 			case $value->isValue():
168
-				return $this->renderEntityId( $value->getItemId(), $role );
168
+				return $this->renderEntityId($value->getItemId(), $role);
169 169
 			case $value->isSomeValue():
170
-				return Message::rawParam( $this->addRole(
171
-					'<span class="wikibase-snakview-variation-somevaluesnak">' .
172
-						wfMessage( 'wikibase-snakview-snaktypeselector-somevalue' )->escaped() .
170
+				return Message::rawParam($this->addRole(
171
+					'<span class="wikibase-snakview-variation-somevaluesnak">'.
172
+						wfMessage('wikibase-snakview-snaktypeselector-somevalue')->escaped().
173 173
 						'</span>',
174 174
 					$role
175
-				) );
175
+				));
176 176
 			case $value->isNoValue():
177
-				return Message::rawParam( $this->addRole(
178
-					'<span class="wikibase-snakview-variation-novaluesnak">' .
179
-						wfMessage( 'wikibase-snakview-snaktypeselector-novalue' )->escaped() .
177
+				return Message::rawParam($this->addRole(
178
+					'<span class="wikibase-snakview-variation-novaluesnak">'.
179
+						wfMessage('wikibase-snakview-snaktypeselector-novalue')->escaped().
180 180
 						'</span>',
181 181
 					$role
182
-				) );
182
+				));
183 183
 			default:
184 184
 				// @codeCoverageIgnoreStart
185 185
 				throw new LogicException(
@@ -189,43 +189,43 @@  discard block
 block discarded – undo
189 189
 		}
190 190
 	}
191 191
 
192
-	private function renderItemIdSnakValueList( array $valueList, $role ) {
193
-		return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] );
192
+	private function renderItemIdSnakValueList(array $valueList, $role) {
193
+		return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']);
194 194
 	}
195 195
 
196
-	private function renderDataValue( DataValue $dataValue, $role ) {
197
-		return Message::rawParam( $this->addRole(
198
-			$this->dataValueFormatter->format( $dataValue ),
196
+	private function renderDataValue(DataValue $dataValue, $role) {
197
+		return Message::rawParam($this->addRole(
198
+			$this->dataValueFormatter->format($dataValue),
199 199
 			$role
200
-		) );
200
+		));
201 201
 	}
202 202
 
203
-	private function renderDataValueType( $dataValueType, $role ) {
203
+	private function renderDataValueType($dataValueType, $role) {
204 204
 		$messageKeys = [
205 205
 			'string' => 'datatypes-type-string',
206 206
 			'monolingualtext' => 'datatypes-monolingualtext',
207 207
 			'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid',
208 208
 		];
209 209
 
210
-		if ( array_key_exists( $dataValueType, $messageKeys ) ) {
211
-			return Message::rawParam( $this->addRole(
212
-				wfMessage( $messageKeys[$dataValueType] )->escaped(),
210
+		if (array_key_exists($dataValueType, $messageKeys)) {
211
+			return Message::rawParam($this->addRole(
212
+				wfMessage($messageKeys[$dataValueType])->escaped(),
213 213
 				$role
214
-			) );
214
+			));
215 215
 		} else {
216 216
 			// @codeCoverageIgnoreStart
217 217
 			throw new LogicException(
218
-				'Unknown data value type ' . $dataValueType
218
+				'Unknown data value type '.$dataValueType
219 219
 			);
220 220
 			// @codeCoverageIgnoreEnd
221 221
 		}
222 222
 	}
223 223
 
224
-	private function renderInlineCode( $code, $role ) {
225
-		return Message::rawParam( $this->addRole(
226
-			'<code>' . htmlspecialchars( $code ) . '</code>',
224
+	private function renderInlineCode($code, $role) {
225
+		return Message::rawParam($this->addRole(
226
+			'<code>'.htmlspecialchars($code).'</code>',
227 227
 			$role
228
-		) );
228
+		));
229 229
 	}
230 230
 
231 231
 }
Please login to merge, or discard this patch.