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 | trait LiteSpeedTest |
||
22 | { |
||
23 | /** |
||
24 | * @var LiteSpeed |
||
25 | */ |
||
26 | protected $proxyClient; |
||
27 | |||
28 | /** |
||
29 | * @var LiteSpeedProxy |
||
30 | */ |
||
31 | protected $proxy; |
||
32 | |||
33 | protected function setUp() |
||
37 | |||
38 | protected function tearDown() |
||
42 | |||
43 | /** |
||
44 | * Defaults to "/usr/local/lsws/bin/lswsctrl". |
||
45 | * |
||
46 | * @return string |
||
47 | */ |
||
48 | protected function getBinary() |
||
52 | |||
53 | /** |
||
54 | * Defaults to 80. |
||
55 | * |
||
56 | * @return int |
||
57 | */ |
||
58 | protected function getCachingProxyPort() |
||
62 | |||
63 | /** |
||
64 | * Get the hostname where your application can be reached. |
||
65 | * |
||
66 | * @throws \Exception |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | protected function getHostName() |
||
82 | |||
83 | /** |
||
84 | * @return LiteSpeedProxy |
||
85 | */ |
||
86 | protected function getProxy() |
||
99 | |||
100 | /** |
||
101 | * Get proxy client. |
||
102 | * |
||
103 | * @return LiteSpeed |
||
104 | */ |
||
105 | View Code Duplication | protected function getProxyClient() |
|
118 | } |
||
119 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.