@@ -97,17 +97,17 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -65,31 +65,31 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |