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 |
||
13 | View Code Duplication | class ValuelistsStorage extends AbstractStorage |
|
|
|||
14 | { |
||
15 | /** |
||
16 | * Get all valuelists |
||
17 | * |
||
18 | * @return mixed |
||
19 | */ |
||
20 | public function getValuelists() |
||
24 | |||
25 | public function addValuelist($postValues) |
||
33 | |||
34 | /** |
||
35 | * Save changes to a valuelist |
||
36 | * |
||
37 | * @param $slug |
||
38 | * @param $postValues |
||
39 | * |
||
40 | * @throws \Exception |
||
41 | */ |
||
42 | public function saveValuelist($slug, $postValues) |
||
55 | |||
56 | /** |
||
57 | * Get a valuelist by its slug |
||
58 | * |
||
59 | * @param $slug |
||
60 | * |
||
61 | * @return mixed |
||
62 | */ |
||
63 | public function getValuelistBySlug($slug) |
||
74 | |||
75 | /** |
||
76 | * Delete a sitemap item by its slug |
||
77 | * |
||
78 | * @param $slug |
||
79 | * |
||
80 | * @throws \Exception |
||
81 | */ |
||
82 | public function deleteValuelistBySlug($slug) |
||
94 | } |
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.