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 |
||
21 | class BeerCommand extends AbstractCommand |
||
22 | { |
||
23 | /** |
||
24 | * AbstractCommand constructor. |
||
25 | * |
||
26 | * @param Payload $payload |
||
27 | * @param RealTimeClient $client |
||
28 | * @param array|null $configuration |
||
29 | */ |
||
30 | 8 | View Code Duplication | public function __construct(Payload $payload, RealTimeClient $client, array $configuration = null) |
42 | |||
43 | /** |
||
44 | * stats for all beer counter. |
||
45 | * |
||
46 | * @return string |
||
47 | * |
||
48 | * @throws \Doctrine\DBAL\DBALException |
||
49 | */ |
||
50 | 1 | protected function processAll() : string |
|
54 | |||
55 | /** |
||
56 | * stats for TOP 10. |
||
57 | * |
||
58 | * @return string |
||
59 | * |
||
60 | * @throws \Doctrine\DBAL\DBALException |
||
61 | */ |
||
62 | 1 | protected function processTop10() : string |
|
72 | |||
73 | /** |
||
74 | * stats for beer counter. |
||
75 | * |
||
76 | * @return string |
||
77 | * |
||
78 | * @throws \Doctrine\DBAL\DBALException |
||
79 | */ |
||
80 | 2 | protected function processStats() : string |
|
92 | |||
93 | /** |
||
94 | * give someone a beer. |
||
95 | * |
||
96 | * @return string |
||
97 | * |
||
98 | * @throws \Doctrine\DBAL\DBALException |
||
99 | */ |
||
100 | 3 | protected function processFor() : string |
|
119 | |||
120 | /** |
||
121 | * @param string $username |
||
122 | * @param string $from_user |
||
123 | * |
||
124 | * @return bool |
||
125 | * @throws \Doctrine\DBAL\DBALException |
||
126 | */ |
||
127 | 2 | protected function checkSpendingOfLastBeer(string $username, string $from_user) : bool |
|
142 | |||
143 | /** |
||
144 | * @param $username |
||
145 | * |
||
146 | * @return int |
||
147 | * |
||
148 | * @throws \Doctrine\DBAL\DBALException |
||
149 | */ |
||
150 | 3 | protected function getBeerCountByUsername($username) : int |
|
161 | |||
162 | /** |
||
163 | * @return int |
||
164 | * |
||
165 | * @throws \Doctrine\DBAL\DBALException |
||
166 | */ |
||
167 | 1 | protected function getBeerCountAll() : int |
|
176 | |||
177 | /** |
||
178 | * @return array |
||
179 | * |
||
180 | * @throws \Doctrine\DBAL\DBALException |
||
181 | */ |
||
182 | 1 | protected function getBeerTop10() : array |
|
194 | } |
||
195 |