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 |
||
19 | abstract class DomainBase implements DomainInterface |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Equivalent to `__FILE__` for main plugin file. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | private $plugin_file; |
||
28 | |||
29 | /** |
||
30 | * String indicating version for plugin |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | private $version; |
||
35 | |||
36 | /** |
||
37 | * @var string $plugin_basename |
||
38 | */ |
||
39 | private $plugin_basename; |
||
40 | |||
41 | /** |
||
42 | * @var string $plugin_path |
||
43 | */ |
||
44 | private $plugin_path; |
||
45 | |||
46 | /** |
||
47 | * @var string $plugin_url |
||
48 | */ |
||
49 | private $plugin_url; |
||
50 | |||
51 | |||
52 | |||
53 | /** |
||
54 | * Initializes internal properties. |
||
55 | * |
||
56 | * @param string $plugin_file |
||
57 | * @param string $version |
||
58 | * @throws InvalidArgumentException |
||
59 | */ |
||
60 | public function __construct($plugin_file, $version) |
||
68 | |||
69 | |||
70 | /** |
||
71 | * @param string $plugin_file |
||
72 | * @throws InvalidArgumentException |
||
73 | */ |
||
74 | View Code Duplication | private function setPluginFile($plugin_file) |
|
94 | |||
95 | |||
96 | /** |
||
97 | * @param string $version |
||
98 | * @throws InvalidArgumentException |
||
99 | */ |
||
100 | View Code Duplication | private function setVersion($version) |
|
120 | |||
121 | |||
122 | /** |
||
123 | * @return string |
||
124 | * @throws DomainException |
||
125 | */ |
||
126 | public function pluginFile() |
||
130 | |||
131 | |||
132 | |||
133 | /** |
||
134 | * @return string |
||
135 | * @throws DomainException |
||
136 | */ |
||
137 | public function pluginBasename() |
||
141 | |||
142 | |||
143 | |||
144 | /** |
||
145 | * @return string |
||
146 | */ |
||
147 | public function pluginPath() |
||
151 | |||
152 | |||
153 | |||
154 | /** |
||
155 | * @return string |
||
156 | * @throws DomainException |
||
157 | */ |
||
158 | public function pluginUrl() |
||
162 | |||
163 | |||
164 | |||
165 | /** |
||
166 | * @return string |
||
167 | * @throws DomainException |
||
168 | */ |
||
169 | public function version() |
||
173 | |||
174 | |||
175 | } |
||
176 |