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 Factory |
||
22 | { |
||
23 | /** |
||
24 | * Create alive request object |
||
25 | * |
||
26 | * @param AliveOptions $options |
||
27 | * |
||
28 | * @throws \RuntimeException |
||
29 | * |
||
30 | * @return RequestInterface |
||
31 | */ |
||
32 | public function createAliveRequest(AliveOptions $options) |
||
50 | |||
51 | /** |
||
52 | * Create byebye request object |
||
53 | * |
||
54 | * @param ByebyeOptions $options |
||
55 | * |
||
56 | * @throws \RuntimeException |
||
57 | * |
||
58 | * @return RequestInterface |
||
59 | */ |
||
60 | View Code Duplication | public function createByebyeRequest(ByebyeOptions $options) |
|
75 | |||
76 | |||
77 | /** |
||
78 | * Create discover request object |
||
79 | * |
||
80 | * @param DiscoverOptions $options |
||
81 | * |
||
82 | * @throws \RuntimeException |
||
83 | * |
||
84 | * @return RequestInterface |
||
85 | */ |
||
86 | public function createDiscoverRequest(DiscoverOptions $options) |
||
97 | |||
98 | /** |
||
99 | * Create update request object |
||
100 | * |
||
101 | * @param UpdateOptions $options |
||
102 | * |
||
103 | * @throws \RuntimeException |
||
104 | * |
||
105 | * @return RequestInterface |
||
106 | */ |
||
107 | View Code Duplication | public function createUpdateRequest(UpdateOptions $options) |
|
123 | } |
||
124 |
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.