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 |
||
| 33 | View Code Duplication | class RaSecondFactorService |
|
|
|
|||
| 34 | { |
||
| 35 | /** |
||
| 36 | * @var LibraryRaSecondFactorService |
||
| 37 | */ |
||
| 38 | private $service; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var ValidatorInterface |
||
| 42 | */ |
||
| 43 | private $validator; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param LibraryRaSecondFactorService $service |
||
| 47 | * @param ValidatorInterface $validator |
||
| 48 | */ |
||
| 49 | public function __construct(LibraryRaSecondFactorService $service, ValidatorInterface $validator) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param RaSecondFactorSearchQuery $query |
||
| 57 | * @return RaSecondFactorCollection |
||
| 58 | * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource. |
||
| 59 | * @throws InvalidResponseException When the API responded with invalid data. |
||
| 60 | * @throws ResourceReadException When the API doesn't respond with the resource. |
||
| 61 | * @throws MalformedResponseException When the API doesn't respond with a proper response. |
||
| 62 | */ |
||
| 63 | public function search(RaSecondFactorSearchQuery $query) |
||
| 83 | } |
||
| 84 |
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.