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 RefreshTokenRepository implements RefreshTokenRepositoryInterface |
|
|
|||
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 RefreshTokenEntity |
||
32 | */ |
||
33 | public function getNewRefreshToken() |
||
37 | |||
38 | /** |
||
39 | * @param RefreshTokenEntityInterface $refreshTokenEntity |
||
40 | */ |
||
41 | public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity) |
||
46 | |||
47 | /** |
||
48 | * @param string $tokenId |
||
49 | */ |
||
50 | public function revokeRefreshToken($tokenId) |
||
55 | |||
56 | /** |
||
57 | * @param string $tokenId |
||
58 | * @return bool |
||
59 | */ |
||
60 | public function isRefreshTokenRevoked($tokenId) |
||
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.