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 |
||
5 | class Parameters |
||
6 | { |
||
7 | protected $country = null; |
||
8 | protected $case = null; |
||
9 | protected $type = null; |
||
10 | |||
11 | 30 | public function __construct($params) |
|
18 | |||
19 | 30 | View Code Duplication | protected function pullCountry($params) |
35 | |||
36 | 30 | protected function pullCase($params) |
|
47 | |||
48 | 30 | View Code Duplication | protected function pullType($params) |
64 | |||
65 | 24 | public function getCountry() |
|
69 | |||
70 | 24 | public function getCase() |
|
74 | |||
75 | 24 | public function getType() |
|
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.