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 |
||
23 | class DirectDebitSubForm extends AbstractPayoneSubForm |
||
24 | { |
||
25 | const PAYMENT_METHOD = 'direct_debit'; |
||
26 | const FIELD_IBAN = 'iban'; |
||
27 | const FIELD_BIC = 'bic'; |
||
28 | const FIELD_BANK_COUNTRY = 'bankcountry'; |
||
29 | const FIELD_BANK_ACCOUNT = 'bankaccount'; |
||
30 | const FIELD_BANK_ACCOUNT_MODE = 'bankaccountmode'; |
||
31 | const FIELD_BANK_CODE = 'bankcode'; |
||
32 | const OPTION_BANK_COUNTRIES = 'direct debit bank countries'; |
||
33 | const OPTION_BANK_ACCOUNT_MODE = 'direct debit bank account mode'; |
||
34 | |||
35 | /** |
||
36 | * @return string |
||
37 | */ |
||
38 | public function getName() |
||
42 | |||
43 | /** |
||
44 | * @return string |
||
45 | */ |
||
46 | public function getPropertyPath() |
||
50 | |||
51 | /** |
||
52 | * @return string |
||
53 | */ |
||
54 | public function getTemplatePath() |
||
58 | |||
59 | /** |
||
60 | * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver |
||
61 | * |
||
62 | * @return void |
||
63 | */ |
||
64 | public function configureOptions(OptionsResolver $resolver) |
||
70 | |||
71 | /** |
||
72 | * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver |
||
73 | * |
||
74 | * @return void |
||
75 | */ |
||
76 | public function setDefaultOptions(OptionsResolver $resolver) |
||
80 | |||
81 | /** |
||
82 | * @param \Symfony\Component\Form\FormBuilderInterface $builder |
||
83 | * @param array $options |
||
84 | * |
||
85 | * @return void |
||
86 | */ |
||
87 | public function buildForm(FormBuilderInterface $builder, array $options) |
||
99 | |||
100 | /** |
||
101 | * @param \Symfony\Component\Form\FormBuilderInterface $builder |
||
102 | * @param array $options |
||
103 | * |
||
104 | * @return \SprykerEco\Yves\Payone\Form\DirectDebitSubForm |
||
105 | */ |
||
106 | protected function addModeSwitch(FormBuilderInterface $builder, array $options) |
||
125 | |||
126 | /** |
||
127 | * @param \Symfony\Component\Form\FormBuilderInterface $builder |
||
128 | * |
||
129 | * @return \SprykerEco\Yves\Payone\Form\DirectDebitSubForm |
||
130 | */ |
||
131 | protected function addBankAccount(FormBuilderInterface $builder) |
||
146 | |||
147 | /** |
||
148 | * @param \Symfony\Component\Form\FormBuilderInterface $builder |
||
149 | * |
||
150 | * @return \SprykerEco\Yves\Payone\Form\DirectDebitSubForm |
||
151 | */ |
||
152 | protected function addBankCode(FormBuilderInterface $builder) |
||
167 | |||
168 | /** |
||
169 | * @param \Symfony\Component\Form\FormBuilderInterface $builder |
||
170 | * @param array $options |
||
171 | * |
||
172 | * @return \SprykerEco\Yves\Payone\Form\DirectDebitSubForm |
||
173 | */ |
||
174 | protected function addBankCountry(FormBuilderInterface $builder, array $options) |
||
204 | |||
205 | /** |
||
206 | * @param \Symfony\Component\Form\FormBuilderInterface $builder |
||
207 | * |
||
208 | * @return \SprykerEco\Yves\Payone\Form\DirectDebitSubForm |
||
209 | */ |
||
210 | View Code Duplication | protected function addIBAN(FormBuilderInterface $builder) |
|
225 | |||
226 | /** |
||
227 | * @param \Symfony\Component\Form\FormBuilderInterface $builder |
||
228 | * |
||
229 | * @return \SprykerEco\Yves\Payone\Form\DirectDebitSubForm |
||
230 | */ |
||
231 | protected function addBIC(FormBuilderInterface $builder) |
||
247 | |||
248 | /** |
||
249 | * @return \Symfony\Component\Validator\Constraint |
||
250 | */ |
||
251 | protected function createNotBlankConstraint() |
||
255 | |||
256 | /** |
||
257 | * @return \Symfony\Component\Validator\Constraint |
||
258 | */ |
||
259 | protected function createManageMandateConstraint() |
||
263 | } |
||
264 |
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.