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 |
||
14 | View Code Duplication | class RefreshTokenRepository implements RefreshTokenRepositoryInterface |
|
|
|||
15 | { |
||
16 | /** |
||
17 | * @var Registry |
||
18 | */ |
||
19 | private $registry; |
||
20 | |||
21 | /** |
||
22 | * @param Registry $registry |
||
23 | */ |
||
24 | public function __construct(Registry $registry) |
||
28 | |||
29 | /** |
||
30 | * @return RefreshTokenEntity |
||
31 | */ |
||
32 | public function getNewRefreshToken() |
||
36 | |||
37 | /** |
||
38 | * @param RefreshTokenEntityInterface $refreshTokenEntity |
||
39 | * @throws ORMInvalidArgumentException |
||
40 | * @throws OptimisticLockException |
||
41 | */ |
||
42 | public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity) |
||
50 | |||
51 | /** |
||
52 | * @param string $tokenId |
||
53 | * @throws InvalidStateException |
||
54 | * @throws QueryException |
||
55 | * @throws OptimisticLockException |
||
56 | */ |
||
57 | public function revokeRefreshToken($tokenId) |
||
66 | |||
67 | /** |
||
68 | * @param string $tokenId |
||
69 | * @return bool |
||
70 | * @throws InvalidStateException |
||
71 | * @throws QueryException |
||
72 | */ |
||
73 | public function isRefreshTokenRevoked($tokenId) |
||
79 | |||
80 | /** |
||
81 | * @return RefreshTokenQuery |
||
82 | */ |
||
83 | protected function createQuery(): RefreshTokenQuery |
||
87 | } |
||
88 |
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.