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 | trait LengthTrait |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @Exclude |
||
| 9 | * @var integer Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero |
||
| 10 | */ |
||
| 11 | private $maxLength = null; |
||
| 12 | /** |
||
| 13 | * @Exclude |
||
| 14 | * @var integer Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero |
||
| 15 | */ |
||
| 16 | private $minLength = null; |
||
| 17 | |||
| 18 | protected function setLengthFacet($value) |
||
| 23 | |||
| 24 | protected function setMinLengthFacet($value) |
||
| 29 | |||
| 30 | private function checkValidMinMaxLength($value, $min = 0) |
||
| 39 | |||
| 40 | protected function setMaxLengthFacet($value) |
||
| 45 | |||
| 46 | private function checkMaxLength($v) |
||
| 58 | |||
| 59 | View Code Duplication | private function checkMaxLengthArray($v) |
|
| 70 | |||
| 71 | View Code Duplication | private function checkMaxLengthString($v) |
|
| 81 | |||
| 82 | private function checkMinLength($v) |
||
| 92 | |||
| 93 | View Code Duplication | private function checkMinLengthArray($v) |
|
| 104 | |||
| 105 | View Code Duplication | private function checkMinLengthString($v) |
|
| 115 | } |
||
| 116 |
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.