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 |
||
4 | trait DigitsTrait |
||
5 | { |
||
6 | /** |
||
7 | * @Exclude |
||
8 | * @var int Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero |
||
9 | */ |
||
10 | private $fractionDigits = null; |
||
11 | /** |
||
12 | * @Exclude |
||
13 | * @var int Specifies the exact number of digits allowed. Must be greater than zero |
||
14 | */ |
||
15 | private $totalDigits = null; |
||
16 | |||
17 | /** |
||
18 | * @param int $fd Specifies the exact number of digits allowed. Must be greater than zero |
||
19 | */ |
||
20 | public function setTotalDigits($fd) |
||
25 | |||
26 | /** |
||
27 | * @param int $fd |
||
28 | */ |
||
29 | private function checkDigitLength($fd) |
||
47 | |||
48 | View Code Duplication | public function checkTotalDigits($v) |
|
60 | |||
61 | /** |
||
62 | * @param int $fd Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero |
||
63 | */ |
||
64 | public function setFractionDigits($fd) |
||
69 | |||
70 | /** |
||
71 | * Checks the number of fraction digits to verify they are not longer then expected. |
||
72 | * |
||
73 | * @param float $v the value to check fraction digits on |
||
74 | */ |
||
75 | View Code Duplication | public function checkFractionDigits($v) |
|
89 | |||
90 | /** |
||
91 | * @param float $v the digit to be fixed |
||
92 | * |
||
93 | * @return float |
||
94 | */ |
||
95 | public function fixFractionDigits($v) |
||
102 | } |
||
103 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.