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 | class ApiKeyAuthenticator extends AbstractGuardAuthenticator |
||
19 | { |
||
20 | /** |
||
21 | * @var ManagerRegistry |
||
22 | */ |
||
23 | private $registry; |
||
24 | /** |
||
25 | * @var Logger |
||
26 | */ |
||
27 | private $logger; |
||
28 | |||
29 | public function __construct(ManagerRegistry $registry, Logger $logger) |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | public function getCredentials(Request $request) |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public function getUser($credentials, UserProviderInterface $userProvider) |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function checkCredentials($credentials, UserInterface $user) |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) |
||
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | View Code Duplication | public function onAuthenticationFailure(Request $request, AuthenticationException $exception) |
|
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | View Code Duplication | public function start(Request $request, AuthenticationException $authException = null) |
|
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | public function supportsRememberMe() |
||
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | private function saveSwindler($request) |
||
145 | } |
||
146 |
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.