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 |
||
18 | View Code Duplication | class AuthorizationCodeGrant implements AuthorizationGrantInterface |
|
|
|||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var ClientRepositoryInterface |
||
23 | */ |
||
24 | private $clientRepository; |
||
25 | |||
26 | /** |
||
27 | * @var ScopeRepositoryInterface |
||
28 | */ |
||
29 | private $scopeRepository; |
||
30 | |||
31 | /** |
||
32 | * @var UserRepositoryInterface |
||
33 | */ |
||
34 | private $userRepository; |
||
35 | |||
36 | /** |
||
37 | * @var AccessTokenRepositoryInterface |
||
38 | */ |
||
39 | private $accessTokenRepository; |
||
40 | |||
41 | /** |
||
42 | * @var RefreshTokenRepositoryInterface |
||
43 | */ |
||
44 | private $refreshTokenRepository; |
||
45 | |||
46 | /** |
||
47 | * @var TokenTypeInterface |
||
48 | */ |
||
49 | private $token; |
||
50 | |||
51 | /** |
||
52 | * @param ClientRepositoryInterface $clientRepository |
||
53 | * @param ScopeRepositoryInterface $scopeRepository |
||
54 | * @param UserRepositoryInterface $userRepository |
||
55 | * @param AccessTokenRepositoryInterface $accessTokenRepository |
||
56 | * @param RefreshTokenRepositoryInterface $refreshTokenRepository |
||
57 | * @param TokenTypeInterface $token |
||
58 | */ |
||
59 | public function __construct( |
||
74 | |||
75 | /** |
||
76 | * @param Request $request |
||
77 | * @return bool |
||
78 | */ |
||
79 | public function supports(Request $request) |
||
83 | |||
84 | /** |
||
85 | * @param Request $request |
||
86 | * @param ResponseBuilderInterface $responseBuilder |
||
87 | * @return mixed |
||
88 | */ |
||
89 | public function handle(Request $request, ResponseBuilderInterface $responseBuilder) |
||
105 | |||
106 | /** |
||
107 | * @param Request $request |
||
108 | * @return ClientEntityInterface |
||
109 | * @throws AuthorizationServerException |
||
110 | */ |
||
111 | private function validateClient(Request $request) |
||
145 | |||
146 | /** |
||
147 | * @param Request $request |
||
148 | * @return ScopeEntityInterface[] |
||
149 | */ |
||
150 | private function validateScopes(Request $request) |
||
159 | |||
160 | private function validateUser(Request $request) |
||
179 | |||
180 | /** |
||
181 | * @return string |
||
182 | */ |
||
183 | private function getIdentifier() |
||
187 | |||
188 | public function cancel() |
||
192 | |||
193 | public function validate(Request $request) |
||
197 | } |
||
198 |
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.