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 |
||
| 32 | class GetQrCode |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * @var GetQrCodeInterfaceFactory |
||
| 36 | */ |
||
| 37 | private $response; |
||
| 38 | /** |
||
| 39 | * @var IsUsingTwoFactor |
||
| 40 | */ |
||
| 41 | private $isUsingTwoFactor; |
||
| 42 | /** |
||
| 43 | * @var TwoFactorSecret |
||
| 44 | */ |
||
| 45 | private $twoFactorSecret; |
||
| 46 | /** |
||
| 47 | * @var QRCode |
||
| 48 | */ |
||
| 49 | private $qrCode; |
||
| 50 | /** |
||
| 51 | * @var GetQrCodeFetcher |
||
| 52 | */ |
||
| 53 | private $getQrCode; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * GetQrCode constructor. |
||
| 57 | * |
||
| 58 | * @param GetQrCodeInterfaceFactory $response |
||
| 59 | * @param IsUsingTwoFactor $isUsingTwoFactor |
||
| 60 | * @param TwoFactorSecret $twoFactorSecret |
||
| 61 | * @param QRCode $qrCode |
||
| 62 | * @param GetQrCodeFetcher $getQrCode |
||
| 63 | */ |
||
| 64 | public function __construct( |
||
| 78 | |||
| 79 | public function buildResponseForCustomer(CustomerInterface $customer) |
||
| 92 | |||
| 93 | View Code Duplication | private function isUsingTwoFactor(CustomerInterface $customer) |
|
| 102 | } |
||
| 103 |
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.