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 |
||
12 | View Code Duplication | class AuthCodeRepository implements AuthCodeRepositoryInterface |
|
|
|||
13 | { |
||
14 | /** |
||
15 | * @var EntityManager |
||
16 | */ |
||
17 | private $entityManager; |
||
18 | |||
19 | /** |
||
20 | * @var EntityRepository |
||
21 | */ |
||
22 | private $repository; |
||
23 | |||
24 | public function __construct(EntityManager $entityManager) |
||
29 | |||
30 | /** |
||
31 | * @return AuthCodeEntityInterface |
||
32 | */ |
||
33 | public function getNewAuthCode() |
||
37 | |||
38 | /** |
||
39 | * @param AuthCodeEntityInterface $authCodeEntity |
||
40 | */ |
||
41 | public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity) |
||
46 | |||
47 | /** |
||
48 | * @param string $codeId |
||
49 | */ |
||
50 | public function revokeAuthCode($codeId) |
||
55 | |||
56 | /** |
||
57 | * @param string $codeId |
||
58 | * @return bool |
||
59 | */ |
||
60 | public function isAuthCodeRevoked($codeId) |
||
64 | |||
65 | /** |
||
66 | * @return QueryObject |
||
67 | */ |
||
68 | protected function createQuery(): QueryObject |
||
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.