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 |
||
| 24 | View Code Duplication | class TwoFactorSecret |
|
|
|
|||
| 25 | { |
||
| 26 | const ATTRIBUTE_CODE = 'two_factor_secret'; |
||
| 27 | /** |
||
| 28 | * @var Getter |
||
| 29 | */ |
||
| 30 | private $getter; |
||
| 31 | /** |
||
| 32 | * @var Setter |
||
| 33 | */ |
||
| 34 | private $setter; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * TwoFactorSecret constructor. |
||
| 38 | * |
||
| 39 | * @param Getter $getter |
||
| 40 | * @param Setter $setter |
||
| 41 | */ |
||
| 42 | 10 | public function __construct(Getter $getter, Setter $setter) |
|
| 47 | |||
| 48 | 6 | public function getValue($customer) |
|
| 52 | |||
| 53 | public function setValue($customer, $value) |
||
| 57 | |||
| 58 | 2 | public function hasValue($customer) |
|
| 62 | } |
||
| 63 |
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.