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 ControlFactory |
||
9 | { |
||
10 | |||
11 | /** @var array */ |
||
12 | private $config; |
||
13 | |||
14 | /** @var string */ |
||
15 | private $basePath; |
||
16 | |||
17 | |||
18 | 5 | public function __construct(array $config = NULL) |
|
27 | |||
28 | |||
29 | 5 | public function setConfig(array $config) |
|
33 | |||
34 | |||
35 | /** |
||
36 | * @return string |
||
37 | */ |
||
38 | 1 | public function getBasePath() |
|
42 | |||
43 | |||
44 | /** |
||
45 | * @param string $basePath |
||
46 | */ |
||
47 | 5 | public function setBasePath($basePath) |
|
51 | |||
52 | |||
53 | 2 | View Code Duplication | public function createCssControl($section) |
65 | |||
66 | |||
67 | 2 | View Code Duplication | public function createJsControl($section) |
79 | |||
80 | } |
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.