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 |
||
25 | View Code Duplication | class Tag extends HttpApi |
|
|
|||
26 | { |
||
27 | /** |
||
28 | * Returns a list of tags. |
||
29 | * |
||
30 | * @param string $domain |
||
31 | * @param int $limit |
||
32 | * |
||
33 | * @return IndexResponse|ResponseInterface |
||
34 | */ |
||
35 | 1 | public function index($domain, $limit = 100) |
|
48 | |||
49 | /** |
||
50 | * Returns a single tag. |
||
51 | * |
||
52 | * @param string $domain Name of the domain |
||
53 | * @param string $tag |
||
54 | * |
||
55 | * @return ShowResponse|ResponseInterface |
||
56 | */ |
||
57 | 1 | public function show($domain, $tag) |
|
66 | |||
67 | /** |
||
68 | * Update a tag. |
||
69 | * |
||
70 | * @param string $domain |
||
71 | * @param string $tag |
||
72 | * @param string $description |
||
73 | * |
||
74 | * @return UpdateResponse|ResponseInterface |
||
75 | */ |
||
76 | 1 | public function update($domain, $tag, $description) |
|
90 | |||
91 | /** |
||
92 | * Returns statistics for a single tag. |
||
93 | * |
||
94 | * @param string $domain Name of the domain |
||
95 | * @param string $tag |
||
96 | * @param array $params |
||
97 | * |
||
98 | * @return StatisticsResponse|ResponseInterface |
||
99 | */ |
||
100 | 1 | public function stats($domain, $tag, array $params) |
|
110 | |||
111 | /** |
||
112 | * Removes a tag from the account. |
||
113 | * |
||
114 | * @param string $domain Name of the domain |
||
115 | * @param string $tag |
||
116 | * |
||
117 | * @return DeleteResponse|ResponseInterface |
||
118 | */ |
||
119 | 1 | public function delete($domain, $tag) |
|
128 | } |
||
129 |
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.