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 | final class Configuration |
||
14 | { |
||
15 | const OPT_TRANSACTIONAL = 'transactional'; |
||
16 | const OPT_OPEN_TRACKING = 'open_tracking'; |
||
17 | const OPT_CLICK_TRACKING = 'click_tracking'; |
||
18 | const OPT_SANDBOX = 'sandbox'; |
||
19 | const OPT_SKIP_SUPPRESSION = 'skip_suppression'; |
||
20 | const OPT_INLINE_CSS = 'inline_css'; |
||
21 | const OPT_IP_POOL = 'ip_pool'; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $recipientOverride; |
||
27 | |||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | private $overrideGmailStyle; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | private $options; |
||
37 | |||
38 | /** |
||
39 | * @param array $options |
||
40 | * |
||
41 | * @throws Exception |
||
42 | */ |
||
43 | 24 | public static function guardOptionValidity(array $options) |
|
61 | |||
62 | /** |
||
63 | * @return Configuration |
||
64 | */ |
||
65 | 39 | public static function newInstance() |
|
69 | |||
70 | 75 | public function __construct() |
|
76 | |||
77 | 51 | public function overrideRecipients() |
|
81 | |||
82 | /** |
||
83 | * @return bool |
||
84 | */ |
||
85 | 18 | public function overrideGmailStyle() |
|
89 | |||
90 | /** |
||
91 | * @param bool $overrideGmailStyle |
||
92 | * |
||
93 | * @return Configuration |
||
94 | */ |
||
95 | 9 | public function setOverrideGmailStyle($overrideGmailStyle) |
|
101 | |||
102 | /** |
||
103 | * @return string |
||
104 | */ |
||
105 | 18 | public function getRecipientOverride() |
|
109 | |||
110 | /** |
||
111 | * @param string $recipientOverride |
||
112 | * |
||
113 | * @return Configuration |
||
114 | * @throws Exception |
||
115 | */ |
||
116 | 21 | public function setRecipientOverride($recipientOverride) |
|
126 | |||
127 | /** |
||
128 | * @return array |
||
129 | */ |
||
130 | 51 | public function getOptions() |
|
134 | |||
135 | /** |
||
136 | * @param array $options |
||
137 | * |
||
138 | * @return Configuration |
||
139 | * @throws Exception |
||
140 | */ |
||
141 | 15 | View Code Duplication | public function setOptions(array $options) |
156 | } |
||
157 |
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.