@@ -44,84 +44,84 @@ |
||
44 | 44 | $language = null, |
45 | 45 | $format = Message::FORMAT_ESCAPED |
46 | 46 | ) { |
47 | - if ( is_string( $violationMessage ) ) { |
|
47 | + if (is_string($violationMessage)) { |
|
48 | 48 | // TODO remove this once all checkers produce ViolationMessage objects |
49 | 49 | return $violationMessage; |
50 | 50 | } |
51 | - $message = new Message( $violationMessage->getMessageKey(), [], $language ); |
|
52 | - foreach ( $violationMessage->getArguments() as $argument ) { |
|
53 | - $this->renderArgument( $argument, $message ); |
|
51 | + $message = new Message($violationMessage->getMessageKey(), [], $language); |
|
52 | + foreach ($violationMessage->getArguments() as $argument) { |
|
53 | + $this->renderArgument($argument, $message); |
|
54 | 54 | } |
55 | - return $message->toString( $format ); |
|
55 | + return $message->toString($format); |
|
56 | 56 | } |
57 | 57 | |
58 | - private function addRole( $value, $role ) { |
|
59 | - if ( $role === null ) { |
|
58 | + private function addRole($value, $role) { |
|
59 | + if ($role === null) { |
|
60 | 60 | return $value; |
61 | 61 | } |
62 | 62 | |
63 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' . |
|
64 | - $value . |
|
63 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'. |
|
64 | + $value. |
|
65 | 65 | '</span>'; |
66 | 66 | } |
67 | 67 | |
68 | - private function renderArgument( array $argument, Message $message ) { |
|
69 | - switch ( $argument['type'] ) { |
|
68 | + private function renderArgument(array $argument, Message $message) { |
|
69 | + switch ($argument['type']) { |
|
70 | 70 | case ViolationMessage::TYPE_ENTITY_ID: |
71 | - $params = $this->renderEntityId( $argument['value'], $argument['role'] ); |
|
71 | + $params = $this->renderEntityId($argument['value'], $argument['role']); |
|
72 | 72 | break; |
73 | 73 | case ViolationMessage::TYPE_ENTITY_ID_LIST: |
74 | - $params = $this->renderEntityIdList( $argument['value'], $argument['role'] ); |
|
74 | + $params = $this->renderEntityIdList($argument['value'], $argument['role']); |
|
75 | 75 | break; |
76 | 76 | default: |
77 | 77 | throw new InvalidArgumentException( |
78 | - 'Unknown ViolationMessage argument type ' . $argument['type'] . '!' |
|
78 | + 'Unknown ViolationMessage argument type '.$argument['type'].'!' |
|
79 | 79 | ); |
80 | 80 | } |
81 | - $message->params( $params ); |
|
81 | + $message->params($params); |
|
82 | 82 | } |
83 | 83 | |
84 | - private function renderEntityId( EntityId $entityId, $role ) { |
|
85 | - return Message::rawParam( $this->addRole( |
|
86 | - $this->entityIdFormatter->formatEntityId( $entityId ), |
|
84 | + private function renderEntityId(EntityId $entityId, $role) { |
|
85 | + return Message::rawParam($this->addRole( |
|
86 | + $this->entityIdFormatter->formatEntityId($entityId), |
|
87 | 87 | $role |
88 | - ) ); |
|
88 | + )); |
|
89 | 89 | } |
90 | 90 | |
91 | - private function renderEntityIdList( array $entityIdList, $role ) { |
|
92 | - if ( $entityIdList === [] ) { |
|
91 | + private function renderEntityIdList(array $entityIdList, $role) { |
|
92 | + if ($entityIdList === []) { |
|
93 | 93 | return [ |
94 | - Message::numParam( 0 ), |
|
95 | - Message::rawParam( '<ul></ul>' ), |
|
94 | + Message::numParam(0), |
|
95 | + Message::rawParam('<ul></ul>'), |
|
96 | 96 | ]; |
97 | 97 | } |
98 | 98 | |
99 | - if ( count( $entityIdList ) > $this->maxListLength ) { |
|
100 | - $entityIdList = array_slice( $entityIdList, 0, $this->maxListLength ); |
|
99 | + if (count($entityIdList) > $this->maxListLength) { |
|
100 | + $entityIdList = array_slice($entityIdList, 0, $this->maxListLength); |
|
101 | 101 | $truncated = true; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $renderedParams = array_map( |
105 | - [ $this, 'renderEntityId' ], |
|
105 | + [$this, 'renderEntityId'], |
|
106 | 106 | $entityIdList, |
107 | - array_fill( 0, count( $entityIdList ), $role ) |
|
107 | + array_fill(0, count($entityIdList), $role) |
|
108 | 108 | ); |
109 | 109 | $renderedElements = array_map( |
110 | - function ( $param ) { |
|
110 | + function($param) { |
|
111 | 111 | return $param['raw']; |
112 | 112 | }, |
113 | 113 | $renderedParams |
114 | 114 | ); |
115 | - if ( isset( $truncated ) ) { |
|
116 | - $renderedElements[] = wfMessage( 'ellipsis' )->escaped(); |
|
115 | + if (isset($truncated)) { |
|
116 | + $renderedElements[] = wfMessage('ellipsis')->escaped(); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | return array_merge( |
120 | 120 | [ |
121 | - Message::numParam( count( $entityIdList ) ), |
|
121 | + Message::numParam(count($entityIdList)), |
|
122 | 122 | Message::rawParam( |
123 | - '<ul><li>' . |
|
124 | - implode( '</li><li>', $renderedElements ) . |
|
123 | + '<ul><li>'. |
|
124 | + implode('</li><li>', $renderedElements). |
|
125 | 125 | '</li></ul>' |
126 | 126 | ), |
127 | 127 | ], |
@@ -52,17 +52,17 @@ discard block |
||
52 | 52 | public function __construct( |
53 | 53 | $messageKey |
54 | 54 | ) { |
55 | - if ( strpos( $messageKey, self::MESSAGE_KEY_PREFIX ) !== 0 ) { |
|
55 | + if (strpos($messageKey, self::MESSAGE_KEY_PREFIX) !== 0) { |
|
56 | 56 | throw new InvalidArgumentException( |
57 | - 'ViolationMessage key ⧼' . |
|
58 | - $messageKey . |
|
59 | - '⧽ should start with "' . |
|
60 | - self::MESSAGE_KEY_PREFIX . |
|
57 | + 'ViolationMessage key ⧼'. |
|
58 | + $messageKey. |
|
59 | + '⧽ should start with "'. |
|
60 | + self::MESSAGE_KEY_PREFIX. |
|
61 | 61 | '".' |
62 | 62 | ); |
63 | 63 | } |
64 | 64 | |
65 | - $this->messageKeySuffix = substr( $messageKey, strlen( self::MESSAGE_KEY_PREFIX ) ); |
|
65 | + $this->messageKeySuffix = substr($messageKey, strlen(self::MESSAGE_KEY_PREFIX)); |
|
66 | 66 | $this->arguments = []; |
67 | 67 | } |
68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @return string |
72 | 72 | */ |
73 | 73 | public function getMessageKey() { |
74 | - return self::MESSAGE_KEY_PREFIX . $this->messageKeySuffix; |
|
74 | + return self::MESSAGE_KEY_PREFIX.$this->messageKeySuffix; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | * @param mixed $value the value, which should match the $type |
90 | 90 | * @return ViolationMessage |
91 | 91 | */ |
92 | - private function withArgument( $type, $role, $value ) { |
|
92 | + private function withArgument($type, $role, $value) { |
|
93 | 93 | $ret = clone $this; |
94 | - $ret->arguments[] = [ 'type' => $type, 'role' => $role, 'value' => $value ]; |
|
94 | + $ret->arguments[] = ['type' => $type, 'role' => $role, 'value' => $value]; |
|
95 | 95 | return $ret; |
96 | 96 | } |
97 | 97 | |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * @param string|null $role one of the Role::* constants |
104 | 104 | * @return ViolationMessage |
105 | 105 | */ |
106 | - public function withEntityId( EntityId $entityId, $role = null ) { |
|
107 | - return $this->withArgument( self::TYPE_ENTITY_ID, $role, $entityId ); |
|
106 | + public function withEntityId(EntityId $entityId, $role = null) { |
|
107 | + return $this->withArgument(self::TYPE_ENTITY_ID, $role, $entityId); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | * @param string|null $role one of the Role::* constants |
122 | 122 | * @return ViolationMessage |
123 | 123 | */ |
124 | - public function withEntityIdList( array $entityIdList, $role = null ) { |
|
125 | - return $this->withArgument( self::TYPE_ENTITY_ID_LIST, $role, $entityIdList ); |
|
124 | + public function withEntityIdList(array $entityIdList, $role = null) { |
|
125 | + return $this->withArgument(self::TYPE_ENTITY_ID_LIST, $role, $entityIdList); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | } |