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 |
||
14 | trait SideNavHelpers |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * Check menu has sub |
||
19 | * |
||
20 | * @author Alireza Josheghani <[email protected]> |
||
21 | * @since 8 Oct 2016 |
||
22 | * @param $menu |
||
23 | * @return bool |
||
24 | */ |
||
25 | public static function hasSub($menu) |
||
34 | |||
35 | /** |
||
36 | * Print item icon |
||
37 | * |
||
38 | * @author Alireza Josheghani <[email protected]> |
||
39 | * @since 8 Oct 2016 |
||
40 | * @param $value |
||
41 | * @return string |
||
42 | */ |
||
43 | View Code Duplication | public static function itemIcon($value) |
|
54 | |||
55 | /** |
||
56 | * Print item new_tab option |
||
57 | * |
||
58 | * @author Alireza Josheghani <[email protected]> |
||
59 | * @since 8 Oct 2016 |
||
60 | * @param $newTab |
||
61 | * @return null|string |
||
62 | */ |
||
63 | public static function new_tab($newTab) |
||
71 | |||
72 | } |
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.