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 |
||
8 | class RouterMapBuilder |
||
9 | { |
||
10 | |||
11 | private $routerConfig = []; |
||
12 | |||
13 | public function setRouterConfig(array $config) |
||
17 | |||
18 | public function build() |
||
29 | |||
30 | private function getRoutePathMap() |
||
37 | |||
38 | /** |
||
39 | * $handlers schema |
||
40 | * (string) $handlers method or function name | {closure} |
||
41 | * (array) $handlers['GET' | 'POST'] => method or function name | {closure} |
||
42 | * |
||
43 | * @param Map $routerMap |
||
44 | * @param string $path url path |
||
45 | * @param string|array|closure $handlers |
||
46 | */ |
||
47 | private function addRouterMap(Map $routerMap, $path, $handlers) |
||
57 | |||
58 | View Code Duplication | private function resolveHttpGetHandler($handlers) |
|
66 | |||
67 | View Code Duplication | private function resolveHttpPostHandler($handlers) |
|
75 | } |
||
76 |
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.