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 |
||
9 | View Code Duplication | class LocaleWhiteListAdminType extends AbstractRuleAdminType |
|
|
|||
10 | { |
||
11 | private $locales; |
||
12 | |||
13 | public function __construct(DomainConfigurationInterface $domainConfiguration) |
||
18 | |||
19 | /** |
||
20 | * Builds the form. |
||
21 | * |
||
22 | * This method is called for each type in the hierarchy starting form the |
||
23 | * top most type. Type extensions can further modify the form. |
||
24 | * |
||
25 | * @see FormTypeExtensionInterface::buildForm() |
||
26 | * |
||
27 | * @param FormBuilderInterface $builder The form builder |
||
28 | * @param array $options The options |
||
29 | */ |
||
30 | public function buildForm(FormBuilderInterface $builder, array $options) |
||
40 | |||
41 | /** |
||
42 | * Returns the name of this type. |
||
43 | * |
||
44 | * @return string The name of this type |
||
45 | */ |
||
46 | public function getBlockPrefix() |
||
50 | } |
||
51 |
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.