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 |
||
| 7 | final class DeviceRegisteredEvent extends AbstractEvent |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | private $deviceLibraryIdentifier; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | private $passTypeIdentifier; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | private $serialNumber; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | private $authenticationToken; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | private $pushToken; |
||
| 33 | |||
| 34 | 1 | View Code Duplication | public function __construct( |
| 48 | |||
| 49 | 1 | public function getDeviceLibraryIdentifier(): string |
|
| 53 | |||
| 54 | 1 | public function getPassTypeIdentifier(): string |
|
| 58 | |||
| 59 | 1 | public function getSerialNumber(): string |
|
| 63 | |||
| 64 | 1 | public function getAuthenticationToken(): string |
|
| 68 | |||
| 69 | 1 | public function getPushToken(): string |
|
| 73 | |||
| 74 | 1 | public function deviceRegistered(): void |
|
| 78 | } |
||
| 79 |
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.