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 |
||
6 | trait digitsTrait |
||
7 | { |
||
8 | /** |
||
9 | * @Exclude |
||
10 | * @var integer Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero |
||
11 | */ |
||
12 | private $fractionDigits = null; |
||
13 | /** |
||
14 | * @Exclude |
||
15 | * @var integer Specifies the exact number of digits allowed. Must be greater than zero |
||
16 | */ |
||
17 | private $totalDigits = null; |
||
18 | |||
19 | public function setTotalDigits($fd) |
||
24 | |||
25 | private function checkDigitLength($fd) |
||
43 | |||
44 | View Code Duplication | public function checkTotalDigits($v) |
|
56 | |||
57 | public function setFractionDigits($fd) |
||
62 | |||
63 | View Code Duplication | public function checkFractionDigits($v) |
|
77 | |||
78 | public function fixFractionDigits($v) |
||
84 | } |
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.