@@ -332,7 +332,6 @@ |
||
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
335 | - * @param string[] $text Context::TYPE_* constants |
|
336 | 335 | * @param string|null $role one of the Role::* constants |
337 | 336 | * @return array[] list of parameters as accepted by Message::params() |
338 | 337 | */ |
@@ -66,21 +66,21 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -103,17 +103,17 @@ discard block |
||
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 |
||
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 | /** |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | * @param mixed $value the value, which should match the $type |
143 | 143 | * @return ViolationMessage |
144 | 144 | */ |
145 | - public function withArgument( $type, $role, $value ) { |
|
145 | + public function withArgument($type, $role, $value) { |
|
146 | 146 | $ret = clone $this; |
147 | - $ret->arguments[] = [ 'type' => $type, 'role' => $role, 'value' => $value ]; |
|
147 | + $ret->arguments[] = ['type' => $type, 'role' => $role, 'value' => $value]; |
|
148 | 148 | return $ret; |
149 | 149 | } |
150 | 150 | |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | * @param string|null $role one of the Role::* constants |
157 | 157 | * @return ViolationMessage |
158 | 158 | */ |
159 | - public function withEntityId( EntityId $entityId, $role = null ) { |
|
160 | - return $this->withArgument( self::TYPE_ENTITY_ID, $role, $entityId ); |
|
159 | + public function withEntityId(EntityId $entityId, $role = null) { |
|
160 | + return $this->withArgument(self::TYPE_ENTITY_ID, $role, $entityId); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -174,8 +174,8 @@ discard block |
||
174 | 174 | * @param string|null $role one of the Role::* constants |
175 | 175 | * @return ViolationMessage |
176 | 176 | */ |
177 | - public function withEntityIdList( array $entityIdList, $role = null ) { |
|
178 | - return $this->withArgument( self::TYPE_ENTITY_ID_LIST, $role, $entityIdList ); |
|
177 | + public function withEntityIdList(array $entityIdList, $role = null) { |
|
178 | + return $this->withArgument(self::TYPE_ENTITY_ID_LIST, $role, $entityIdList); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * @param string|null $role one of the Role::* constants |
187 | 187 | * @return ViolationMessage |
188 | 188 | */ |
189 | - public function withItemIdSnakValue( ItemIdSnakValue $value, $role = null ) { |
|
190 | - return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value ); |
|
189 | + public function withItemIdSnakValue(ItemIdSnakValue $value, $role = null) { |
|
190 | + return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -204,8 +204,8 @@ discard block |
||
204 | 204 | * @param string|null $role one of the Role::* constants |
205 | 205 | * @return ViolationMessage |
206 | 206 | */ |
207 | - public function withItemIdSnakValueList( array $valueList, $role = null ) { |
|
208 | - return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList ); |
|
207 | + public function withItemIdSnakValueList(array $valueList, $role = null) { |
|
208 | + return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | * @param string|null $role one of the Role::* constants |
217 | 217 | * @return ViolationMessage |
218 | 218 | */ |
219 | - public function withDataValue( DataValue $dataValue, $role = null ) { |
|
220 | - return $this->withArgument( self::TYPE_DATA_VALUE, $role, $dataValue ); |
|
219 | + public function withDataValue(DataValue $dataValue, $role = null) { |
|
220 | + return $this->withArgument(self::TYPE_DATA_VALUE, $role, $dataValue); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -232,8 +232,8 @@ discard block |
||
232 | 232 | * @param string|null $role one of the Role::* constants |
233 | 233 | * @return ViolationMessage |
234 | 234 | */ |
235 | - public function withDataValueType( $dataValueType, $role = null ) { |
|
236 | - return $this->withArgument( self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType ); |
|
235 | + public function withDataValueType($dataValueType, $role = null) { |
|
236 | + return $this->withArgument(self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | * @param string|null $role one of the Role::* constants |
245 | 245 | * @return ViolationMessage |
246 | 246 | */ |
247 | - public function withInlineCode( $code, $role = null ) { |
|
248 | - return $this->withArgument( self::TYPE_INLINE_CODE, $role, $code ); |
|
247 | + public function withInlineCode($code, $role = null) { |
|
248 | + return $this->withArgument(self::TYPE_INLINE_CODE, $role, $code); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -256,8 +256,8 @@ discard block |
||
256 | 256 | * @param string|null $role one of the Role::* constants |
257 | 257 | * @return ViolationMessage |
258 | 258 | */ |
259 | - public function withConstraintScope( $scope, $role = null ) { |
|
260 | - return $this->withArgument( self::TYPE_CONSTRAINT_SCOPE, $role, $scope ); |
|
259 | + public function withConstraintScope($scope, $role = null) { |
|
260 | + return $this->withArgument(self::TYPE_CONSTRAINT_SCOPE, $role, $scope); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | * @param string|null $role one of the Role::* constants |
269 | 269 | * @return ViolationMessage |
270 | 270 | */ |
271 | - public function withConstraintScopeList( array $scopeList, $role = null ) { |
|
272 | - return $this->withArgument( self::TYPE_CONSTRAINT_SCOPE_LIST, $role, $scopeList ); |
|
271 | + public function withConstraintScopeList(array $scopeList, $role = null) { |
|
272 | + return $this->withArgument(self::TYPE_CONSTRAINT_SCOPE_LIST, $role, $scopeList); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * @param string $languageCode |
285 | 285 | * @return ViolationMessage |
286 | 286 | */ |
287 | - public function withLanguage( $languageCode ) { |
|
288 | - return $this->withArgument( self::TYPE_LANGUAGE, null, $languageCode ); |
|
287 | + public function withLanguage($languageCode) { |
|
288 | + return $this->withArgument(self::TYPE_LANGUAGE, null, $languageCode); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
@@ -21,23 +21,23 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @return Constraint[] |
23 | 23 | */ |
24 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
25 | - $db = wfGetDB( DB_REPLICA ); |
|
24 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
25 | + $db = wfGetDB(DB_REPLICA); |
|
26 | 26 | |
27 | 27 | $results = $db->select( |
28 | 28 | 'wbqc_constraints', |
29 | 29 | '*', |
30 | - [ 'pid' => $propertyId->getNumericId() ] |
|
30 | + ['pid' => $propertyId->getNumericId()] |
|
31 | 31 | ); |
32 | 32 | |
33 | - return $this->convertToConstraints( $results ); |
|
33 | + return $this->convertToConstraints($results); |
|
34 | 34 | } |
35 | 35 | |
36 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
37 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
36 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
37 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
38 | 38 | |
39 | - if ( strlen( $json ) > 50000 ) { |
|
40 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
39 | + if (strlen($json) > 50000) { |
|
40 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | return $json; |
@@ -49,21 +49,21 @@ discard block |
||
49 | 49 | * @throws DBUnexpectedError |
50 | 50 | * @return bool |
51 | 51 | */ |
52 | - public function insertBatch( array $constraints ) { |
|
52 | + public function insertBatch(array $constraints) { |
|
53 | 53 | $accumulator = array_map( |
54 | - function ( Constraint $constraint ) { |
|
54 | + function(Constraint $constraint) { |
|
55 | 55 | return [ |
56 | 56 | 'constraint_guid' => $constraint->getConstraintId(), |
57 | 57 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
58 | 58 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
59 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
59 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
60 | 60 | ]; |
61 | 61 | }, |
62 | 62 | $constraints |
63 | 63 | ); |
64 | 64 | |
65 | - $db = wfGetDB( DB_MASTER ); |
|
66 | - return $db->insert( 'wbqc_constraints', $accumulator ); |
|
65 | + $db = wfGetDB(DB_MASTER); |
|
66 | + return $db->insert('wbqc_constraints', $accumulator); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return array |
73 | 73 | */ |
74 | - private function uuidPattern( LikeMatch $any ) { |
|
74 | + private function uuidPattern(LikeMatch $any) { |
|
75 | 75 | return array_merge( |
76 | - array_fill( 0, 8, $any ), [ '-' ], |
|
77 | - array_fill( 0, 4, $any ), [ '-' ], |
|
78 | - array_fill( 0, 4, $any ), [ '-' ], |
|
79 | - array_fill( 0, 4, $any ), [ '-' ], |
|
80 | - array_fill( 0, 12, $any ) |
|
76 | + array_fill(0, 8, $any), ['-'], |
|
77 | + array_fill(0, 4, $any), ['-'], |
|
78 | + array_fill(0, 4, $any), ['-'], |
|
79 | + array_fill(0, 4, $any), ['-'], |
|
80 | + array_fill(0, 12, $any) |
|
81 | 81 | ); |
82 | 82 | } |
83 | 83 | |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | * @throws DBUnexpectedError |
89 | 89 | */ |
90 | 90 | public function deleteWhereConstraintIdIsUuid() { |
91 | - $db = wfGetDB( DB_MASTER ); |
|
91 | + $db = wfGetDB(DB_MASTER); |
|
92 | 92 | $db->delete( |
93 | 93 | 'wbqc_constraints', |
94 | 94 | // WHERE constraint_guid LIKE ________-____-____-____-____________ |
95 | - 'constraint_guid ' . $db->buildLike( $this->uuidPattern( $db->anyChar() ) ) |
|
95 | + 'constraint_guid '.$db->buildLike($this->uuidPattern($db->anyChar())) |
|
96 | 96 | ); |
97 | 97 | } |
98 | 98 | |
@@ -104,14 +104,14 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @throws DBUnexpectedError |
106 | 106 | */ |
107 | - public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) { |
|
108 | - $db = wfGetDB( DB_MASTER ); |
|
107 | + public function deleteForPropertyWhereConstraintIdIsStatementId(PropertyId $propertyId) { |
|
108 | + $db = wfGetDB(DB_MASTER); |
|
109 | 109 | $db->delete( |
110 | 110 | 'wbqc_constraints', |
111 | 111 | [ |
112 | 112 | 'pid' => $propertyId->getNumericId(), |
113 | 113 | // AND constraint_guid LIKE %$________-____-____-____-____________ |
114 | - 'constraint_guid ' . $db->buildLike( array_merge( [ $db->anyString(), '$' ], $this->uuidPattern( $db->anyChar() ) ) ) |
|
114 | + 'constraint_guid '.$db->buildLike(array_merge([$db->anyString(), '$'], $this->uuidPattern($db->anyChar()))) |
|
115 | 115 | ] |
116 | 116 | ); |
117 | 117 | } |
@@ -122,21 +122,21 @@ discard block |
||
122 | 122 | * @throws InvalidArgumentException |
123 | 123 | * @throws DBUnexpectedError |
124 | 124 | */ |
125 | - public function deleteAll( $batchSize = 1000 ) { |
|
126 | - if ( !is_int( $batchSize ) ) { |
|
125 | + public function deleteAll($batchSize = 1000) { |
|
126 | + if (!is_int($batchSize)) { |
|
127 | 127 | throw new InvalidArgumentException(); |
128 | 128 | } |
129 | 129 | $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); |
130 | - $db = $lbFactory->getMainLB()->getConnection( DB_MASTER ); |
|
131 | - if ( $db->getType() === 'sqlite' ) { |
|
132 | - $db->delete( 'wbqc_constraints', '*' ); |
|
130 | + $db = $lbFactory->getMainLB()->getConnection(DB_MASTER); |
|
131 | + if ($db->getType() === 'sqlite') { |
|
132 | + $db->delete('wbqc_constraints', '*'); |
|
133 | 133 | } else { |
134 | 134 | do { |
135 | - $db->commit( __METHOD__, 'flush' ); |
|
135 | + $db->commit(__METHOD__, 'flush'); |
|
136 | 136 | $lbFactory->waitForReplication(); |
137 | - $table = $db->tableName( 'wbqc_constraints' ); |
|
138 | - $db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) ); |
|
139 | - } while ( $db->affectedRows() > 0 ); |
|
137 | + $table = $db->tableName('wbqc_constraints'); |
|
138 | + $db->query(sprintf('DELETE FROM %s LIMIT %d', $table, $batchSize)); |
|
139 | + } while ($db->affectedRows() > 0); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
@@ -145,26 +145,26 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return Constraint[] |
147 | 147 | */ |
148 | - private function convertToConstraints( IResultWrapper $results ) { |
|
148 | + private function convertToConstraints(IResultWrapper $results) { |
|
149 | 149 | $constraints = []; |
150 | - foreach ( $results as $result ) { |
|
150 | + foreach ($results as $result) { |
|
151 | 151 | $constraintTypeItemId = $result->constraint_type_qid; |
152 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
152 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
153 | 153 | |
154 | - if ( $constraintParameters === null ) { |
|
154 | + if ($constraintParameters === null) { |
|
155 | 155 | // T171295 |
156 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ) |
|
157 | - ->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
156 | + LoggerFactory::getInstance('WikibaseQualityConstraints') |
|
157 | + ->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
158 | 158 | 'method' => __METHOD__, |
159 | 159 | 'constraintId' => $result->constraint_guid, |
160 | 160 | 'constraintParameters' => $result->constraint_parameters, |
161 | - ] ); |
|
162 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
161 | + ]); |
|
162 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | $constraints[] = new Constraint( |
166 | 166 | $result->constraint_guid, |
167 | - PropertyId::newFromNumber( $result->pid ), |
|
167 | + PropertyId::newFromNumber($result->pid), |
|
168 | 168 | $constraintTypeItemId, |
169 | 169 | $constraintParameters |
170 | 170 | ); |
@@ -80,22 +80,22 @@ discard block |
||
80 | 80 | * @return array first element is the namespace number (default namespace for TitleParser), |
81 | 81 | * second element is a string to prepend to the title before giving it to the TitleParser |
82 | 82 | */ |
83 | - private function getCommonsNamespace( $namespace ) { |
|
83 | + private function getCommonsNamespace($namespace) { |
|
84 | 84 | // for namespace numbers see mediawiki-config repo, wmf-config/InitialiseSettings.php, |
85 | 85 | // 'wgExtraNamespaces' key, 'commonswiki' subkey |
86 | - switch ( $namespace ) { |
|
86 | + switch ($namespace) { |
|
87 | 87 | case '': |
88 | - return [ NS_MAIN, '' ]; |
|
88 | + return [NS_MAIN, '']; |
|
89 | 89 | case 'Creator': |
90 | - return [ 100, '' ]; |
|
90 | + return [100, '']; |
|
91 | 91 | case 'TimedText': |
92 | - return [ 102, '' ]; |
|
92 | + return [102, '']; |
|
93 | 93 | case 'Sequence': |
94 | - return [ 104, '' ]; |
|
94 | + return [104, '']; |
|
95 | 95 | case 'Institution': |
96 | - return [ 106, '' ]; |
|
96 | + return [106, '']; |
|
97 | 97 | default: |
98 | - return [ NS_MAIN, $namespace . ':' ]; |
|
98 | + return [NS_MAIN, $namespace.':']; |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -108,17 +108,17 @@ discard block |
||
108 | 108 | * @throws ConstraintParameterException |
109 | 109 | * @return CheckResult |
110 | 110 | */ |
111 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
111 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
112 | 112 | $parameters = []; |
113 | 113 | $constraintParameters = $constraint->getConstraintParameters(); |
114 | - $namespace = $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
115 | - $parameters['namespace'] = [ $namespace ]; |
|
114 | + $namespace = $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
115 | + $parameters['namespace'] = [$namespace]; |
|
116 | 116 | |
117 | 117 | $snak = $context->getSnak(); |
118 | 118 | |
119 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
119 | + if (!$snak instanceof PropertyValueSnak) { |
|
120 | 120 | // nothing to check |
121 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
121 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | $dataValue = $snak->getDataValue(); |
@@ -128,46 +128,46 @@ discard block |
||
128 | 128 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
129 | 129 | * parameter $namespace can be null, works for commons galleries |
130 | 130 | */ |
131 | - if ( $dataValue->getType() !== 'string' ) { |
|
132 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
133 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
134 | - ->withDataValueType( 'string' ); |
|
135 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
131 | + if ($dataValue->getType() !== 'string') { |
|
132 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
133 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
134 | + ->withDataValueType('string'); |
|
135 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | $commonsLink = $dataValue->getValue(); |
139 | 139 | |
140 | 140 | try { |
141 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
142 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
141 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
142 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
143 | 143 | } |
144 | - list( $defaultNamespace, $prefix ) = $this->getCommonsNamespace( $namespace ); |
|
145 | - $title = $this->titleParser->parseTitle( $prefix . $commonsLink, $defaultNamespace ); |
|
146 | - if ( $this->pageExists( $title ) ) { |
|
144 | + list($defaultNamespace, $prefix) = $this->getCommonsNamespace($namespace); |
|
145 | + $title = $this->titleParser->parseTitle($prefix.$commonsLink, $defaultNamespace); |
|
146 | + if ($this->pageExists($title)) { |
|
147 | 147 | $message = null; |
148 | 148 | $status = CheckResult::STATUS_COMPLIANCE; |
149 | 149 | } else { |
150 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
151 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
150 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
151 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
152 | 152 | } else { |
153 | - $message = new ViolationMessage( 'wbqc-violation-message-commons-link-no-existent' ); |
|
153 | + $message = new ViolationMessage('wbqc-violation-message-commons-link-no-existent'); |
|
154 | 154 | $status = CheckResult::STATUS_VIOLATION; |
155 | 155 | } |
156 | 156 | } |
157 | - } catch ( MalformedTitleException $e ) { |
|
158 | - $message = new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ); |
|
157 | + } catch (MalformedTitleException $e) { |
|
158 | + $message = new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed'); |
|
159 | 159 | $status = CheckResult::STATUS_VIOLATION; |
160 | 160 | } |
161 | 161 | |
162 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
162 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
163 | 163 | } |
164 | 164 | |
165 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
165 | + public function checkConstraintParameters(Constraint $constraint) { |
|
166 | 166 | $constraintParameters = $constraint->getConstraintParameters(); |
167 | 167 | $exceptions = []; |
168 | 168 | try { |
169 | - $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
170 | - } catch ( ConstraintParameterException $e ) { |
|
169 | + $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
170 | + } catch (ConstraintParameterException $e) { |
|
171 | 171 | $exceptions[] = $e; |
172 | 172 | } |
173 | 173 | return $exceptions; |
@@ -178,20 +178,20 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @return bool |
180 | 180 | */ |
181 | - private function pageExists( TitleValue $title ) { |
|
181 | + private function pageExists(TitleValue $title) { |
|
182 | 182 | $commonsWikiId = 'commonswiki'; |
183 | - if ( defined( 'MW_PHPUNIT_TEST' ) ) { |
|
183 | + if (defined('MW_PHPUNIT_TEST')) { |
|
184 | 184 | $commonsWikiId = false; |
185 | 185 | } |
186 | 186 | |
187 | 187 | $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); |
188 | - $dbConnection = $lbFactory->getMainLB( $commonsWikiId )->getConnection( |
|
188 | + $dbConnection = $lbFactory->getMainLB($commonsWikiId)->getConnection( |
|
189 | 189 | DB_REPLICA, false, $commonsWikiId |
190 | 190 | ); |
191 | - $row = $dbConnection->selectRow( 'page', '*', [ |
|
191 | + $row = $dbConnection->selectRow('page', '*', [ |
|
192 | 192 | 'page_title' => $title->getDBkey(), |
193 | 193 | 'page_namespace' => $title->getNamespace() |
194 | - ] ); |
|
194 | + ]); |
|
195 | 195 | |
196 | 196 | return $row !== false; |
197 | 197 | } |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @return bool |
203 | 203 | */ |
204 | - private function commonsLinkIsWellFormed( $commonsLink ) { |
|
205 | - $toReplace = [ "_", "%20" ]; |
|
206 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
204 | + private function commonsLinkIsWellFormed($commonsLink) { |
|
205 | + $toReplace = ["_", "%20"]; |
|
206 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
207 | 207 | return $commonsLink === $compareString; |
208 | 208 | } |
209 | 209 | |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @return bool |
218 | 218 | */ |
219 | - private function valueIncludesNamespace( $value, $namespace ) { |
|
219 | + private function valueIncludesNamespace($value, $namespace) { |
|
220 | 220 | return $namespace !== '' && |
221 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
221 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | } |
@@ -14,26 +14,26 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class ViolationMessageSerializer implements Serializer { |
16 | 16 | |
17 | - private function abbreviateViolationMessageKey( $fullMessageKey ) { |
|
18 | - return substr( $fullMessageKey, strlen( ViolationMessage::MESSAGE_KEY_PREFIX ) ); |
|
17 | + private function abbreviateViolationMessageKey($fullMessageKey) { |
|
18 | + return substr($fullMessageKey, strlen(ViolationMessage::MESSAGE_KEY_PREFIX)); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @param ViolationMessage $object |
23 | 23 | * @return array |
24 | 24 | */ |
25 | - public function serialize( $object ) { |
|
25 | + public function serialize($object) { |
|
26 | 26 | /** @var ViolationMessage $object */ |
27 | - Assert::parameterType( ViolationMessage::class, $object, '$object' ); |
|
27 | + Assert::parameterType(ViolationMessage::class, $object, '$object'); |
|
28 | 28 | |
29 | 29 | $arguments = $object->getArguments(); |
30 | 30 | $serializedArguments = []; |
31 | - foreach ( $arguments as $argument ) { |
|
32 | - $serializedArguments[] = $this->serializeArgument( $argument ); |
|
31 | + foreach ($arguments as $argument) { |
|
32 | + $serializedArguments[] = $this->serializeArgument($argument); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | return [ |
36 | - 'k' => $this->abbreviateViolationMessageKey( $object->getMessageKey() ), |
|
36 | + 'k' => $this->abbreviateViolationMessageKey($object->getMessageKey()), |
|
37 | 37 | 'a' => $serializedArguments, |
38 | 38 | ]; |
39 | 39 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @return array [ 't' => ViolationMessage::TYPE_*, 'v' => serialized value, |
44 | 44 | * 'r' => $role, (optional) 'a' => $alternativeMessageKey ] |
45 | 45 | */ |
46 | - private function serializeArgument( array $argument ) { |
|
46 | + private function serializeArgument(array $argument) { |
|
47 | 47 | $methods = [ |
48 | 48 | ViolationMessage::TYPE_ENTITY_ID => 'serializeEntityId', |
49 | 49 | ]; |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | $value = $argument['value']; |
53 | 53 | $role = $argument['role']; |
54 | 54 | |
55 | - if ( array_key_exists( $type, $methods ) ) { |
|
55 | + if (array_key_exists($type, $methods)) { |
|
56 | 56 | $method = $methods[$type]; |
57 | - $serializedValue = $this->$method( $value ); |
|
57 | + $serializedValue = $this->$method($value); |
|
58 | 58 | } else { |
59 | 59 | throw new InvalidArgumentException( |
60 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
60 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
61 | 61 | ); |
62 | 62 | } |
63 | 63 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | 'r' => $role, |
68 | 68 | ]; |
69 | 69 | |
70 | - if ( array_key_exists( 'alternativeMessageKey', $argument ) ) { |
|
70 | + if (array_key_exists('alternativeMessageKey', $argument)) { |
|
71 | 71 | $serialized['a'] = $this->abbreviateViolationMessageKey( |
72 | 72 | $argument['alternativeMessageKey'] |
73 | 73 | ); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @param EntityId $entityId |
81 | 81 | * @return string entity ID serialization |
82 | 82 | */ |
83 | - private function serializeEntityId( EntityId $entityId ) { |
|
83 | + private function serializeEntityId(EntityId $entityId) { |
|
84 | 84 | return $entityId->getSerialization(); |
85 | 85 | } |
86 | 86 |
@@ -26,23 +26,23 @@ discard block |
||
26 | 26 | $this->entityIdParser = $entityIdParser; |
27 | 27 | } |
28 | 28 | |
29 | - public function unabbreviateViolationMessageKey( $messageKeySuffix ) { |
|
30 | - return ViolationMessage::MESSAGE_KEY_PREFIX . $messageKeySuffix; |
|
29 | + public function unabbreviateViolationMessageKey($messageKeySuffix) { |
|
30 | + return ViolationMessage::MESSAGE_KEY_PREFIX.$messageKeySuffix; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @param array $serialization |
35 | 35 | * @return ViolationMessage |
36 | 36 | */ |
37 | - public function deserialize( $serialization ) { |
|
38 | - Assert::parameterType( 'array', $serialization, '$serialization' ); |
|
37 | + public function deserialize($serialization) { |
|
38 | + Assert::parameterType('array', $serialization, '$serialization'); |
|
39 | 39 | |
40 | 40 | $message = new ViolationMessage( |
41 | - $this->unabbreviateViolationMessageKey( $serialization['k'] ) |
|
41 | + $this->unabbreviateViolationMessageKey($serialization['k']) |
|
42 | 42 | ); |
43 | 43 | |
44 | - foreach ( $serialization['a'] as $serializedArgument ) { |
|
45 | - $message = $this->deserializeArgument( $message, $serializedArgument ); |
|
44 | + foreach ($serialization['a'] as $serializedArgument) { |
|
45 | + $message = $this->deserializeArgument($message, $serializedArgument); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | return $message; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * 'r' => $role, (optional) 'a' => $alternativeMessageKey ] |
55 | 55 | * @return ViolationMessage $message with the deserialized argument appended |
56 | 56 | */ |
57 | - private function deserializeArgument( ViolationMessage $message, array $serializedArgument ) { |
|
57 | + private function deserializeArgument(ViolationMessage $message, array $serializedArgument) { |
|
58 | 58 | $methods = [ |
59 | 59 | ViolationMessage::TYPE_ENTITY_ID => 'deserializeEntityId', |
60 | 60 | ]; |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $type = $serializedArgument['t']; |
63 | 63 | $serializedValue = $serializedArgument['v']; |
64 | 64 | $role = $serializedArgument['r']; |
65 | - if ( array_key_exists( 'a', $serializedArgument ) ) { |
|
65 | + if (array_key_exists('a', $serializedArgument)) { |
|
66 | 66 | $alternativeMessageKey = $this->unabbreviateViolationMessageKey( |
67 | 67 | $serializedArgument['a'] |
68 | 68 | ); |
@@ -70,24 +70,24 @@ discard block |
||
70 | 70 | $alternativeMessageKey = null; |
71 | 71 | } |
72 | 72 | |
73 | - if ( array_key_exists( $type, $methods ) ) { |
|
73 | + if (array_key_exists($type, $methods)) { |
|
74 | 74 | $method = $methods[$type]; |
75 | - $value = $this->$method( $serializedValue ); |
|
75 | + $value = $this->$method($serializedValue); |
|
76 | 76 | } else { |
77 | 77 | throw new InvalidArgumentException( |
78 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
78 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
79 | 79 | ); |
80 | 80 | } |
81 | 81 | |
82 | - return $message->withArgument( $type, $role, $value, $alternativeMessageKey ); |
|
82 | + return $message->withArgument($type, $role, $value, $alternativeMessageKey); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
86 | 86 | * @param string $entityIdSerialization entity ID serialization |
87 | 87 | * @return EntityId |
88 | 88 | */ |
89 | - private function deserializeEntityId( $entityIdSerialization ) { |
|
90 | - return $this->entityIdParser->parse( $entityIdSerialization ); |
|
89 | + private function deserializeEntityId($entityIdSerialization) { |
|
90 | + return $this->entityIdParser->parse($entityIdSerialization); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | } |