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 |
||
31 | View Code Duplication | class PersonalSettings implements ISettings { |
|
|
|||
32 | |||
33 | /** @var IConfig */ |
||
34 | private $config; |
||
35 | /** @var \OC_Defaults */ |
||
36 | private $defaults; |
||
37 | |||
38 | public function __construct(IConfig $config, \OC_Defaults $defaults) { |
||
42 | |||
43 | /** |
||
44 | * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
||
45 | * @since 9.1 |
||
46 | */ |
||
47 | public function getForm() { |
||
51 | |||
52 | /** |
||
53 | * @return string the section ID, e.g. 'sharing' |
||
54 | * @since 9.1 |
||
55 | */ |
||
56 | public function getSection() { |
||
59 | |||
60 | /** |
||
61 | * @return int whether the form should be rather on the top or bottom of |
||
62 | * the admin section. The forms are arranged in ascending order of the |
||
63 | * priority values. It is required to return a value between 0 and 100. |
||
64 | * |
||
65 | * E.g.: 70 |
||
66 | * @since 9.1 |
||
67 | */ |
||
68 | public function getPriority() { |
||
71 | |||
72 | } |
||
73 |
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.