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 |
||
19 | class PasswordCheckListener |
||
20 | { |
||
21 | /** |
||
22 | * @var AuthorizationCheckerInterface |
||
23 | */ |
||
24 | private $authorizationChecker; |
||
25 | |||
26 | /** |
||
27 | * @var TokenStorageInterface |
||
28 | */ |
||
29 | private $tokenStorage; |
||
30 | |||
31 | /** |
||
32 | * @var Router |
||
33 | */ |
||
34 | private $router; |
||
35 | |||
36 | /** |
||
37 | * @var Session |
||
38 | */ |
||
39 | private $session; |
||
40 | |||
41 | /** |
||
42 | * @var TranslatorInterface |
||
43 | */ |
||
44 | private $translator; |
||
45 | |||
46 | /** |
||
47 | * @var AdminRouteHelper |
||
48 | */ |
||
49 | private $adminRouteHelper; |
||
50 | |||
51 | /** |
||
52 | * @param AuthorizationCheckerInterface $authorizationChecker |
||
53 | * @param TokenStorageInterface $tokenStorage |
||
54 | * @param Router $router |
||
55 | * @param Session $session |
||
56 | * @param TranslatorInterface $translator |
||
57 | * @param AdminRouteHelper $adminRouteHelper |
||
58 | */ |
||
59 | 3 | public function __construct(AuthorizationCheckerInterface $authorizationChecker, TokenStorageInterface $tokenStorage, Router $router, Session $session, TranslatorInterface $translator, AdminRouteHelper $adminRouteHelper) |
|
68 | |||
69 | /** |
||
70 | * @param GetResponseEvent|ResponseEvent $event |
||
71 | **/ |
||
72 | 3 | public function onKernelRequest($event) |
|
98 | } |
||
99 |
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.