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