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 |
||
18 | View Code Duplication | abstract class Electricity |
|
|
|||
19 | { |
||
20 | private $config; |
||
21 | private $clubKonnect; |
||
22 | |||
23 | public function __construct(ClubKonnect $clubKonnect, $config) |
||
28 | |||
29 | /** |
||
30 | * @return ClubKonnectResponse |
||
31 | */ |
||
32 | public function getDiscosAndMinMax(): ClubKonnectResponse |
||
36 | |||
37 | /** |
||
38 | * @param DiscoEnum $disco |
||
39 | * @param $meterNumber |
||
40 | * @return ClubKonnectResponse |
||
41 | */ |
||
42 | public function verifyMeterNumber(DiscoEnum $disco, $meterNumber): ClubKonnectResponse |
||
49 | |||
50 | /** |
||
51 | * @param DiscoEnum $disco |
||
52 | * @param $meterNumber |
||
53 | * @param $amount |
||
54 | * @param MeterTypeEnum $meterType |
||
55 | * @param $requestID |
||
56 | * @param $callbackUrl |
||
57 | * @return ClubKonnectResponse |
||
58 | */ |
||
59 | public function buyElectricity(DiscoEnum $disco, $meterNumber, $amount, MeterTypeEnum $meterType, $requestID, $callbackUrl = null): ClubKonnectResponse |
||
71 | |||
72 | } |
||
73 |
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.