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 |
||
31 | class Yaml extends Ini |
||
32 | { |
||
33 | /** |
||
34 | * @var Project |
||
35 | */ |
||
36 | protected $project; |
||
37 | |||
38 | /** |
||
39 | * |
||
40 | */ |
||
41 | public function __construct() |
||
45 | |||
46 | /** |
||
47 | * @return string |
||
48 | */ |
||
49 | public function getCode() |
||
53 | |||
54 | /** |
||
55 | * @return Project[] |
||
56 | */ |
||
57 | public function getProjects() |
||
61 | |||
62 | /** |
||
63 | * @return Project |
||
64 | */ |
||
65 | public function getProject() |
||
69 | |||
70 | /** |
||
71 | * @param string $content |
||
72 | * @param string $filename |
||
73 | */ |
||
74 | View Code Duplication | public function processContent($content, $filename = null) |
|
88 | |||
89 | /** |
||
90 | * @param string $content |
||
91 | * @return array |
||
92 | * @throws ParseException |
||
93 | */ |
||
94 | protected function parseContent($content) |
||
106 | |||
107 | /** |
||
108 | * @return array |
||
109 | */ |
||
110 | protected function getRequiredKeys() |
||
114 | |||
115 | /** |
||
116 | * @param string $filename |
||
117 | */ |
||
118 | public function processFile($filename) |
||
124 | |||
125 | /** |
||
126 | * @parser string $filename |
||
127 | * @return integer |
||
128 | */ |
||
129 | public function supportedFile($filename) |
||
134 | } |
||
135 | |||
136 |
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.