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 SettingAsMember implements ISetting { |
|
|
|||
10 | |||
11 | /** @var IL10N */ |
||
12 | protected $l10n; |
||
13 | |||
14 | /** |
||
15 | * @param IL10N $l10n |
||
16 | */ |
||
17 | public function __construct(IL10N $l10n) { |
||
20 | |||
21 | /** |
||
22 | * @return string Lowercase a-z and underscore only identifier |
||
23 | * @since 11.0.0 |
||
24 | */ |
||
25 | public function getIdentifier() { |
||
28 | |||
29 | /** |
||
30 | * @return string A translated string |
||
31 | * @since 11.0.0 |
||
32 | */ |
||
33 | public function getName() { |
||
36 | |||
37 | /** |
||
38 | * @return int whether the filter should be rather on the top or bottom of |
||
39 | * the admin section. The filters are arranged in ascending order of the |
||
40 | * priority values. It is required to return a value between 0 and 100. |
||
41 | * @since 11.0.0 |
||
42 | */ |
||
43 | public function getPriority() { |
||
46 | |||
47 | /** |
||
48 | * @return bool True when the option can be changed for the stream |
||
49 | * @since 11.0.0 |
||
50 | */ |
||
51 | public function canChangeStream() { |
||
54 | |||
55 | /** |
||
56 | * @return bool True when the option can be changed for the stream |
||
57 | * @since 11.0.0 |
||
58 | */ |
||
59 | public function isDefaultEnabledStream() { |
||
62 | |||
63 | /** |
||
64 | * @return bool True when the option can be changed for the mail |
||
65 | * @since 11.0.0 |
||
66 | */ |
||
67 | public function canChangeMail() { |
||
70 | |||
71 | /** |
||
72 | * @return bool True when the option can be changed for the stream |
||
73 | * @since 11.0.0 |
||
74 | */ |
||
75 | public function isDefaultEnabledMail() { |
||
78 | } |
||
79 | |||
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.