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 namespace core\src; |
||
10 | class FrontController |
||
11 | { |
||
|
|||
12 | |||
13 | /** |
||
14 | * @var CI |
||
15 | */ |
||
16 | private $ci; |
||
17 | |||
18 | /** |
||
19 | * @var CoreModel |
||
20 | */ |
||
21 | private $frontModel; |
||
22 | |||
23 | /** |
||
24 | * @var Router |
||
25 | */ |
||
26 | private $router; |
||
27 | |||
28 | /** |
||
29 | * FrontController constructor. |
||
30 | * @param CI $ci |
||
31 | * @param CoreModel $frontModel |
||
32 | * @param Router $router |
||
33 | */ |
||
34 | public function __construct(CI $ci, CoreModel $frontModel, Router $router) { |
||
39 | |||
40 | /** |
||
41 | * @param string $url |
||
42 | * @throws PageNotFoundException |
||
43 | */ |
||
44 | public function display($url) { |
||
83 | |||
84 | private function main() { |
||
107 | |||
108 | /** |
||
109 | * @param int $id |
||
110 | */ |
||
111 | private function page($id) { |
||
115 | |||
116 | /** |
||
117 | * @param int $id |
||
118 | */ |
||
119 | private function category($id) { |
||
122 | |||
123 | /** |
||
124 | * @param int $id |
||
125 | */ |
||
126 | private function shopCategory($id) { |
||
129 | |||
130 | /** |
||
131 | * @param int $id |
||
132 | */ |
||
133 | private function product($id) { |
||
142 | |||
143 | /** |
||
144 | * @param string $url |
||
145 | * @throws PageNotFoundException |
||
146 | */ |
||
147 | private function module($url) { |
||
178 | |||
179 | } |