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 |
||
24 | final class OauthRefreshTokenRepository implements RefreshTokenRepositoryInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var DqlQueryBuilderInterface |
||
28 | */ |
||
29 | private $dqlQueryBuilder; |
||
30 | |||
31 | /** |
||
32 | * @var QueryServiceRouterInterface |
||
33 | */ |
||
34 | private $queryService; |
||
35 | |||
36 | /** |
||
37 | * @var PersistenceServiceInterface |
||
38 | */ |
||
39 | private $persistenceService; |
||
40 | |||
41 | public function __construct( |
||
50 | |||
51 | public function getNewRefreshToken(): RefreshTokenEntityInterface |
||
55 | |||
56 | public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshToken): void |
||
60 | |||
61 | /** |
||
62 | * @param OauthRefreshTokenId $refreshTokenId |
||
63 | */ |
||
64 | public function revokeRefreshToken($refreshTokenId): void |
||
75 | |||
76 | /** |
||
77 | * @param OauthRefreshTokenId $refreshTokenId |
||
78 | */ |
||
79 | public function isRefreshTokenRevoked($refreshTokenId): bool |
||
90 | |||
91 | View Code Duplication | private function find(OauthRefreshTokenId $refreshTokenId): OauthRefreshToken |
|
100 | } |
||
101 |
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.