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 |
||
24 | class ResetPasswordControl extends Control implements TranslatorAwareInterface |
||
25 | { |
||
26 | use TranslatorAwareTrait; |
||
27 | |||
28 | /** @var \SixtyEightPublishers\User\ForgotPassword\Entity\PasswordRequestInterface */ |
||
29 | private $passwordRequest; |
||
30 | |||
31 | /** @var \SixtyEightPublishers\User\Common\Logger\LoggerInterface */ |
||
32 | private $logger; |
||
33 | |||
34 | /** @var \SixtyEightPublishers\User\ForgotPassword\Mail\PasswordHasBeenResetEmailInterface */ |
||
35 | private $passwordHasBeenResetEmail; |
||
36 | |||
37 | /** @var \SixtyEightPublishers\User\ForgotPassword\PasswordRequest\PasswordRequestManagerInterface */ |
||
38 | private $passwordRequestManager; |
||
39 | |||
40 | /** @var \Nette\Security\User */ |
||
41 | private $user; |
||
42 | |||
43 | /** @var bool */ |
||
44 | private $autoLogin = FALSE; |
||
45 | |||
46 | /** @var callable[] */ |
||
47 | public $onSuccess = []; |
||
48 | |||
49 | /** @var callable[] */ |
||
50 | public $onError = []; |
||
51 | |||
52 | /** @var callable[] */ |
||
53 | public $onFormCreation = []; |
||
54 | |||
55 | /** |
||
56 | * @param \SixtyEightPublishers\User\ForgotPassword\Entity\PasswordRequestInterface $passwordRequest |
||
57 | * @param \SixtyEightPublishers\User\Common\Logger\LoggerInterface $logger |
||
58 | * @param \SixtyEightPublishers\User\ForgotPassword\Mail\PasswordHasBeenResetEmailInterface $passwordHasBeenResetEmail |
||
59 | * @param \SixtyEightPublishers\User\ForgotPassword\PasswordRequest\PasswordRequestManagerInterface $passwordRequestManager |
||
60 | * @param \Nette\Security\User $user |
||
61 | */ |
||
62 | public function __construct( |
||
75 | |||
76 | /** |
||
77 | * @param bool $autoLogin |
||
78 | * |
||
79 | * @return void |
||
80 | */ |
||
81 | public function setAutoLogin(bool $autoLogin): void |
||
85 | |||
86 | /** |
||
87 | * @return void |
||
88 | */ |
||
89 | public function render(): void |
||
94 | |||
95 | /** |
||
96 | * @return \Nette\Application\UI\Form |
||
97 | */ |
||
98 | View Code Duplication | protected function createComponentForm(): Form |
|
118 | |||
119 | /** |
||
120 | * @internal |
||
121 | * |
||
122 | * @param \Nette\Application\UI\Form $form |
||
123 | * |
||
124 | * @return void |
||
125 | * @throws \Nette\Security\AuthenticationException |
||
126 | */ |
||
127 | public function processForm(Form $form): void |
||
155 | } |
||
156 |
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.