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 Unsubscribe extends HttpApi |
|
|
|||
26 | { |
||
27 | use Pagination; |
||
28 | |||
29 | /** |
||
30 | * @param string $domain Domain to get unsubscribes for |
||
31 | * @param int $limit optional |
||
32 | * |
||
33 | * @return IndexResponse |
||
34 | */ |
||
35 | public function index($domain, $limit = 100) |
||
48 | |||
49 | /** |
||
50 | * @param string $domain Domain to show unsubscribe for |
||
51 | * @param string $address Unsubscribe address |
||
52 | * |
||
53 | * @return ShowResponse |
||
54 | */ |
||
55 | public function show($domain, $address) |
||
64 | |||
65 | /** |
||
66 | * @param string $domain Domain to create unsubscribe for |
||
67 | * @param string $address Unsubscribe address |
||
68 | * @param array $params optional |
||
69 | * |
||
70 | * @return CreateResponse |
||
71 | */ |
||
72 | public function create($domain, $address, array $params = []) |
||
83 | |||
84 | /** |
||
85 | * @param string $domain Domain to delete unsubscribe for |
||
86 | * @param string $address Unsubscribe address |
||
87 | * |
||
88 | * @return DeleteResponse |
||
89 | */ |
||
90 | public function delete($domain, $address) |
||
99 | |||
100 | /** |
||
101 | * @param string $domain Domain to delete all unsubscribes for |
||
102 | * |
||
103 | * @return DeleteResponse |
||
104 | */ |
||
105 | public function deleteAll($domain) |
||
113 | } |
||
114 |
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.