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 PasswordResetController |
||
20 | { |
||
21 | /** @var UserRepositoryCollection */ |
||
22 | private $userRepositoryCollection; |
||
23 | |||
24 | /** @var ResetPasswordHandler */ |
||
25 | private $resetPasswordHandler; |
||
26 | |||
27 | /** @var Router */ |
||
28 | private $router; |
||
29 | |||
30 | /** @var FormFactoryInterface */ |
||
31 | private $formFactory; |
||
32 | |||
33 | /** @var EngineInterface */ |
||
34 | private $templating; |
||
35 | |||
36 | /** @var Translator */ |
||
37 | private $translator; |
||
38 | |||
39 | /** @var FlashBagInterface */ |
||
40 | private $flashBag; |
||
41 | |||
42 | /** |
||
43 | * @param UserRepositoryCollection $userRepositoryCollection |
||
44 | * @param ResetPasswordHandler $resetPasswordHandler |
||
45 | * @param Router $router |
||
46 | * @param FormFactoryInterface $formFactory |
||
47 | * @param EngineInterface $templating |
||
48 | * @param Translator $translator |
||
49 | * @param FlashBagInterface $flashBag |
||
50 | */ |
||
51 | View Code Duplication | public function __construct( |
|
68 | |||
69 | /** |
||
70 | * @param Request $request |
||
71 | * @param PasswordResetToken $token |
||
72 | * |
||
73 | * @throws InvalidPasswordConfirmationException |
||
74 | * |
||
75 | * @return RedirectResponse |
||
76 | */ |
||
77 | public function resetAction(Request $request, PasswordResetToken $token) |
||
114 | } |
||
115 |
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.