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 |
||
11 | class DevelopController implements InjectionAwareInterface |
||
12 | { |
||
13 | use InjectionAwareTrait; |
||
14 | |||
15 | |||
16 | |||
17 | /** |
||
18 | * @var string $namespace A namespace to prepend each template file. |
||
19 | */ |
||
20 | private $namespace = "anax/v1/dev"; |
||
21 | |||
22 | |||
23 | |||
24 | /** |
||
25 | * Render a page showing a menu with links to all dev pages. |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | View Code Duplication | public function index() |
|
36 | |||
37 | |||
38 | |||
39 | /** |
||
40 | * Render a page displaying information on services loaded in $di. |
||
41 | * |
||
42 | * @return void |
||
43 | */ |
||
44 | View Code Duplication | public function di() |
|
51 | |||
52 | |||
53 | |||
54 | /** |
||
55 | * Render a page displaying information on the current request. |
||
56 | * |
||
57 | * @return void |
||
58 | */ |
||
59 | View Code Duplication | public function request() |
|
66 | |||
67 | |||
68 | |||
69 | /** |
||
70 | * Render a page displaying information on routes loaded in framework. |
||
71 | * |
||
72 | * @return void |
||
73 | */ |
||
74 | View Code Duplication | public function route() |
|
81 | |||
82 | |||
83 | |||
84 | /** |
||
85 | * Render a page displaying session data. |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | View Code Duplication | public function session() |
|
96 | |||
97 | |||
98 | |||
99 | /** |
||
100 | * Render a page displaying details on view helpers. |
||
101 | * |
||
102 | * @return void |
||
103 | */ |
||
104 | View Code Duplication | public function view() |
|
111 | } |
||
112 |
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.