Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 9 | class Channel extends ClientObject implements ChannelInterface |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * {@inheritDoc} |
||
| 13 | */ |
||
| 14 | 3 | public function getId() |
|
| 15 | { |
||
| 16 | 3 | return $this->data['id']; |
|
| 17 | } |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Gets the channel name. |
||
| 21 | * |
||
| 22 | * @return string The name of the channel. |
||
| 23 | */ |
||
| 24 | 1 | public function getName() |
|
| 25 | { |
||
| 26 | 1 | return $this->data['name']; |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Gets the channel's purpose text. |
||
| 31 | * |
||
| 32 | * @return string The channel's purpose text. |
||
| 33 | */ |
||
| 34 | 1 | public function getPurpose() |
|
| 38 | |||
| 39 | /** |
||
| 40 | * Gets the channel topic text. |
||
| 41 | * |
||
| 42 | * @return string The channel's topic text. |
||
| 43 | */ |
||
| 44 | 1 | public function getTopic() |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Gets an iterator over all users in the channel. |
||
| 51 | * |
||
| 52 | * @return \React\Promise\PromiseInterface A promise for an array of user |
||
| 53 | * objects for each member in the channel. |
||
| 54 | */ |
||
| 55 | public function getMembers() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Gets the time the channel was created. |
||
| 67 | * |
||
| 68 | * @return \DateTime The time the channel was created. |
||
| 69 | */ |
||
| 70 | 1 | public function getTimeCreated() |
|
| 76 | |||
| 77 | /** |
||
| 78 | * Gets the creator of the channel. |
||
| 79 | * |
||
| 80 | * @return \React\Promise\PromiseInterface The user who created the channel. |
||
| 81 | */ |
||
| 82 | 1 | public function getCreator() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Gets the number of message unread by the authenticated user. |
||
| 89 | * |
||
| 90 | * @return int The number of unread messages. |
||
| 91 | */ |
||
| 92 | 1 | public function getUnreadCount() |
|
| 96 | |||
| 97 | /** |
||
| 98 | * Checks if the channel has been archived. |
||
| 99 | * |
||
| 100 | * @return bool True if the channel has been archived, otherwise false. |
||
| 101 | */ |
||
| 102 | 1 | public function isArchived() |
|
| 106 | |||
| 107 | /** |
||
| 108 | * Renames the channel. |
||
| 109 | * |
||
| 110 | * @param string $name The name to set to. |
||
| 111 | * |
||
| 112 | * @return \React\Promise\PromiseInterface |
||
| 113 | */ |
||
| 114 | public function rename($name) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Sets the channel's purpose text. |
||
| 127 | * |
||
| 128 | * @param string $text The new purpose text to set to. |
||
| 129 | * |
||
| 130 | * @return \React\Promise\PromiseInterface |
||
| 131 | */ |
||
| 132 | public function setPurpose($text) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Sets the channel topic text. |
||
| 145 | * |
||
| 146 | * @param string $text The new topic text to set to. |
||
| 147 | * |
||
| 148 | * @return \React\Promise\PromiseInterface |
||
| 149 | */ |
||
| 150 | public function setTopic($text) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Archives the channel. |
||
| 163 | * |
||
| 164 | * @return \React\Promise\PromiseInterface |
||
| 165 | */ |
||
| 166 | View Code Duplication | public function archive() |
|
| 174 | |||
| 175 | /** |
||
| 176 | * Un-archives the channel. |
||
| 177 | * |
||
| 178 | * @return \React\Promise\PromiseInterface |
||
| 179 | */ |
||
| 180 | View Code Duplication | public function unarchive() |
|
| 188 | |||
| 189 | /** |
||
| 190 | * Invites a user to the channel. |
||
| 191 | * |
||
| 192 | * @param User The user to invite. |
||
| 193 | * |
||
| 194 | * @return \React\Promise\PromiseInterface |
||
| 195 | */ |
||
| 196 | View Code Duplication | public function inviteUser(User $user) |
|
| 205 | |||
| 206 | /** |
||
| 207 | * Kicks a user from the channel. |
||
| 208 | * |
||
| 209 | * @param User The user to kick. |
||
| 210 | * |
||
| 211 | * @return \React\Promise\PromiseInterface |
||
| 212 | */ |
||
| 213 | View Code Duplication | public function kickUser(User $user) |
|
| 222 | |||
| 223 | /** |
||
| 224 | * {@inheritDoc} |
||
| 225 | */ |
||
| 226 | View Code Duplication | public function close() |
|
| 234 | } |
||
| 235 |