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 |
||
| 31 | View Code Duplication | class AuditLogService |
|
|
|
|||
| 32 | { |
||
| 33 | /** |
||
| 34 | * @var LibraryAuditLogService |
||
| 35 | */ |
||
| 36 | private $service; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var ValidatorInterface |
||
| 40 | */ |
||
| 41 | private $validator; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param LibraryAuditLogService $service |
||
| 45 | * @param ValidatorInterface $validator |
||
| 46 | */ |
||
| 47 | public function __construct(LibraryAuditLogService $service, ValidatorInterface $validator) |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param SecondFactorAuditLogSearchQuery $query |
||
| 55 | * @return AuditLog |
||
| 56 | * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. |
||
| 57 | * @throws InvalidResponseException When the API responded with invalid data. |
||
| 58 | * @throws ResourceReadException When the API doesn't respond with the resource. |
||
| 59 | * @throws MalformedResponseException When the API doesn't respond with a proper response. |
||
| 60 | */ |
||
| 61 | public function searchSecondFactorAuditLog(SecondFactorAuditLogSearchQuery $query) |
||
| 81 | } |
||
| 82 |
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.