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 LengthTrait |
||
5 | { |
||
6 | /** |
||
7 | * @Exclude |
||
8 | * @var int Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero |
||
9 | */ |
||
10 | private $maxLength = null; |
||
11 | /** |
||
12 | * @Exclude |
||
13 | * @var int Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero |
||
14 | */ |
||
15 | private $minLength = null; |
||
16 | |||
17 | /** |
||
18 | * @param int $value Specifies the exact number of characters or list items allowed. Must be equal to or |
||
19 | * greater than zero |
||
20 | */ |
||
21 | protected function setLengthFacet($value) |
||
26 | |||
27 | /** |
||
28 | * @param int $value Specifies the minimum number of characters or list items allowed. Must be equal to or |
||
29 | * greater than zero |
||
30 | */ |
||
31 | protected function setMinLengthFacet($value) |
||
36 | |||
37 | /** |
||
38 | * @param int $value |
||
39 | * @param int $min |
||
40 | */ |
||
41 | private function checkValidMinMaxLength($value, $min = 0) |
||
50 | |||
51 | /** |
||
52 | * @param int $value Specifies the maximum number of characters or list items allowed. Must be equal to or |
||
53 | * greater than zero |
||
54 | */ |
||
55 | protected function setMaxLengthFacet($value) |
||
60 | |||
61 | private function checkLength($v) |
||
70 | |||
71 | View Code Duplication | private function checkMinLength($v) |
|
81 | |||
82 | private function getLengthForValue($v) |
||
89 | |||
90 | View Code Duplication | private function checkMaxLength($v) |
|
100 | } |
||
101 |
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.