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 |
||
26 | class Loader |
||
27 | { |
||
28 | /** |
||
29 | * Loader instance. |
||
30 | * |
||
31 | * @static |
||
32 | * |
||
33 | * @var Loader |
||
34 | */ |
||
35 | private static $_instance; |
||
36 | |||
37 | /** |
||
38 | * Default gettext domain to use. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | private $default_domain = ''; |
||
43 | |||
44 | /** |
||
45 | * Configured locale. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | private $locale = ''; |
||
50 | |||
51 | /** |
||
52 | * Loaded domains. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | private $domains = array(); |
||
57 | |||
58 | /** |
||
59 | * Bound paths for domains. |
||
60 | * |
||
61 | * @var array |
||
62 | */ |
||
63 | private $paths = array('' => './'); |
||
64 | |||
65 | /** |
||
66 | * Returns the singleton Loader object. |
||
67 | * |
||
68 | * @return Loader object |
||
69 | */ |
||
70 | 5 | public static function getInstance() |
|
78 | |||
79 | /** |
||
80 | * Loads global localizaton functions. |
||
81 | */ |
||
82 | 2 | public static function loadFunctions() |
|
86 | |||
87 | /** |
||
88 | * Figure out all possible locale names and start with the most |
||
89 | * specific ones. I.e. for sr_CS.UTF-8@latin, look through all of |
||
90 | * sr_CS.UTF-8@latin, sr_CS@latin, sr@latin, sr_CS.UTF-8, sr_CS, sr. |
||
91 | * |
||
92 | * @param string $locale Locale code |
||
93 | * |
||
94 | * @return array list of locales to try for any POSIX-style locale specification |
||
95 | */ |
||
96 | 18 | public static function listLocales($locale) |
|
143 | |||
144 | /** |
||
145 | * Returns Translator object for domain or for default domain. |
||
146 | * |
||
147 | * @param string $domain Translation domain |
||
148 | * |
||
149 | * @return Translator |
||
150 | */ |
||
151 | public function getTranslator($domain = '') |
||
181 | |||
182 | /** |
||
183 | * Sets the path for a domain. |
||
184 | * |
||
185 | * @param string $domain Domain name |
||
186 | * @param string $path Path where to find locales |
||
187 | */ |
||
188 | public function bindtextdomain($domain, $path) |
||
192 | |||
193 | /** |
||
194 | * Sets the default domain. |
||
195 | * |
||
196 | * @param string $domain Domain name |
||
197 | */ |
||
198 | public function textdomain($domain) |
||
202 | |||
203 | /** |
||
204 | * Sets a requested locale. |
||
205 | * |
||
206 | * @param string $locale Locale name |
||
207 | * |
||
208 | * @return string Set or current locale |
||
209 | */ |
||
210 | public function setlocale($locale) |
||
222 | |||
223 | /** |
||
224 | * Detects currently configured locale. |
||
225 | * |
||
226 | * It checks: |
||
227 | * |
||
228 | * - global lang variable |
||
229 | * - environment for LC_ALL, LC_MESSAGES and LANG |
||
230 | * |
||
231 | * @return string with locale name |
||
232 | */ |
||
233 | public function detectlocale() |
||
247 | } |
||
248 |