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 |
||
13 | View Code Duplication | class LocaleBlacklistRule extends AbstractRule |
|
|
|||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | * @ORM\Column(name="locale", type="text", nullable=true) |
||
18 | * @Assert\NotBlank() |
||
19 | */ |
||
20 | private $locale; |
||
21 | |||
22 | /** |
||
23 | * @return string |
||
24 | */ |
||
25 | 1 | public function getLocale() |
|
29 | |||
30 | /** |
||
31 | * @param string $locale |
||
32 | * |
||
33 | * @return LocaleWhitelistRule |
||
34 | */ |
||
35 | 1 | public function setLocale($locale) |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | 1 | public function getJsObjectClass() |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 1 | public function getJsProperties() |
|
59 | |||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | 1 | public function getService() |
|
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | 1 | public function getJsFilePath() |
|
75 | |||
76 | /** |
||
77 | * @return string |
||
78 | */ |
||
79 | 1 | public function getAdminType() |
|
83 | } |
||
84 |
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.