@@ -110,17 +110,17 @@ discard block |
||
110 | 110 | public function __construct( |
111 | 111 | $messageKey |
112 | 112 | ) { |
113 | - if ( strpos( $messageKey, self::MESSAGE_KEY_PREFIX ) !== 0 ) { |
|
113 | + if (strpos($messageKey, self::MESSAGE_KEY_PREFIX) !== 0) { |
|
114 | 114 | throw new InvalidArgumentException( |
115 | - 'ViolationMessage key ⧼' . |
|
116 | - $messageKey . |
|
117 | - '⧽ should start with "' . |
|
118 | - self::MESSAGE_KEY_PREFIX . |
|
115 | + 'ViolationMessage key ⧼'. |
|
116 | + $messageKey. |
|
117 | + '⧽ should start with "'. |
|
118 | + self::MESSAGE_KEY_PREFIX. |
|
119 | 119 | '".' |
120 | 120 | ); |
121 | 121 | } |
122 | 122 | |
123 | - $this->messageKeySuffix = substr( $messageKey, strlen( self::MESSAGE_KEY_PREFIX ) ); |
|
123 | + $this->messageKeySuffix = substr($messageKey, strlen(self::MESSAGE_KEY_PREFIX)); |
|
124 | 124 | $this->arguments = []; |
125 | 125 | } |
126 | 126 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @return string |
130 | 130 | */ |
131 | 131 | public function getMessageKey() { |
132 | - return self::MESSAGE_KEY_PREFIX . $this->messageKeySuffix; |
|
132 | + return self::MESSAGE_KEY_PREFIX.$this->messageKeySuffix; |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -149,9 +149,9 @@ discard block |
||
149 | 149 | * @param mixed $value the value, which should match the $type |
150 | 150 | * @return ViolationMessage |
151 | 151 | */ |
152 | - public function withArgument( $type, $role, $value ) { |
|
152 | + public function withArgument($type, $role, $value) { |
|
153 | 153 | $ret = clone $this; |
154 | - $ret->arguments[] = [ 'type' => $type, 'role' => $role, 'value' => $value ]; |
|
154 | + $ret->arguments[] = ['type' => $type, 'role' => $role, 'value' => $value]; |
|
155 | 155 | return $ret; |
156 | 156 | } |
157 | 157 | |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | * @param string|null $role one of the Role::* constants |
164 | 164 | * @return ViolationMessage |
165 | 165 | */ |
166 | - public function withEntityId( EntityId $entityId, $role = null ) { |
|
167 | - return $this->withArgument( self::TYPE_ENTITY_ID, $role, $entityId ); |
|
166 | + public function withEntityId(EntityId $entityId, $role = null) { |
|
167 | + return $this->withArgument(self::TYPE_ENTITY_ID, $role, $entityId); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * @param string|null $role one of the Role::* constants |
182 | 182 | * @return ViolationMessage |
183 | 183 | */ |
184 | - public function withEntityIdList( array $entityIdList, $role = null ) { |
|
185 | - return $this->withArgument( self::TYPE_ENTITY_ID_LIST, $role, $entityIdList ); |
|
184 | + public function withEntityIdList(array $entityIdList, $role = null) { |
|
185 | + return $this->withArgument(self::TYPE_ENTITY_ID_LIST, $role, $entityIdList); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | * @param string|null $role one of the Role::* constants |
194 | 194 | * @return ViolationMessage |
195 | 195 | */ |
196 | - public function withItemIdSnakValue( ItemIdSnakValue $value, $role = null ) { |
|
197 | - return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value ); |
|
196 | + public function withItemIdSnakValue(ItemIdSnakValue $value, $role = null) { |
|
197 | + return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -211,8 +211,8 @@ discard block |
||
211 | 211 | * @param string|null $role one of the Role::* constants |
212 | 212 | * @return ViolationMessage |
213 | 213 | */ |
214 | - public function withItemIdSnakValueList( array $valueList, $role = null ) { |
|
215 | - return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList ); |
|
214 | + public function withItemIdSnakValueList(array $valueList, $role = null) { |
|
215 | + return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * @param string|null $role one of the Role::* constants |
224 | 224 | * @return ViolationMessage |
225 | 225 | */ |
226 | - public function withDataValue( DataValue $dataValue, $role = null ) { |
|
227 | - return $this->withArgument( self::TYPE_DATA_VALUE, $role, $dataValue ); |
|
226 | + public function withDataValue(DataValue $dataValue, $role = null) { |
|
227 | + return $this->withArgument(self::TYPE_DATA_VALUE, $role, $dataValue); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -239,8 +239,8 @@ discard block |
||
239 | 239 | * @param string|null $role one of the Role::* constants |
240 | 240 | * @return ViolationMessage |
241 | 241 | */ |
242 | - public function withDataValueType( $dataValueType, $role = null ) { |
|
243 | - return $this->withArgument( self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType ); |
|
242 | + public function withDataValueType($dataValueType, $role = null) { |
|
243 | + return $this->withArgument(self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | * @param string|null $role one of the Role::* constants |
252 | 252 | * @return ViolationMessage |
253 | 253 | */ |
254 | - public function withInlineCode( $code, $role = null ) { |
|
255 | - return $this->withArgument( self::TYPE_INLINE_CODE, $role, $code ); |
|
254 | + public function withInlineCode($code, $role = null) { |
|
255 | + return $this->withArgument(self::TYPE_INLINE_CODE, $role, $code); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | * @param string|null $role one of the Role::* constants |
264 | 264 | * @return ViolationMessage |
265 | 265 | */ |
266 | - public function withConstraintScope( $scope, $role = null ) { |
|
267 | - return $this->withArgument( self::TYPE_CONSTRAINT_SCOPE, $role, $scope ); |
|
266 | + public function withConstraintScope($scope, $role = null) { |
|
267 | + return $this->withArgument(self::TYPE_CONSTRAINT_SCOPE, $role, $scope); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -275,8 +275,8 @@ discard block |
||
275 | 275 | * @param string|null $role one of the Role::* constants |
276 | 276 | * @return ViolationMessage |
277 | 277 | */ |
278 | - public function withConstraintScopeList( array $scopeList, $role = null ) { |
|
279 | - return $this->withArgument( self::TYPE_CONSTRAINT_SCOPE_LIST, $role, $scopeList ); |
|
278 | + public function withConstraintScopeList(array $scopeList, $role = null) { |
|
279 | + return $this->withArgument(self::TYPE_CONSTRAINT_SCOPE_LIST, $role, $scopeList); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -291,8 +291,8 @@ discard block |
||
291 | 291 | * @param string $languageCode |
292 | 292 | * @return ViolationMessage |
293 | 293 | */ |
294 | - public function withLanguage( $languageCode ) { |
|
295 | - return $this->withArgument( self::TYPE_LANGUAGE, null, $languageCode ); |
|
294 | + public function withLanguage($languageCode) { |
|
295 | + return $this->withArgument(self::TYPE_LANGUAGE, null, $languageCode); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -307,8 +307,8 @@ discard block |
||
307 | 307 | * @param string|null $role one of the Role::* constants |
308 | 308 | * @return ViolationMessage |
309 | 309 | */ |
310 | - public function withMultilingualText( MultilingualTextValue $text, $role = null ) { |
|
311 | - return $this->withArgument( self::TYPE_MULTILINGUAL_TEXT, $role, $text ); |
|
310 | + public function withMultilingualText(MultilingualTextValue $text, $role = null) { |
|
311 | + return $this->withArgument(self::TYPE_MULTILINGUAL_TEXT, $role, $text); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | } |
@@ -69,21 +69,21 @@ discard block |
||
69 | 69 | * (temporarily, pre-rendered strings are allowed and returned without changes) |
70 | 70 | * @return string |
71 | 71 | */ |
72 | - public function render( $violationMessage ) { |
|
73 | - if ( is_string( $violationMessage ) ) { |
|
72 | + public function render($violationMessage) { |
|
73 | + if (is_string($violationMessage)) { |
|
74 | 74 | // TODO remove this once all checkers produce ViolationMessage objects |
75 | 75 | return $violationMessage; |
76 | 76 | } |
77 | 77 | |
78 | 78 | $messageKey = $violationMessage->getMessageKey(); |
79 | - $paramsLists = [ [] ]; |
|
80 | - foreach ( $violationMessage->getArguments() as $argument ) { |
|
81 | - $params = $this->renderArgument( $argument ); |
|
79 | + $paramsLists = [[]]; |
|
80 | + foreach ($violationMessage->getArguments() as $argument) { |
|
81 | + $params = $this->renderArgument($argument); |
|
82 | 82 | $paramsLists[] = $params; |
83 | 83 | } |
84 | - $allParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
85 | - return ( new Message( $messageKey ) ) |
|
86 | - ->params( $allParams ) |
|
84 | + $allParams = call_user_func_array('array_merge', $paramsLists); |
|
85 | + return (new Message($messageKey)) |
|
86 | + ->params($allParams) |
|
87 | 87 | ->escaped(); |
88 | 88 | } |
89 | 89 | |
@@ -92,13 +92,13 @@ discard block |
||
92 | 92 | * @param string|null $role one of the Role::* constants |
93 | 93 | * @return string HTML |
94 | 94 | */ |
95 | - protected function addRole( $value, $role ) { |
|
96 | - if ( $role === null ) { |
|
95 | + protected function addRole($value, $role) { |
|
96 | + if ($role === null) { |
|
97 | 97 | return $value; |
98 | 98 | } |
99 | 99 | |
100 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' . |
|
101 | - $value . |
|
100 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'. |
|
101 | + $value. |
|
102 | 102 | '</span>'; |
103 | 103 | } |
104 | 104 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @param array $argument |
107 | 107 | * @return array[] params (for Message::params) |
108 | 108 | */ |
109 | - protected function renderArgument( array $argument ) { |
|
109 | + protected function renderArgument(array $argument) { |
|
110 | 110 | $methods = [ |
111 | 111 | ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId', |
112 | 112 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList', |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | $value = $argument['value']; |
125 | 125 | $role = $argument['role']; |
126 | 126 | |
127 | - if ( array_key_exists( $type, $methods ) ) { |
|
127 | + if (array_key_exists($type, $methods)) { |
|
128 | 128 | $method = $methods[$type]; |
129 | - $params = $this->$method( $value, $role ); |
|
129 | + $params = $this->$method($value, $role); |
|
130 | 130 | } else { |
131 | 131 | throw new InvalidArgumentException( |
132 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
132 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
133 | 133 | ); |
134 | 134 | } |
135 | 135 | |
@@ -143,46 +143,46 @@ discard block |
||
143 | 143 | * and return a single-element array with a raw message param (i. e. [ Message::rawParam( … ) ]) |
144 | 144 | * @return array[] list of parameters as accepted by Message::params() |
145 | 145 | */ |
146 | - private function renderList( array $list, $role, callable $render ) { |
|
147 | - if ( $list === [] ) { |
|
146 | + private function renderList(array $list, $role, callable $render) { |
|
147 | + if ($list === []) { |
|
148 | 148 | return [ |
149 | - Message::numParam( 0 ), |
|
150 | - Message::rawParam( '<ul></ul>' ), |
|
149 | + Message::numParam(0), |
|
150 | + Message::rawParam('<ul></ul>'), |
|
151 | 151 | ]; |
152 | 152 | } |
153 | 153 | |
154 | - if ( count( $list ) > $this->maxListLength ) { |
|
155 | - $list = array_slice( $list, 0, $this->maxListLength ); |
|
154 | + if (count($list) > $this->maxListLength) { |
|
155 | + $list = array_slice($list, 0, $this->maxListLength); |
|
156 | 156 | $truncated = true; |
157 | 157 | } |
158 | 158 | |
159 | 159 | $renderedParamsLists = array_map( |
160 | 160 | $render, |
161 | 161 | $list, |
162 | - array_fill( 0, count( $list ), $role ) |
|
162 | + array_fill(0, count($list), $role) |
|
163 | 163 | ); |
164 | 164 | $renderedParams = array_map( |
165 | - function ( $params ) { |
|
165 | + function($params) { |
|
166 | 166 | return $params[0]; |
167 | 167 | }, |
168 | 168 | $renderedParamsLists |
169 | 169 | ); |
170 | 170 | $renderedElements = array_map( |
171 | - function ( $param ) { |
|
171 | + function($param) { |
|
172 | 172 | return $param['raw']; |
173 | 173 | }, |
174 | 174 | $renderedParams |
175 | 175 | ); |
176 | - if ( isset( $truncated ) ) { |
|
177 | - $renderedElements[] = wfMessage( 'ellipsis' )->escaped(); |
|
176 | + if (isset($truncated)) { |
|
177 | + $renderedElements[] = wfMessage('ellipsis')->escaped(); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | return array_merge( |
181 | 181 | [ |
182 | - Message::numParam( count( $list ) ), |
|
182 | + Message::numParam(count($list)), |
|
183 | 183 | Message::rawParam( |
184 | - '<ul><li>' . |
|
185 | - implode( '</li><li>', $renderedElements ) . |
|
184 | + '<ul><li>'. |
|
185 | + implode('</li><li>', $renderedElements). |
|
186 | 186 | '</li></ul>' |
187 | 187 | ), |
188 | 188 | ], |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | * @param string|null $role one of the Role::* constants |
196 | 196 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
197 | 197 | */ |
198 | - private function renderEntityId( EntityId $entityId, $role ) { |
|
199 | - return [ Message::rawParam( $this->addRole( |
|
200 | - $this->entityIdFormatter->formatEntityId( $entityId ), |
|
198 | + private function renderEntityId(EntityId $entityId, $role) { |
|
199 | + return [Message::rawParam($this->addRole( |
|
200 | + $this->entityIdFormatter->formatEntityId($entityId), |
|
201 | 201 | $role |
202 | - ) ) ]; |
|
202 | + ))]; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | * @param string|null $role one of the Role::* constants |
208 | 208 | * @return array[] list of parameters as accepted by Message::params() |
209 | 209 | */ |
210 | - private function renderEntityIdList( array $entityIdList, $role ) { |
|
211 | - return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] ); |
|
210 | + private function renderEntityIdList(array $entityIdList, $role) { |
|
211 | + return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -216,24 +216,24 @@ discard block |
||
216 | 216 | * @param string|null $role one of the Role::* constants |
217 | 217 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
218 | 218 | */ |
219 | - private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) { |
|
220 | - switch ( true ) { |
|
219 | + private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) { |
|
220 | + switch (true) { |
|
221 | 221 | case $value->isValue(): |
222 | - return $this->renderEntityId( $value->getItemId(), $role ); |
|
222 | + return $this->renderEntityId($value->getItemId(), $role); |
|
223 | 223 | case $value->isSomeValue(): |
224 | - return [ Message::rawParam( $this->addRole( |
|
225 | - '<span class="wikibase-snakview-variation-somevaluesnak">' . |
|
226 | - wfMessage( 'wikibase-snakview-snaktypeselector-somevalue' )->escaped() . |
|
224 | + return [Message::rawParam($this->addRole( |
|
225 | + '<span class="wikibase-snakview-variation-somevaluesnak">'. |
|
226 | + wfMessage('wikibase-snakview-snaktypeselector-somevalue')->escaped(). |
|
227 | 227 | '</span>', |
228 | 228 | $role |
229 | - ) ) ]; |
|
229 | + ))]; |
|
230 | 230 | case $value->isNoValue(): |
231 | - return [ Message::rawParam( $this->addRole( |
|
232 | - '<span class="wikibase-snakview-variation-novaluesnak">' . |
|
233 | - wfMessage( 'wikibase-snakview-snaktypeselector-novalue' )->escaped() . |
|
231 | + return [Message::rawParam($this->addRole( |
|
232 | + '<span class="wikibase-snakview-variation-novaluesnak">'. |
|
233 | + wfMessage('wikibase-snakview-snaktypeselector-novalue')->escaped(). |
|
234 | 234 | '</span>', |
235 | 235 | $role |
236 | - ) ) ]; |
|
236 | + ))]; |
|
237 | 237 | default: |
238 | 238 | // @codeCoverageIgnoreStart |
239 | 239 | throw new LogicException( |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | * @param string|null $role one of the Role::* constants |
249 | 249 | * @return array[] list of parameters as accepted by Message::params() |
250 | 250 | */ |
251 | - private function renderItemIdSnakValueList( array $valueList, $role ) { |
|
252 | - return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] ); |
|
251 | + private function renderItemIdSnakValueList(array $valueList, $role) { |
|
252 | + return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -257,11 +257,11 @@ discard block |
||
257 | 257 | * @param string|null $role one of the Role::* constants |
258 | 258 | * @return array[] list of parameters as accepted by Message::params() |
259 | 259 | */ |
260 | - private function renderDataValue( DataValue $dataValue, $role ) { |
|
261 | - return [ Message::rawParam( $this->addRole( |
|
262 | - $this->dataValueFormatter->format( $dataValue ), |
|
260 | + private function renderDataValue(DataValue $dataValue, $role) { |
|
261 | + return [Message::rawParam($this->addRole( |
|
262 | + $this->dataValueFormatter->format($dataValue), |
|
263 | 263 | $role |
264 | - ) ) ]; |
|
264 | + ))]; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -269,22 +269,22 @@ discard block |
||
269 | 269 | * @param string|null $role one of the Role::* constants |
270 | 270 | * @return array[] list of parameters as accepted by Message::params() |
271 | 271 | */ |
272 | - private function renderDataValueType( $dataValueType, $role ) { |
|
272 | + private function renderDataValueType($dataValueType, $role) { |
|
273 | 273 | $messageKeys = [ |
274 | 274 | 'string' => 'datatypes-type-string', |
275 | 275 | 'monolingualtext' => 'datatypes-monolingualtext', |
276 | 276 | 'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid', |
277 | 277 | ]; |
278 | 278 | |
279 | - if ( array_key_exists( $dataValueType, $messageKeys ) ) { |
|
280 | - return [ Message::rawParam( $this->addRole( |
|
281 | - wfMessage( $messageKeys[$dataValueType] )->escaped(), |
|
279 | + if (array_key_exists($dataValueType, $messageKeys)) { |
|
280 | + return [Message::rawParam($this->addRole( |
|
281 | + wfMessage($messageKeys[$dataValueType])->escaped(), |
|
282 | 282 | $role |
283 | - ) ) ]; |
|
283 | + ))]; |
|
284 | 284 | } else { |
285 | 285 | // @codeCoverageIgnoreStart |
286 | 286 | throw new LogicException( |
287 | - 'Unknown data value type ' . $dataValueType |
|
287 | + 'Unknown data value type '.$dataValueType |
|
288 | 288 | ); |
289 | 289 | // @codeCoverageIgnoreEnd |
290 | 290 | } |
@@ -295,11 +295,11 @@ discard block |
||
295 | 295 | * @param string|null $role one of the Role::* constants |
296 | 296 | * @return array[] list of parameters as accepted by Message::params() |
297 | 297 | */ |
298 | - private function renderInlineCode( $code, $role ) { |
|
299 | - return [ Message::rawParam( $this->addRole( |
|
300 | - '<code>' . htmlspecialchars( $code ) . '</code>', |
|
298 | + private function renderInlineCode($code, $role) { |
|
299 | + return [Message::rawParam($this->addRole( |
|
300 | + '<code>'.htmlspecialchars($code).'</code>', |
|
301 | 301 | $role |
302 | - ) ) ]; |
|
302 | + ))]; |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -307,8 +307,8 @@ discard block |
||
307 | 307 | * @param string|null $role one of the Role::* constants |
308 | 308 | * @return array[] list of a single raw message param (i. e. [ Message::rawParam( … ) ]) |
309 | 309 | */ |
310 | - private function renderConstraintScope( $scope, $role ) { |
|
311 | - switch ( $scope ) { |
|
310 | + private function renderConstraintScope($scope, $role) { |
|
311 | + switch ($scope) { |
|
312 | 312 | case Context::TYPE_STATEMENT: |
313 | 313 | $itemId = $this->config->get( |
314 | 314 | 'WBQualityConstraintsConstraintCheckedOnMainValueId' |
@@ -328,10 +328,10 @@ discard block |
||
328 | 328 | // callers should never let this happen, but if it does happen, |
329 | 329 | // showing “unknown value” seems reasonable |
330 | 330 | // @codeCoverageIgnoreStart |
331 | - return $this->renderItemIdSnakValue( ItemIdSnakValue::someValue(), $role ); |
|
331 | + return $this->renderItemIdSnakValue(ItemIdSnakValue::someValue(), $role); |
|
332 | 332 | // @codeCoverageIgnoreEnd |
333 | 333 | } |
334 | - return $this->renderEntityId( new ItemId( $itemId ), $role ); |
|
334 | + return $this->renderEntityId(new ItemId($itemId), $role); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | * @param string|null $role one of the Role::* constants |
340 | 340 | * @return array[] list of parameters as accepted by Message::params() |
341 | 341 | */ |
342 | - private function renderConstraintScopeList( array $scopeList, $role ) { |
|
343 | - return $this->renderList( $scopeList, $role, [ $this, 'renderConstraintScope' ] ); |
|
342 | + private function renderConstraintScopeList(array $scopeList, $role) { |
|
343 | + return $this->renderList($scopeList, $role, [$this, 'renderConstraintScope']); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
@@ -348,10 +348,10 @@ discard block |
||
348 | 348 | * @param string|null $role one of the Role::* constants |
349 | 349 | * @return array[] list of parameters as accepted by Message::params() |
350 | 350 | */ |
351 | - private function renderLanguage( $languageCode, $role ) { |
|
351 | + private function renderLanguage($languageCode, $role) { |
|
352 | 352 | return [ |
353 | - Message::plaintextParam( Language::fetchLanguageName( $languageCode ) ), |
|
354 | - Message::plaintextParam( $languageCode ), |
|
353 | + Message::plaintextParam(Language::fetchLanguageName($languageCode)), |
|
354 | + Message::plaintextParam($languageCode), |
|
355 | 355 | ]; |
356 | 356 | } |
357 | 357 |
@@ -77,21 +77,21 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return self |
79 | 79 | */ |
80 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
80 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
81 | 81 | $repo = WikibaseRepo::getDefaultInstance(); |
82 | 82 | |
83 | 83 | $language = $repo->getUserLanguage(); |
84 | 84 | $formatterOptions = new FormatterOptions(); |
85 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
85 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
86 | 86 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
87 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
87 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
88 | 88 | |
89 | 89 | $languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory(); |
90 | - $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language ); |
|
90 | + $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language); |
|
91 | 91 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
92 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
92 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
93 | 93 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
94 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
94 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
95 | 95 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
96 | 96 | $titleParser = MediaWikiServices::getInstance()->getTitleParser(); |
97 | 97 | $unitConverter = $repo->getUnitConverter(); |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | $repo->getEntityTitleLookup(), |
125 | 125 | $entityIdLabelFormatter, |
126 | 126 | $constraintParameterRenderer, |
127 | - new MultilingualTextViolationMessageRenderer( $entityIdHtmlLinkFormatter, $valueFormatter, $config ), |
|
127 | + new MultilingualTextViolationMessageRenderer($entityIdHtmlLinkFormatter, $valueFormatter, $config), |
|
128 | 128 | $config |
129 | 129 | ); |
130 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
130 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
131 | 131 | $wikiPageEntityMetaDataAccessor = new WikiPageEntityMetaDataLookup( |
132 | 132 | $repo->getEntityNamespaceLookup() |
133 | 133 | ); |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | ResultsCache::getDefaultInstance(), |
139 | 139 | $wikiPageEntityMetaDataAccessor, |
140 | 140 | $entityIdParser, |
141 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
141 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
142 | 142 | [ |
143 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
144 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
145 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
146 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
143 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
144 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
145 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
146 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
147 | 147 | ], |
148 | 148 | $dataFactory |
149 | 149 | ); |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $prefix, |
156 | 156 | $repo->getEntityIdParser(), |
157 | 157 | $repo->getStatementGuidValidator(), |
158 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
158 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
159 | 159 | $resultsBuilder, |
160 | 160 | $dataFactory |
161 | 161 | ); |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | ResultsBuilder $resultsBuilder, |
182 | 182 | IBufferingStatsdDataFactory $dataFactory |
183 | 183 | ) { |
184 | - parent::__construct( $main, $name, $prefix ); |
|
184 | + parent::__construct($main, $name, $prefix); |
|
185 | 185 | $this->entityIdParser = $entityIdParser; |
186 | 186 | $this->statementGuidValidator = $statementGuidValidator; |
187 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
188 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
187 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
188 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
189 | 189 | $this->resultsBuilder = $resultsBuilder; |
190 | 190 | $this->dataFactory = $dataFactory; |
191 | 191 | } |
@@ -200,9 +200,9 @@ discard block |
||
200 | 200 | |
201 | 201 | $params = $this->extractRequestParams(); |
202 | 202 | |
203 | - $this->validateParameters( $params ); |
|
204 | - $entityIds = $this->parseEntityIds( $params ); |
|
205 | - $claimIds = $this->parseClaimIds( $params ); |
|
203 | + $this->validateParameters($params); |
|
204 | + $entityIds = $this->parseEntityIds($params); |
|
205 | + $claimIds = $this->parseClaimIds($params); |
|
206 | 206 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
207 | 207 | $statuses = $params[self::PARAM_STATUS]; |
208 | 208 | |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | )->getArray() |
218 | 218 | ); |
219 | 219 | // ensure that result contains the given entity IDs even if they have no statements |
220 | - foreach ( $entityIds as $entityId ) { |
|
220 | + foreach ($entityIds as $entityId) { |
|
221 | 221 | $this->getResult()->addArrayType( |
222 | - [ $this->getModuleName(), $entityId->getSerialization() ], |
|
222 | + [$this->getModuleName(), $entityId->getSerialization()], |
|
223 | 223 | 'assoc' |
224 | 224 | ); |
225 | 225 | } |
226 | - $this->resultBuilder->markSuccess( 1 ); |
|
226 | + $this->resultBuilder->markSuccess(1); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -231,24 +231,24 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return EntityId[] |
233 | 233 | */ |
234 | - private function parseEntityIds( array $params ) { |
|
234 | + private function parseEntityIds(array $params) { |
|
235 | 235 | $ids = $params[self::PARAM_ID]; |
236 | 236 | |
237 | - if ( $ids === null ) { |
|
237 | + if ($ids === null) { |
|
238 | 238 | return []; |
239 | - } elseif ( $ids === [] ) { |
|
239 | + } elseif ($ids === []) { |
|
240 | 240 | $this->errorReporter->dieError( |
241 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
241 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
242 | 242 | } |
243 | 243 | |
244 | - return array_map( function ( $id ) { |
|
244 | + return array_map(function($id) { |
|
245 | 245 | try { |
246 | - return $this->entityIdParser->parse( $id ); |
|
247 | - } catch ( EntityIdParsingException $e ) { |
|
246 | + return $this->entityIdParser->parse($id); |
|
247 | + } catch (EntityIdParsingException $e) { |
|
248 | 248 | $this->errorReporter->dieError( |
249 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
249 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
250 | 250 | } |
251 | - }, $ids ); |
|
251 | + }, $ids); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -256,35 +256,35 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @return string[] |
258 | 258 | */ |
259 | - private function parseClaimIds( array $params ) { |
|
259 | + private function parseClaimIds(array $params) { |
|
260 | 260 | $ids = $params[self::PARAM_CLAIM_ID]; |
261 | 261 | |
262 | - if ( $ids === null ) { |
|
262 | + if ($ids === null) { |
|
263 | 263 | return []; |
264 | - } elseif ( $ids === [] ) { |
|
264 | + } elseif ($ids === []) { |
|
265 | 265 | $this->errorReporter->dieError( |
266 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
266 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
267 | 267 | } |
268 | 268 | |
269 | - foreach ( $ids as $id ) { |
|
270 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
269 | + foreach ($ids as $id) { |
|
270 | + if (!$this->statementGuidValidator->validate($id)) { |
|
271 | 271 | $this->errorReporter->dieError( |
272 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
272 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
276 | 276 | return $ids; |
277 | 277 | } |
278 | 278 | |
279 | - private function validateParameters( array $params ) { |
|
280 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
281 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
279 | + private function validateParameters(array $params) { |
|
280 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
281 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
282 | 282 | ) { |
283 | 283 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
284 | 284 | $this->errorReporter->dieError( |
285 | 285 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
286 | 286 | } |
287 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
287 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
288 | 288 | $paramId = self::PARAM_ID; |
289 | 289 | $paramClaimId = self::PARAM_CLAIM_ID; |
290 | 290 | $this->errorReporter->dieError( |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | * @param array $parameters |
79 | 79 | * @throws ConstraintParameterException |
80 | 80 | */ |
81 | - public function checkError( array $parameters ) { |
|
82 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
81 | + public function checkError(array $parameters) { |
|
82 | + if (array_key_exists('@error', $parameters)) { |
|
83 | 83 | $error = $parameters['@error']; |
84 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
84 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
85 | 85 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
86 | 86 | } else { |
87 | 87 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
88 | 88 | } |
89 | - throw new ConstraintParameterException( wfMessage( $msg )->escaped() ); |
|
89 | + throw new ConstraintParameterException(wfMessage($msg)->escaped()); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | * @param string $parameterId |
97 | 97 | * @throws ConstraintParameterException |
98 | 98 | */ |
99 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
100 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
99 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
100 | + if (count($parameters[$parameterId]) !== 1) { |
|
101 | 101 | throw new ConstraintParameterException( |
102 | - wfMessage( 'wbqc-violation-message-parameter-single' ) |
|
103 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
102 | + wfMessage('wbqc-violation-message-parameter-single') |
|
103 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
104 | 104 | ->escaped() |
105 | 105 | ); |
106 | 106 | } |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | * @return void |
114 | 114 | * @throws ConstraintParameterException |
115 | 115 | */ |
116 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
117 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
116 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
117 | + if (!($snak instanceof PropertyValueSnak)) { |
|
118 | 118 | throw new ConstraintParameterException( |
119 | - wfMessage( 'wbqc-violation-message-parameter-value' ) |
|
120 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
119 | + wfMessage('wbqc-violation-message-parameter-value') |
|
120 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
121 | 121 | ->escaped() |
122 | 122 | ); |
123 | 123 | } |
@@ -130,18 +130,18 @@ discard block |
||
130 | 130 | * @throws ConstraintParameterException |
131 | 131 | * @return EntityId |
132 | 132 | */ |
133 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
134 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
135 | - $this->requireValueParameter( $snak, $parameterId ); |
|
133 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
134 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
135 | + $this->requireValueParameter($snak, $parameterId); |
|
136 | 136 | $value = $snak->getDataValue(); |
137 | - if ( $value instanceof EntityIdValue ) { |
|
137 | + if ($value instanceof EntityIdValue) { |
|
138 | 138 | return $value->getEntityId(); |
139 | 139 | } else { |
140 | 140 | throw new ConstraintParameterException( |
141 | - wfMessage( 'wbqc-violation-message-parameter-entity' ) |
|
141 | + wfMessage('wbqc-violation-message-parameter-entity') |
|
142 | 142 | ->rawParams( |
143 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
144 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
143 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
144 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
145 | 145 | ) |
146 | 146 | ->escaped() |
147 | 147 | ); |
@@ -154,21 +154,21 @@ discard block |
||
154 | 154 | * @throws ConstraintParameterException if the parameter is invalid or missing |
155 | 155 | * @return string[] class entity ID serializations |
156 | 156 | */ |
157 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
158 | - $this->checkError( $constraintParameters ); |
|
159 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
160 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
157 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
158 | + $this->checkError($constraintParameters); |
|
159 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
160 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
161 | 161 | throw new ConstraintParameterException( |
162 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
163 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
164 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $classId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
162 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
163 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
164 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($classId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
165 | 165 | ->escaped() |
166 | 166 | ); |
167 | 167 | } |
168 | 168 | |
169 | 169 | $classes = []; |
170 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
171 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
170 | + foreach ($constraintParameters[$classId] as $class) { |
|
171 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
172 | 172 | } |
173 | 173 | return $classes; |
174 | 174 | } |
@@ -179,24 +179,24 @@ discard block |
||
179 | 179 | * @throws ConstraintParameterException if the parameter is invalid or missing |
180 | 180 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
181 | 181 | */ |
182 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
183 | - $this->checkError( $constraintParameters ); |
|
184 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
185 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
182 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
183 | + $this->checkError($constraintParameters); |
|
184 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
185 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
186 | 186 | throw new ConstraintParameterException( |
187 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
188 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
189 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
187 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
188 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
189 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
190 | 190 | ->escaped() |
191 | 191 | ); |
192 | 192 | } |
193 | 193 | |
194 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
195 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
196 | - $instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ); |
|
197 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ); |
|
198 | - $instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ); |
|
199 | - switch ( $relationEntityId ) { |
|
194 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
195 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
196 | + $instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId'); |
|
197 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId'); |
|
198 | + $instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId'); |
|
199 | + switch ($relationEntityId) { |
|
200 | 200 | case $instanceId: |
201 | 201 | return 'instance'; |
202 | 202 | case $subclassId: |
@@ -205,13 +205,13 @@ discard block |
||
205 | 205 | return 'instanceOrSubclass'; |
206 | 206 | default: |
207 | 207 | throw new ConstraintParameterException( |
208 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
209 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
210 | - ->numParams( 3 ) |
|
211 | - ->rawParams( $this->constraintParameterRenderer->formatItemIdList( |
|
212 | - [ $instanceId, $subclassId, $instanceOrSubclassId ], |
|
208 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
209 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
210 | + ->numParams(3) |
|
211 | + ->rawParams($this->constraintParameterRenderer->formatItemIdList( |
|
212 | + [$instanceId, $subclassId, $instanceOrSubclassId], |
|
213 | 213 | Role::CONSTRAINT_PARAMETER_VALUE |
214 | - ) ) |
|
214 | + )) |
|
215 | 215 | ->escaped() |
216 | 216 | ); |
217 | 217 | } |
@@ -224,21 +224,21 @@ discard block |
||
224 | 224 | * @throws ConstraintParameterException |
225 | 225 | * @return PropertyId |
226 | 226 | */ |
227 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
228 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
229 | - $this->requireValueParameter( $snak, $parameterId ); |
|
227 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
228 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
229 | + $this->requireValueParameter($snak, $parameterId); |
|
230 | 230 | $value = $snak->getDataValue(); |
231 | - if ( $value instanceof EntityIdValue ) { |
|
231 | + if ($value instanceof EntityIdValue) { |
|
232 | 232 | $id = $value->getEntityId(); |
233 | - if ( $id instanceof PropertyId ) { |
|
233 | + if ($id instanceof PropertyId) { |
|
234 | 234 | return $id; |
235 | 235 | } |
236 | 236 | } |
237 | 237 | throw new ConstraintParameterException( |
238 | - wfMessage( 'wbqc-violation-message-parameter-property' ) |
|
238 | + wfMessage('wbqc-violation-message-parameter-property') |
|
239 | 239 | ->rawParams( |
240 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
241 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
240 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
241 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
242 | 242 | ) |
243 | 243 | ->escaped() |
244 | 244 | ); |
@@ -251,34 +251,34 @@ discard block |
||
251 | 251 | * @throws ConstraintParameterException if the parameter is invalid or missing |
252 | 252 | * @return PropertyId |
253 | 253 | */ |
254 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
255 | - $this->checkError( $constraintParameters ); |
|
256 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
257 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
254 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
255 | + $this->checkError($constraintParameters); |
|
256 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
257 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
258 | 258 | throw new ConstraintParameterException( |
259 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
260 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
261 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
259 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
260 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
261 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
262 | 262 | ->escaped() |
263 | 263 | ); |
264 | 264 | } |
265 | 265 | |
266 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
267 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
266 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
267 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
268 | 268 | } |
269 | 269 | |
270 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
270 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
271 | 271 | $dataValue = $snak->getDataValue(); |
272 | - if ( $dataValue instanceof EntityIdValue && |
|
272 | + if ($dataValue instanceof EntityIdValue && |
|
273 | 273 | $dataValue->getEntityId() instanceof ItemId |
274 | 274 | ) { |
275 | - return ItemIdSnakValue::fromItemId( $dataValue->getEntityId() ); |
|
275 | + return ItemIdSnakValue::fromItemId($dataValue->getEntityId()); |
|
276 | 276 | } else { |
277 | 277 | throw new ConstraintParameterException( |
278 | - wfMessage( 'wbqc-violation-message-parameter-item' ) |
|
278 | + wfMessage('wbqc-violation-message-parameter-item') |
|
279 | 279 | ->rawParams( |
280 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
281 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
280 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
281 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
282 | 282 | ) |
283 | 283 | ->escaped() |
284 | 284 | ); |
@@ -292,15 +292,15 @@ discard block |
||
292 | 292 | * @throws ConstraintParameterException if the parameter is invalid or missing |
293 | 293 | * @return ItemIdSnakValue[] array of values |
294 | 294 | */ |
295 | - public function parseItemsParameter( array $constraintParameters, $constraintTypeItemId, $required ) { |
|
296 | - $this->checkError( $constraintParameters ); |
|
297 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
298 | - if ( !array_key_exists( $qualifierId, $constraintParameters ) ) { |
|
299 | - if ( $required ) { |
|
295 | + public function parseItemsParameter(array $constraintParameters, $constraintTypeItemId, $required) { |
|
296 | + $this->checkError($constraintParameters); |
|
297 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
298 | + if (!array_key_exists($qualifierId, $constraintParameters)) { |
|
299 | + if ($required) { |
|
300 | 300 | throw new ConstraintParameterException( |
301 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
302 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
303 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
301 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
302 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
303 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
304 | 304 | ->escaped() |
305 | 305 | ); |
306 | 306 | } else { |
@@ -309,11 +309,11 @@ discard block |
||
309 | 309 | } |
310 | 310 | |
311 | 311 | $values = []; |
312 | - foreach ( $constraintParameters[$qualifierId] as $parameter ) { |
|
313 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
314 | - switch ( true ) { |
|
312 | + foreach ($constraintParameters[$qualifierId] as $parameter) { |
|
313 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
314 | + switch (true) { |
|
315 | 315 | case $snak instanceof PropertyValueSnak: |
316 | - $values[] = $this->parseItemIdParameter( $snak, $qualifierId ); |
|
316 | + $values[] = $this->parseItemIdParameter($snak, $qualifierId); |
|
317 | 317 | break; |
318 | 318 | case $snak instanceof PropertySomeValueSnak: |
319 | 319 | $values[] = ItemIdSnakValue::someValue(); |
@@ -332,28 +332,28 @@ discard block |
||
332 | 332 | * @throws ConstraintParameterException if the parameter is invalid or missing |
333 | 333 | * @return PropertyId[] |
334 | 334 | */ |
335 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
336 | - $this->checkError( $constraintParameters ); |
|
337 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
338 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
335 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
336 | + $this->checkError($constraintParameters); |
|
337 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
338 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
339 | 339 | throw new ConstraintParameterException( |
340 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
341 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
342 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
340 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
341 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
342 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
343 | 343 | ->escaped() |
344 | 344 | ); |
345 | 345 | } |
346 | 346 | |
347 | 347 | $parameters = $constraintParameters[$propertyId]; |
348 | - if ( count( $parameters ) === 1 && |
|
349 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
348 | + if (count($parameters) === 1 && |
|
349 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
350 | 350 | ) { |
351 | 351 | return []; |
352 | 352 | } |
353 | 353 | |
354 | 354 | $properties = []; |
355 | - foreach ( $parameters as $parameter ) { |
|
356 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
355 | + foreach ($parameters as $parameter) { |
|
356 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
357 | 357 | } |
358 | 358 | return $properties; |
359 | 359 | } |
@@ -364,16 +364,16 @@ discard block |
||
364 | 364 | * @throws ConstraintParameterException |
365 | 365 | * @return DataValue|null |
366 | 366 | */ |
367 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
368 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
369 | - if ( $snak instanceof PropertyValueSnak ) { |
|
367 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
368 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
369 | + if ($snak instanceof PropertyValueSnak) { |
|
370 | 370 | return $snak->getDataValue(); |
371 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
371 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
372 | 372 | return null; |
373 | 373 | } else { |
374 | 374 | throw new ConstraintParameterException( |
375 | - wfMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) |
|
376 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
375 | + wfMessage('wbqc-violation-message-parameter-value-or-novalue') |
|
376 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
377 | 377 | ->escaped() |
378 | 378 | ); |
379 | 379 | } |
@@ -384,13 +384,13 @@ discard block |
||
384 | 384 | * @param string $parameterId |
385 | 385 | * @return DataValue|null |
386 | 386 | */ |
387 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
387 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
388 | 388 | try { |
389 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
390 | - } catch ( ConstraintParameterException $e ) { |
|
389 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
390 | + } catch (ConstraintParameterException $e) { |
|
391 | 391 | // unknown value means “now” |
392 | - $timeParser = ( new TimeParserFactory() )->getTimeParser(); |
|
393 | - return $timeParser->parse( gmdate( '+Y-m-d\T00:00:00\Z' ) ); |
|
392 | + $timeParser = (new TimeParserFactory())->getTimeParser(); |
|
393 | + return $timeParser->parse(gmdate('+Y-m-d\T00:00:00\Z')); |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
@@ -401,14 +401,14 @@ discard block |
||
401 | 401 | * @param string $unit |
402 | 402 | * @return bool |
403 | 403 | */ |
404 | - private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) { |
|
405 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
406 | - !( $max instanceof UnboundedQuantityValue ) |
|
404 | + private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) { |
|
405 | + if (!($min instanceof UnboundedQuantityValue) || |
|
406 | + !($max instanceof UnboundedQuantityValue) |
|
407 | 407 | ) { |
408 | 408 | return false; |
409 | 409 | } |
410 | 410 | |
411 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
411 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | /** |
@@ -419,9 +419,9 @@ discard block |
||
419 | 419 | * @throws ConstraintParameterException if the parameter is invalid or missing |
420 | 420 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
421 | 421 | */ |
422 | - public function parseRangeParameter( array $constraintParameters, $constraintTypeItemId, $type ) { |
|
423 | - $this->checkError( $constraintParameters ); |
|
424 | - switch ( $type ) { |
|
422 | + public function parseRangeParameter(array $constraintParameters, $constraintTypeItemId, $type) { |
|
423 | + $this->checkError($constraintParameters); |
|
424 | + switch ($type) { |
|
425 | 425 | case 'quantity': |
426 | 426 | $configKey = 'Quantity'; |
427 | 427 | break; |
@@ -430,47 +430,47 @@ discard block |
||
430 | 430 | break; |
431 | 431 | default: |
432 | 432 | throw new ConstraintParameterException( |
433 | - wfMessage( 'wbqc-violation-message-value-needed-of-types-2' ) |
|
433 | + wfMessage('wbqc-violation-message-value-needed-of-types-2') |
|
434 | 434 | ->rawParams( |
435 | - $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ), |
|
436 | - wfMessage( 'datatypes-type-quantity' )->escaped(), |
|
437 | - wfMessage( 'datatypes-type-time' )->escaped() |
|
435 | + $this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM), |
|
436 | + wfMessage('datatypes-type-quantity')->escaped(), |
|
437 | + wfMessage('datatypes-type-time')->escaped() |
|
438 | 438 | ) |
439 | 439 | ->escaped() |
440 | 440 | ); |
441 | 441 | } |
442 | - $minimumId = $this->config->get( 'WBQualityConstraintsMinimum' . $configKey . 'Id' ); |
|
443 | - $maximumId = $this->config->get( 'WBQualityConstraintsMaximum' . $configKey . 'Id' ); |
|
444 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
445 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
442 | + $minimumId = $this->config->get('WBQualityConstraintsMinimum'.$configKey.'Id'); |
|
443 | + $maximumId = $this->config->get('WBQualityConstraintsMaximum'.$configKey.'Id'); |
|
444 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
445 | + !array_key_exists($maximumId, $constraintParameters) |
|
446 | 446 | ) { |
447 | 447 | throw new ConstraintParameterException( |
448 | - wfMessage( 'wbqc-violation-message-range-parameters-needed' ) |
|
448 | + wfMessage('wbqc-violation-message-range-parameters-needed') |
|
449 | 449 | ->rawParams( |
450 | - wfMessage( 'datatypes-type-' . $type )->escaped(), |
|
451 | - $this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
452 | - $this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
450 | + wfMessage('datatypes-type-'.$type)->escaped(), |
|
451 | + $this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
452 | + $this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
453 | 453 | ) |
454 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
454 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
455 | 455 | ->escaped() |
456 | 456 | ); |
457 | 457 | } |
458 | 458 | |
459 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
460 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
459 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
460 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
461 | 461 | $parseFunction = $configKey === 'Date' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
462 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
463 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
462 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
463 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
464 | 464 | |
465 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
466 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
465 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
466 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
467 | 467 | throw new ConstraintParameterException( |
468 | - wfMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
468 | + wfMessage('wbqc-violation-message-range-parameters-one-year') |
|
469 | 469 | ->escaped() |
470 | 470 | ); |
471 | 471 | } |
472 | 472 | |
473 | - return [ $min, $max ]; |
|
473 | + return [$min, $max]; |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
@@ -480,18 +480,18 @@ discard block |
||
480 | 480 | * @throws ConstraintParameterException |
481 | 481 | * @return string |
482 | 482 | */ |
483 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
484 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
485 | - $this->requireValueParameter( $snak, $parameterId ); |
|
483 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
484 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
485 | + $this->requireValueParameter($snak, $parameterId); |
|
486 | 486 | $value = $snak->getDataValue(); |
487 | - if ( $value instanceof StringValue ) { |
|
487 | + if ($value instanceof StringValue) { |
|
488 | 488 | return $value->getValue(); |
489 | 489 | } else { |
490 | 490 | throw new ConstraintParameterException( |
491 | - wfMessage( 'wbqc-violation-message-parameter-string' ) |
|
491 | + wfMessage('wbqc-violation-message-parameter-string') |
|
492 | 492 | ->rawParams( |
493 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
494 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
493 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
494 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
495 | 495 | ) |
496 | 496 | ->escaped() |
497 | 497 | ); |
@@ -504,15 +504,15 @@ discard block |
||
504 | 504 | * @throws ConstraintParameterException if the parameter is invalid or missing |
505 | 505 | * @return string |
506 | 506 | */ |
507 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
508 | - $this->checkError( $constraintParameters ); |
|
509 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
510 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
507 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
508 | + $this->checkError($constraintParameters); |
|
509 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
510 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
511 | 511 | return ''; |
512 | 512 | } |
513 | 513 | |
514 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
515 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
514 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
515 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
@@ -521,20 +521,20 @@ discard block |
||
521 | 521 | * @throws ConstraintParameterException if the parameter is invalid or missing |
522 | 522 | * @return string |
523 | 523 | */ |
524 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
525 | - $this->checkError( $constraintParameters ); |
|
526 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
527 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
524 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
525 | + $this->checkError($constraintParameters); |
|
526 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
527 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
528 | 528 | throw new ConstraintParameterException( |
529 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
530 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
531 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $formatId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
529 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
530 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
531 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($formatId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
532 | 532 | ->escaped() |
533 | 533 | ); |
534 | 534 | } |
535 | 535 | |
536 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
537 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
536 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
537 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | /** |
@@ -542,16 +542,16 @@ discard block |
||
542 | 542 | * @throws ConstraintParameterException if the parameter is invalid |
543 | 543 | * @return EntityId[] |
544 | 544 | */ |
545 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
546 | - $this->checkError( $constraintParameters ); |
|
547 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
548 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
545 | + public function parseExceptionParameter(array $constraintParameters) { |
|
546 | + $this->checkError($constraintParameters); |
|
547 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
548 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
549 | 549 | return []; |
550 | 550 | } |
551 | 551 | |
552 | 552 | return array_map( |
553 | - function( $snakSerialization ) use ( $exceptionId ) { |
|
554 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
553 | + function($snakSerialization) use ($exceptionId) { |
|
554 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
555 | 555 | }, |
556 | 556 | $constraintParameters[$exceptionId] |
557 | 557 | ); |
@@ -562,27 +562,27 @@ discard block |
||
562 | 562 | * @throws ConstraintParameterException if the parameter is invalid |
563 | 563 | * @return string|null 'mandatory' or null |
564 | 564 | */ |
565 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
566 | - $this->checkError( $constraintParameters ); |
|
567 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
568 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
565 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
566 | + $this->checkError($constraintParameters); |
|
567 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
568 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
569 | 569 | return null; |
570 | 570 | } |
571 | 571 | |
572 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
573 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
574 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
575 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
572 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
573 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
574 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
575 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
576 | 576 | $statusId = $snak->getDataValue()->getEntityId()->getSerialization(); |
577 | 577 | |
578 | - if ( $statusId === $mandatoryId ) { |
|
578 | + if ($statusId === $mandatoryId) { |
|
579 | 579 | return 'mandatory'; |
580 | 580 | } else { |
581 | 581 | throw new ConstraintParameterException( |
582 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
583 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
584 | - ->numParams( 1 ) |
|
585 | - ->rawParams( $this->constraintParameterRenderer->formatItemIdList( [ $mandatoryId ], Role::CONSTRAINT_PARAMETER_VALUE ) ) |
|
582 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
583 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
584 | + ->numParams(1) |
|
585 | + ->rawParams($this->constraintParameterRenderer->formatItemIdList([$mandatoryId], Role::CONSTRAINT_PARAMETER_VALUE)) |
|
586 | 586 | ->escaped() |
587 | 587 | ); |
588 | 588 | } |
@@ -595,13 +595,13 @@ discard block |
||
595 | 595 | * @return void |
596 | 596 | * @throws ConstraintParameterException |
597 | 597 | */ |
598 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
599 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
598 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
599 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
600 | 600 | throw new ConstraintParameterException( |
601 | - wfMessage( 'wbqc-violation-message-parameter-monolingualtext' ) |
|
601 | + wfMessage('wbqc-violation-message-parameter-monolingualtext') |
|
602 | 602 | ->rawParams( |
603 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
604 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
603 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
604 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
605 | 605 | ) |
606 | 606 | ->escaped() |
607 | 607 | ); |
@@ -616,26 +616,26 @@ discard block |
||
616 | 616 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
617 | 617 | * @return MultilingualTextValue |
618 | 618 | */ |
619 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
619 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
620 | 620 | $result = []; |
621 | 621 | |
622 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
623 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
624 | - $this->requireValueParameter( $snak, $parameterId ); |
|
622 | + foreach ($snakSerializations as $snakSerialization) { |
|
623 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
624 | + $this->requireValueParameter($snak, $parameterId); |
|
625 | 625 | |
626 | 626 | $value = $snak->getDataValue(); |
627 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
627 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
628 | 628 | /** @var MonolingualTextValue $value */ |
629 | 629 | |
630 | 630 | $code = $value->getLanguageCode(); |
631 | - if ( array_key_exists( $code, $result ) ) { |
|
631 | + if (array_key_exists($code, $result)) { |
|
632 | 632 | throw new ConstraintParameterException( |
633 | - wfMessage( 'wbqc-violation-message-parameter-single-per-language' ) |
|
633 | + wfMessage('wbqc-violation-message-parameter-single-per-language') |
|
634 | 634 | ->rawParams( |
635 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
635 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
636 | 636 | ) |
637 | 637 | ->plaintextParams( |
638 | - Language::fetchLanguageName( $code ), |
|
638 | + Language::fetchLanguageName($code), |
|
639 | 639 | $code |
640 | 640 | ) |
641 | 641 | ->escaped() |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | $result[$code] = $value; |
646 | 646 | } |
647 | 647 | |
648 | - return new MultilingualTextValue( $result ); |
|
648 | + return new MultilingualTextValue($result); |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | /** |
@@ -653,11 +653,11 @@ discard block |
||
653 | 653 | * @throws ConstraintParameterException if the parameter is invalid |
654 | 654 | * @return MultilingualTextValue |
655 | 655 | */ |
656 | - public function parseSyntaxClarificationParameter( array $constraintParameters ) { |
|
657 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
656 | + public function parseSyntaxClarificationParameter(array $constraintParameters) { |
|
657 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
658 | 658 | |
659 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
660 | - return new MultilingualTextValue( [] ); |
|
659 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
660 | + return new MultilingualTextValue([]); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -676,20 +676,20 @@ discard block |
||
676 | 676 | * @throws ConstraintParameterException if the parameter is invalid |
677 | 677 | * @return string[]|null Context::TYPE_* constants |
678 | 678 | */ |
679 | - public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) { |
|
680 | - $constraintScopeId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
681 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ); |
|
682 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ); |
|
683 | - $referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ); |
|
679 | + public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) { |
|
680 | + $constraintScopeId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
681 | + $mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId'); |
|
682 | + $qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId'); |
|
683 | + $referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId'); |
|
684 | 684 | |
685 | - if ( !array_key_exists( $constraintScopeId, $constraintParameters ) ) { |
|
685 | + if (!array_key_exists($constraintScopeId, $constraintParameters)) { |
|
686 | 686 | return null; |
687 | 687 | } |
688 | 688 | |
689 | 689 | $contextTypes = []; |
690 | - foreach ( $constraintParameters[$constraintScopeId] as $snakSerialization ) { |
|
691 | - $scopeEntityId = $this->parseEntityIdParameter( $snakSerialization, $constraintScopeId ); |
|
692 | - switch ( $scopeEntityId->getSerialization() ) { |
|
690 | + foreach ($constraintParameters[$constraintScopeId] as $snakSerialization) { |
|
691 | + $scopeEntityId = $this->parseEntityIdParameter($snakSerialization, $constraintScopeId); |
|
692 | + switch ($scopeEntityId->getSerialization()) { |
|
693 | 693 | case $mainSnakId: |
694 | 694 | $contextTypes[] = Context::TYPE_STATEMENT; |
695 | 695 | break; |
@@ -701,14 +701,14 @@ discard block |
||
701 | 701 | break; |
702 | 702 | default: |
703 | 703 | throw new ConstraintParameterException( |
704 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
704 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
705 | 705 | ->rawParams( |
706 | 706 | $this->constraintParameterRenderer->formatPropertyId( |
707 | 707 | $constraintScopeId, |
708 | 708 | Role::CONSTRAINT_PARAMETER_PROPERTY |
709 | 709 | ) |
710 | 710 | ) |
711 | - ->numParams( 3 ) |
|
711 | + ->numParams(3) |
|
712 | 712 | ->rawParams( |
713 | 713 | $this->constraintParameterRenderer->formatItemIdList( |
714 | 714 | [ |
@@ -724,12 +724,12 @@ discard block |
||
724 | 724 | } |
725 | 725 | } |
726 | 726 | |
727 | - if ( $validScopes !== null ) { |
|
728 | - $invalidScopes = array_diff( $contextTypes, $validScopes ); |
|
729 | - if ( $invalidScopes !== [] ) { |
|
730 | - $invalidScope = array_pop( $invalidScopes ); |
|
727 | + if ($validScopes !== null) { |
|
728 | + $invalidScopes = array_diff($contextTypes, $validScopes); |
|
729 | + if ($invalidScopes !== []) { |
|
730 | + $invalidScope = array_pop($invalidScopes); |
|
731 | 731 | throw new ConstraintParameterException( |
732 | - wfMessage( 'wbqc-violation-message-invalid-scope' ) |
|
732 | + wfMessage('wbqc-violation-message-invalid-scope') |
|
733 | 733 | ->rawParams( |
734 | 734 | $this->constraintParameterRenderer->formatConstraintScope( |
735 | 735 | $invalidScope, |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | Role::CONSTRAINT_TYPE_ITEM |
741 | 741 | ) |
742 | 742 | ) |
743 | - ->numParams( count( $validScopes ) ) |
|
743 | + ->numParams(count($validScopes)) |
|
744 | 744 | ->rawParams( |
745 | 745 | $this->constraintParameterRenderer->formatConstraintScopeList( |
746 | 746 | $validScopes, |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | * @throws ConstraintParameterException |
94 | 94 | * @return CheckResult |
95 | 95 | */ |
96 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
96 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
97 | 97 | $parameters = []; |
98 | 98 | $constraintParameters = $constraint->getConstraintParameters(); |
99 | 99 | |
100 | - $format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
101 | - $parameters['pattern'] = [ $format ]; |
|
100 | + $format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
101 | + $parameters['pattern'] = [$format]; |
|
102 | 102 | |
103 | 103 | $syntaxClarifications = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
104 | 104 | $constraintParameters |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | |
107 | 107 | $snak = $context->getSnak(); |
108 | 108 | |
109 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
109 | + if (!$snak instanceof PropertyValueSnak) { |
|
110 | 110 | // nothing to check |
111 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
111 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | $dataValue = $snak->getDataValue(); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * error handling: |
118 | 118 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
119 | 119 | */ |
120 | - switch ( $dataValue->getType() ) { |
|
120 | + switch ($dataValue->getType()) { |
|
121 | 121 | case 'string': |
122 | 122 | $text = $dataValue->getValue(); |
123 | 123 | break; |
@@ -126,46 +126,46 @@ discard block |
||
126 | 126 | $text = $dataValue->getText(); |
127 | 127 | break; |
128 | 128 | default: |
129 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) ) |
|
130 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
131 | - ->withDataValueType( 'string' ) |
|
132 | - ->withDataValueType( 'monolingualtext' ); |
|
133 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
129 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2')) |
|
130 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
131 | + ->withDataValueType('string') |
|
132 | + ->withDataValueType('monolingualtext'); |
|
133 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
134 | 134 | } |
135 | 135 | |
136 | - if ( $this->sparqlHelper !== null && $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
137 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
136 | + if ($this->sparqlHelper !== null && $this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
137 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
138 | 138 | $message = null; |
139 | 139 | $status = CheckResult::STATUS_COMPLIANCE; |
140 | 140 | } else { |
141 | - $message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) ) |
|
142 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
143 | - ->withDataValue( new StringValue( $text ), Role::OBJECT ) |
|
144 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
145 | - ->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE ); |
|
141 | + $message = (new ViolationMessage('wbqc-violation-message-format-clarification')) |
|
142 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
143 | + ->withDataValue(new StringValue($text), Role::OBJECT) |
|
144 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
145 | + ->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE); |
|
146 | 146 | $status = CheckResult::STATUS_VIOLATION; |
147 | 147 | } |
148 | 148 | } else { |
149 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
150 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
149 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
150 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
151 | 151 | $status = CheckResult::STATUS_TODO; |
152 | 152 | } |
153 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
153 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
154 | 154 | } |
155 | 155 | |
156 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
156 | + public function checkConstraintParameters(Constraint $constraint) { |
|
157 | 157 | $constraintParameters = $constraint->getConstraintParameters(); |
158 | 158 | $exceptions = []; |
159 | 159 | try { |
160 | - $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
161 | - } catch ( ConstraintParameterException $e ) { |
|
160 | + $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
161 | + } catch (ConstraintParameterException $e) { |
|
162 | 162 | $exceptions[] = $e; |
163 | 163 | } |
164 | 164 | try { |
165 | 165 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
166 | 166 | $constraintParameters |
167 | 167 | ); |
168 | - } catch ( ConstraintParameterException $e ) { |
|
168 | + } catch (ConstraintParameterException $e) { |
|
169 | 169 | $exceptions[] = $e; |
170 | 170 | } |
171 | 171 | return $exceptions; |
@@ -39,23 +39,23 @@ discard block |
||
39 | 39 | $this->dataValueFactory = $dataValueFactory; |
40 | 40 | } |
41 | 41 | |
42 | - public function unabbreviateViolationMessageKey( $messageKeySuffix ) { |
|
43 | - return ViolationMessage::MESSAGE_KEY_PREFIX . $messageKeySuffix; |
|
42 | + public function unabbreviateViolationMessageKey($messageKeySuffix) { |
|
43 | + return ViolationMessage::MESSAGE_KEY_PREFIX.$messageKeySuffix; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param array $serialization |
48 | 48 | * @return ViolationMessage |
49 | 49 | */ |
50 | - public function deserialize( $serialization ) { |
|
51 | - Assert::parameterType( 'array', $serialization, '$serialization' ); |
|
50 | + public function deserialize($serialization) { |
|
51 | + Assert::parameterType('array', $serialization, '$serialization'); |
|
52 | 52 | |
53 | 53 | $message = new ViolationMessage( |
54 | - $this->unabbreviateViolationMessageKey( $serialization['k'] ) |
|
54 | + $this->unabbreviateViolationMessageKey($serialization['k']) |
|
55 | 55 | ); |
56 | 56 | |
57 | - foreach ( $serialization['a'] as $serializedArgument ) { |
|
58 | - $message = $this->deserializeArgument( $message, $serializedArgument ); |
|
57 | + foreach ($serialization['a'] as $serializedArgument) { |
|
58 | + $message = $this->deserializeArgument($message, $serializedArgument); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | return $message; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param array $serializedArgument [ 't' => ViolationMessage::TYPE_*, 'v' => serialized value, 'r' => $role ] |
67 | 67 | * @return ViolationMessage $message with the deserialized argument appended |
68 | 68 | */ |
69 | - private function deserializeArgument( ViolationMessage $message, array $serializedArgument ) { |
|
69 | + private function deserializeArgument(ViolationMessage $message, array $serializedArgument) { |
|
70 | 70 | $methods = [ |
71 | 71 | ViolationMessage::TYPE_ENTITY_ID => 'deserializeEntityId', |
72 | 72 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'deserializeEntityIdList', |
@@ -85,23 +85,23 @@ discard block |
||
85 | 85 | $serializedValue = $serializedArgument['v']; |
86 | 86 | $role = $serializedArgument['r']; |
87 | 87 | |
88 | - if ( array_key_exists( $type, $methods ) ) { |
|
88 | + if (array_key_exists($type, $methods)) { |
|
89 | 89 | $method = $methods[$type]; |
90 | - $value = $this->$method( $serializedValue ); |
|
90 | + $value = $this->$method($serializedValue); |
|
91 | 91 | } else { |
92 | 92 | throw new InvalidArgumentException( |
93 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
93 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
94 | 94 | ); |
95 | 95 | } |
96 | 96 | |
97 | - return $message->withArgument( $type, $role, $value ); |
|
97 | + return $message->withArgument($type, $role, $value); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @param string $string any value that shall simply be deserialized into itself |
102 | 102 | * @return string that same value, unchanged |
103 | 103 | */ |
104 | - private function deserializeStringByIdentity( $string ) { |
|
104 | + private function deserializeStringByIdentity($string) { |
|
105 | 105 | return $string; |
106 | 106 | } |
107 | 107 | |
@@ -109,30 +109,30 @@ discard block |
||
109 | 109 | * @param string $entityIdSerialization entity ID serialization |
110 | 110 | * @return EntityId |
111 | 111 | */ |
112 | - private function deserializeEntityId( $entityIdSerialization ) { |
|
113 | - return $this->entityIdParser->parse( $entityIdSerialization ); |
|
112 | + private function deserializeEntityId($entityIdSerialization) { |
|
113 | + return $this->entityIdParser->parse($entityIdSerialization); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
117 | 117 | * @param string[] $entityIdSerializations entity ID serializations |
118 | 118 | * @return EntityId[] |
119 | 119 | */ |
120 | - private function deserializeEntityIdList( array $entityIdSerializations ) { |
|
121 | - return array_map( [ $this, 'deserializeEntityId' ], $entityIdSerializations ); |
|
120 | + private function deserializeEntityIdList(array $entityIdSerializations) { |
|
121 | + return array_map([$this, 'deserializeEntityId'], $entityIdSerializations); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
125 | 125 | * @param string $valueSerialization entity ID serialization, '::somevalue' or '::novalue' |
126 | 126 | * @return ItemIdSnakValue |
127 | 127 | */ |
128 | - private function deserializeItemIdSnakValue( $valueSerialization ) { |
|
129 | - switch ( $valueSerialization ) { |
|
128 | + private function deserializeItemIdSnakValue($valueSerialization) { |
|
129 | + switch ($valueSerialization) { |
|
130 | 130 | case '::somevalue': |
131 | 131 | return ItemIdSnakValue::someValue(); |
132 | 132 | case '::novalue': |
133 | 133 | return ItemIdSnakValue::noValue(); |
134 | 134 | default: |
135 | - return ItemIdSnakValue::fromItemId( $this->deserializeEntityId( $valueSerialization ) ); |
|
135 | + return ItemIdSnakValue::fromItemId($this->deserializeEntityId($valueSerialization)); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -140,24 +140,24 @@ discard block |
||
140 | 140 | * @param string[] $valueSerializations entity ID serializations, '::somevalue's or '::novalue's |
141 | 141 | * @return ItemIdSnakValue[] |
142 | 142 | */ |
143 | - private function deserializeItemIdSnakValueList( $valueSerializations ) { |
|
144 | - return array_map( [ $this, 'deserializeItemIdSnakValue' ], $valueSerializations ); |
|
143 | + private function deserializeItemIdSnakValueList($valueSerializations) { |
|
144 | + return array_map([$this, 'deserializeItemIdSnakValue'], $valueSerializations); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
148 | 148 | * @param array $dataValueSerialization the data value in array form |
149 | 149 | * @return DataValue |
150 | 150 | */ |
151 | - private function deserializeDataValue( array $dataValueSerialization ) { |
|
152 | - return $this->dataValueFactory->newFromArray( $dataValueSerialization ); |
|
151 | + private function deserializeDataValue(array $dataValueSerialization) { |
|
152 | + return $this->dataValueFactory->newFromArray($dataValueSerialization); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
156 | 156 | * @param string $scopeAbbreviation |
157 | 157 | * @return string one of the Context::TYPE_* constants |
158 | 158 | */ |
159 | - private function deserializeConstraintScope( $scopeAbbreviation ) { |
|
160 | - switch ( $scopeAbbreviation ) { |
|
159 | + private function deserializeConstraintScope($scopeAbbreviation) { |
|
160 | + switch ($scopeAbbreviation) { |
|
161 | 161 | case 's': |
162 | 162 | return Context::TYPE_STATEMENT; |
163 | 163 | case 'q': |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | default: |
168 | 168 | // @codeCoverageIgnoreStart |
169 | 169 | throw new LogicException( |
170 | - 'Unknown constraint scope abbreviation ' . $scopeAbbreviation |
|
170 | + 'Unknown constraint scope abbreviation '.$scopeAbbreviation |
|
171 | 171 | ); |
172 | 172 | // @codeCoverageIgnoreEnd |
173 | 173 | } |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | * @param string[] $scopeAbbreviations |
178 | 178 | * @return string[] Context::TYPE_* constants |
179 | 179 | */ |
180 | - private function deserializeConstraintScopeList( array $scopeAbbreviations ) { |
|
181 | - return array_map( [ $this, 'deserializeConstraintScope' ], $scopeAbbreviations ); |
|
180 | + private function deserializeConstraintScopeList(array $scopeAbbreviations) { |
|
181 | + return array_map([$this, 'deserializeConstraintScope'], $scopeAbbreviations); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | 185 | * @param mixed $textSerialization {@see MultilingualTextValue::getArrayValue} |
186 | 186 | * @return MultilingualTextValue |
187 | 187 | */ |
188 | - private function deserializeMultilingualText( $textSerialization ) { |
|
189 | - return MultilingualTextValue::newFromArray( $textSerialization ); |
|
188 | + private function deserializeMultilingualText($textSerialization) { |
|
189 | + return MultilingualTextValue::newFromArray($textSerialization); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | } |
@@ -19,26 +19,26 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class ViolationMessageSerializer implements Serializer { |
21 | 21 | |
22 | - private function abbreviateViolationMessageKey( $fullMessageKey ) { |
|
23 | - return substr( $fullMessageKey, strlen( ViolationMessage::MESSAGE_KEY_PREFIX ) ); |
|
22 | + private function abbreviateViolationMessageKey($fullMessageKey) { |
|
23 | + return substr($fullMessageKey, strlen(ViolationMessage::MESSAGE_KEY_PREFIX)); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @param ViolationMessage $object |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - public function serialize( $object ) { |
|
30 | + public function serialize($object) { |
|
31 | 31 | /** @var ViolationMessage $object */ |
32 | - Assert::parameterType( ViolationMessage::class, $object, '$object' ); |
|
32 | + Assert::parameterType(ViolationMessage::class, $object, '$object'); |
|
33 | 33 | |
34 | 34 | $arguments = $object->getArguments(); |
35 | 35 | $serializedArguments = []; |
36 | - foreach ( $arguments as $argument ) { |
|
37 | - $serializedArguments[] = $this->serializeArgument( $argument ); |
|
36 | + foreach ($arguments as $argument) { |
|
37 | + $serializedArguments[] = $this->serializeArgument($argument); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | return [ |
41 | - 'k' => $this->abbreviateViolationMessageKey( $object->getMessageKey() ), |
|
41 | + 'k' => $this->abbreviateViolationMessageKey($object->getMessageKey()), |
|
42 | 42 | 'a' => $serializedArguments, |
43 | 43 | ]; |
44 | 44 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param array $argument element of ViolationMessage::getArguments() |
48 | 48 | * @return array [ 't' => ViolationMessage::TYPE_*, 'v' => serialized value, 'r' => $role ] |
49 | 49 | */ |
50 | - private function serializeArgument( array $argument ) { |
|
50 | + private function serializeArgument(array $argument) { |
|
51 | 51 | $methods = [ |
52 | 52 | ViolationMessage::TYPE_ENTITY_ID => 'serializeEntityId', |
53 | 53 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'serializeEntityIdList', |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | $value = $argument['value']; |
67 | 67 | $role = $argument['role']; |
68 | 68 | |
69 | - if ( array_key_exists( $type, $methods ) ) { |
|
69 | + if (array_key_exists($type, $methods)) { |
|
70 | 70 | $method = $methods[$type]; |
71 | - $serializedValue = $this->$method( $value ); |
|
71 | + $serializedValue = $this->$method($value); |
|
72 | 72 | } else { |
73 | 73 | throw new InvalidArgumentException( |
74 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
74 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
75 | 75 | ); |
76 | 76 | } |
77 | 77 | |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | * @param string $string any value that shall simply be serialized to itself |
89 | 89 | * @return string that same value, unchanged |
90 | 90 | */ |
91 | - private function serializeStringByIdentity( $string ) { |
|
92 | - Assert::parameterType( 'string', $string, '$string' ); |
|
91 | + private function serializeStringByIdentity($string) { |
|
92 | + Assert::parameterType('string', $string, '$string'); |
|
93 | 93 | return $string; |
94 | 94 | } |
95 | 95 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @param EntityId $entityId |
98 | 98 | * @return string entity ID serialization |
99 | 99 | */ |
100 | - private function serializeEntityId( EntityId $entityId ) { |
|
100 | + private function serializeEntityId(EntityId $entityId) { |
|
101 | 101 | return $entityId->getSerialization(); |
102 | 102 | } |
103 | 103 | |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * @param EntityId[] $entityIdList |
106 | 106 | * @return string[] entity ID serializations |
107 | 107 | */ |
108 | - private function serializeEntityIdList( array $entityIdList ) { |
|
109 | - return array_map( [ $this, 'serializeEntityId' ], $entityIdList ); |
|
108 | + private function serializeEntityIdList(array $entityIdList) { |
|
109 | + return array_map([$this, 'serializeEntityId'], $entityIdList); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | * @return string entity ID serialization, '::somevalue', or '::novalue' |
115 | 115 | * (according to EntityId::PATTERN, entity ID serializations can never begin with two colons) |
116 | 116 | */ |
117 | - private function serializeItemIdSnakValue( ItemIdSnakValue $value ) { |
|
118 | - switch ( true ) { |
|
117 | + private function serializeItemIdSnakValue(ItemIdSnakValue $value) { |
|
118 | + switch (true) { |
|
119 | 119 | case $value->isValue(): |
120 | - return $this->serializeEntityId( $value->getItemId() ); |
|
120 | + return $this->serializeEntityId($value->getItemId()); |
|
121 | 121 | case $value->isSomeValue(): |
122 | 122 | return '::somevalue'; |
123 | 123 | case $value->isNoValue(): |
@@ -135,15 +135,15 @@ discard block |
||
135 | 135 | * @param ItemIdSnakValue[] $valueList |
136 | 136 | * @return string[] array of entity ID serializations, '::somevalue's or '::novalue's |
137 | 137 | */ |
138 | - private function serializeItemIdSnakValueList( array $valueList ) { |
|
139 | - return array_map( [ $this, 'serializeItemIdSnakValue' ], $valueList ); |
|
138 | + private function serializeItemIdSnakValueList(array $valueList) { |
|
139 | + return array_map([$this, 'serializeItemIdSnakValue'], $valueList); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | 143 | * @param DataValue $dataValue |
144 | 144 | * @return array the data value in array form |
145 | 145 | */ |
146 | - private function serializeDataValue( DataValue $dataValue ) { |
|
146 | + private function serializeDataValue(DataValue $dataValue) { |
|
147 | 147 | return $dataValue->toArray(); |
148 | 148 | } |
149 | 149 | |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | * @param string $scope one of the Context::TYPE_* constants |
152 | 152 | * @return string the abbreviated scope |
153 | 153 | */ |
154 | - private function serializeConstraintScope( $scope ) { |
|
155 | - switch ( $scope ) { |
|
154 | + private function serializeConstraintScope($scope) { |
|
155 | + switch ($scope) { |
|
156 | 156 | case Context::TYPE_STATEMENT: |
157 | 157 | return 's'; |
158 | 158 | case Context::TYPE_QUALIFIER: |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | default: |
163 | 163 | // @codeCoverageIgnoreStart |
164 | 164 | throw new LogicException( |
165 | - 'Unknown constraint scope ' . $scope |
|
165 | + 'Unknown constraint scope '.$scope |
|
166 | 166 | ); |
167 | 167 | // @codeCoverageIgnoreEnd |
168 | 168 | } |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | * @param string[] $scopeList Context::TYPE_* constants |
173 | 173 | * @return string[] abbreviated scopes |
174 | 174 | */ |
175 | - private function serializeConstraintScopeList( array $scopeList ) { |
|
176 | - return array_map( [ $this, 'serializeConstraintScope' ], $scopeList ); |
|
175 | + private function serializeConstraintScopeList(array $scopeList) { |
|
176 | + return array_map([$this, 'serializeConstraintScope'], $scopeList); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * @param MultilingualTextValue $text |
181 | 181 | * @return mixed {@see MultilingualTextValue::getArrayValue} |
182 | 182 | */ |
183 | - private function serializeMultilingualText( MultilingualTextValue $text ) { |
|
183 | + private function serializeMultilingualText(MultilingualTextValue $text) { |
|
184 | 184 | return $text->getArrayValue(); |
185 | 185 | } |
186 | 186 |