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 |
||
30 | View Code Duplication | class PersonalSection implements IIconSection { |
|
|
|||
31 | /** @var IURLGenerator */ |
||
32 | private $urlGenerator; |
||
33 | /** @var IL10N */ |
||
34 | private $l; |
||
35 | public function __construct(IURLGenerator $urlGenerator, IL10N $l) { |
||
39 | /** |
||
40 | * returns the relative path to an 16*16 icon describing the section. |
||
41 | * e.g. '/core/img/places/files.svg' |
||
42 | * |
||
43 | * @returns string |
||
44 | * @since 13.0.0 |
||
45 | */ |
||
46 | public function getIcon() { |
||
49 | /** |
||
50 | * returns the ID of the section. It is supposed to be a lower case string, |
||
51 | * e.g. 'ldap' |
||
52 | * |
||
53 | * @returns string |
||
54 | * @since 9.1 |
||
55 | */ |
||
56 | public function getID() { |
||
59 | /** |
||
60 | * returns the translated name as it should be displayed, e.g. 'LDAP / AD |
||
61 | * integration'. Use the L10N service to translate it. |
||
62 | * |
||
63 | * @return string |
||
64 | * @since 9.1 |
||
65 | */ |
||
66 | public function getName() { |
||
69 | /** |
||
70 | * @return int whether the form should be rather on the top or bottom of |
||
71 | * the settings navigation. The sections are arranged in ascending order of |
||
72 | * the priority values. It is required to return a value between 0 and 99. |
||
73 | * |
||
74 | * E.g.: 70 |
||
75 | * @since 9.1 |
||
76 | */ |
||
77 | public function getPriority() { |
||
80 | } |
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.