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 | class MaintenanceOperation |
||
6 | { |
||
7 | const OPERATION_AUTHORISATION_RENEW = 'REN'; |
||
8 | const OPERATION_AUTHORISATION_DELETE = 'DEL'; |
||
9 | const OPERATION_AUTHORISATION_DELETE_AND_CLOSE = 'DES'; |
||
10 | const OPERATION_CAPTURE_PARTIAL = 'SAL'; |
||
11 | const OPERATION_CAPTURE_LAST_OR_FULL = 'SAS'; |
||
12 | const OPERATION_REFUND_PARTIAL = 'RFD'; |
||
13 | const OPERATION_REFUND_LAST_OR_FULL = 'RFS'; |
||
14 | |||
15 | protected $operation; |
||
16 | |||
17 | 8 | View Code Duplication | public function __construct($operation) |
25 | |||
26 | 1 | public function equals(MaintenanceOperation $other) |
|
30 | |||
31 | 5 | public function __toString() |
|
35 | |||
36 | 8 | private function getAllAvailableOperations() |
|
48 | } |
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.