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 UriMatcher implements MatcherInterface |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @var |
||
16 | */ |
||
17 | private $router; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | private $request = []; |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | private $resolver = ['isControllerAndTemplate']; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $dispatcher = [ |
||
33 | 'matchTemplate' => 'JetFire\Routing\Dispatcher\TemplateDispatcher', |
||
34 | 'matchController' => 'JetFire\Routing\Dispatcher\ControllerDispatcher' |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * @param Router $router |
||
39 | */ |
||
40 | public function __construct(Router $router) |
||
44 | |||
45 | /** |
||
46 | * @param array $resolver |
||
47 | */ |
||
48 | public function setResolver($resolver = []){ |
||
51 | |||
52 | /** |
||
53 | * @param string $resolver |
||
54 | */ |
||
55 | public function addResolver($resolver){ |
||
58 | |||
59 | /** |
||
60 | * @return array |
||
61 | */ |
||
62 | public function getResolver() |
||
66 | |||
67 | /** |
||
68 | * @param array $dispatcher |
||
69 | */ |
||
70 | public function setDispatcher($dispatcher = []) |
||
74 | |||
75 | /** |
||
76 | * @param $method |
||
77 | * @param $class |
||
78 | * @return mixed|void |
||
79 | */ |
||
80 | public function addDispatcher($method,$class){ |
||
83 | |||
84 | /** |
||
85 | * @return bool |
||
86 | */ |
||
87 | public function match() |
||
98 | |||
99 | /** |
||
100 | * @param array $target |
||
101 | */ |
||
102 | View Code Duplication | public function setTarget($target = []){ |
|
109 | |||
110 | /** |
||
111 | * @return array|bool |
||
112 | */ |
||
113 | public function isControllerAndTemplate(){ |
||
124 | |||
125 | /** |
||
126 | * @return bool|array |
||
127 | */ |
||
128 | public function isTemplate() |
||
148 | |||
149 | /** |
||
150 | * @return bool|array |
||
151 | */ |
||
152 | public function isController() |
||
178 | |||
179 | } |
||
180 |
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.