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 |
||
7 | class Group extends Channel |
||
8 | { |
||
9 | /** |
||
10 | * Renames the group. |
||
11 | * |
||
12 | * @param string $name The name to set to. |
||
13 | * |
||
14 | * @return \React\Promise\PromiseInterface |
||
15 | */ |
||
16 | public function rename($name) |
||
26 | |||
27 | /** |
||
28 | * Sets the group's purpose text. |
||
29 | * |
||
30 | * @param string $text The new purpose text to set to. |
||
31 | * |
||
32 | * @return \React\Promise\PromiseInterface |
||
33 | */ |
||
34 | public function setPurpose($text) |
||
44 | |||
45 | /** |
||
46 | * Sets the group topic text. |
||
47 | * |
||
48 | * @param string $text The new topic text to set to. |
||
49 | * |
||
50 | * @return \React\Promise\PromiseInterface |
||
51 | */ |
||
52 | public function setTopic($text) |
||
62 | |||
63 | /** |
||
64 | * Archives the group. |
||
65 | * |
||
66 | * @return \React\Promise\PromiseInterface |
||
67 | */ |
||
68 | View Code Duplication | public function archive() |
|
76 | |||
77 | /** |
||
78 | * Un-archives the group. |
||
79 | * |
||
80 | * @return \React\Promise\PromiseInterface |
||
81 | */ |
||
82 | View Code Duplication | public function unarchive() |
|
90 | |||
91 | /** |
||
92 | * Invites a user to the group. |
||
93 | * |
||
94 | * @param User $user The user to invite. |
||
95 | * |
||
96 | * @return \React\Promise\PromiseInterface |
||
97 | */ |
||
98 | View Code Duplication | public function inviteUser(User $user) |
|
107 | |||
108 | /** |
||
109 | * Kicks a user from the group. |
||
110 | * |
||
111 | * @param User $user The user to kick. |
||
112 | * |
||
113 | * @return \React\Promise\PromiseInterface |
||
114 | */ |
||
115 | View Code Duplication | public function kickUser(User $user) |
|
124 | |||
125 | /** |
||
126 | * Opens the group. |
||
127 | * |
||
128 | * @return \React\Promise\PromiseInterface |
||
129 | */ |
||
130 | View Code Duplication | public function open() |
|
138 | |||
139 | /** |
||
140 | * {@inheritDoc} |
||
141 | */ |
||
142 | View Code Duplication | public function close() |
|
150 | } |
||
151 |