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