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 |
||
42 | class LdapGuardAuthenticator extends AbstractGuardAuthenticator |
||
43 | { |
||
44 | use LdapAuthenticationTrait; |
||
45 | |||
46 | /** |
||
47 | * @var LdapUserChecker |
||
48 | */ |
||
49 | protected $userChecker; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $domain; |
||
55 | |||
56 | /** |
||
57 | * @var EventDispatcherInterface |
||
58 | */ |
||
59 | protected $dispatcher; |
||
60 | |||
61 | /** |
||
62 | * @var AuthenticationSuccessHandlerInterface |
||
63 | */ |
||
64 | protected $successHandler; |
||
65 | |||
66 | /** |
||
67 | * @var AuthenticationFailureHandlerInterface |
||
68 | */ |
||
69 | protected $failureHandler; |
||
70 | |||
71 | /** |
||
72 | * @var AuthenticationEntryPointInterface |
||
73 | */ |
||
74 | protected $entryPoint; |
||
75 | |||
76 | /** |
||
77 | * @var array |
||
78 | */ |
||
79 | protected $options = [ |
||
80 | 'hide_user_not_found_exceptions' => true, |
||
81 | 'username_parameter' => '_username', |
||
82 | 'password_parameter' => '_password', |
||
83 | 'domain_parameter' => '_ldap_domain', |
||
84 | 'post_only' => false, |
||
85 | 'remember_me' => false, |
||
86 | 'login_query_attribute' => null, |
||
87 | 'http_basic' => false, |
||
88 | 'http_basic_realm' => null, |
||
89 | 'http_basic_domain' => null, |
||
90 | ]; |
||
91 | |||
92 | /** |
||
93 | * @param bool $hideUserNotFoundExceptions |
||
94 | * @param LdapUserChecker $userChecker |
||
95 | * @param LdapManager $ldap |
||
96 | * @param AuthenticationEntryPointInterface $entryPoint |
||
97 | * @param EventDispatcherInterface $dispatcher |
||
98 | * @param AuthenticationSuccessHandlerInterface $successHandler |
||
99 | * @param AuthenticationFailureHandlerInterface $failureHandler |
||
100 | * @param array $options |
||
101 | * @param LdapUserProvider $ldapUserProvider |
||
102 | */ |
||
103 | public function __construct($hideUserNotFoundExceptions = true, LdapUserChecker $userChecker, LdapManager $ldap, AuthenticationEntryPointInterface $entryPoint, EventDispatcherInterface $dispatcher, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options, LdapUserProvider $ldapUserProvider) |
||
115 | |||
116 | /** |
||
117 | * Allows to more easily extend the base LDAP guard service and set specific options. |
||
118 | * |
||
119 | * @param array $options |
||
120 | * @return $this |
||
121 | */ |
||
122 | public function setOptions(array $options) |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function supports(Request $request) |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | public function getCredentials(Request $request) |
||
154 | |||
155 | /** |
||
156 | * {@inheritdoc} |
||
157 | */ |
||
158 | public function getUser($credentials, UserProviderInterface $userProvider) |
||
182 | |||
183 | /** |
||
184 | * {@inheritdoc} |
||
185 | */ |
||
186 | public function checkCredentials($credentials, UserInterface $user) |
||
226 | |||
227 | /** |
||
228 | * {@inheritdoc} |
||
229 | */ |
||
230 | View Code Duplication | public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) |
|
243 | |||
244 | /** |
||
245 | * {@inheritdoc} |
||
246 | */ |
||
247 | public function onAuthenticationFailure(Request $request, AuthenticationException $exception) |
||
258 | |||
259 | /** |
||
260 | * {@inheritdoc} |
||
261 | */ |
||
262 | View Code Duplication | public function start(Request $request, AuthenticationException $authException = null) |
|
274 | |||
275 | /** |
||
276 | * {@inheritdoc} |
||
277 | */ |
||
278 | public function supportsRememberMe() |
||
282 | |||
283 | /** |
||
284 | * {@inheritdoc} |
||
285 | */ |
||
286 | public function createAuthenticatedToken(UserInterface $user, $providerKey) |
||
293 | |||
294 | /** |
||
295 | * @param Request $request |
||
296 | * @return null|string |
||
297 | */ |
||
298 | protected function getRequestUsername(Request $request) |
||
306 | |||
307 | /** |
||
308 | * @param Request $request |
||
309 | * @return null|string |
||
310 | */ |
||
311 | protected function getRequestPassword(Request $request) |
||
319 | |||
320 | /** |
||
321 | * @param Request $request |
||
322 | * @return null|string |
||
323 | */ |
||
324 | protected function getRequestDomain(Request $request) |
||
332 | |||
333 | /** |
||
334 | * @param string $param |
||
335 | * @param Request $request |
||
336 | * @return string|null |
||
337 | */ |
||
338 | protected function getRequestParameter($param, Request $request) |
||
348 | |||
349 | /** |
||
350 | * @return string |
||
351 | */ |
||
352 | protected function getHttpBasicRealm() |
||
364 | } |
||
365 |
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.