Complex classes like ExtraneousLanguage often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ExtraneousLanguage, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | class ExtraneousLanguage { |
||
24 | |||
25 | /** |
||
26 | * @var ExtraneousLanguage |
||
27 | */ |
||
28 | private static $instance = null; |
||
29 | |||
30 | /** |
||
31 | * @var LanguageContents |
||
32 | */ |
||
33 | private $languageContents; |
||
34 | |||
35 | /** |
||
36 | * @var boolean |
||
37 | */ |
||
38 | private $historicTypeNamespace = false; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $languageCode = 'en'; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | private $propertyIdByLabelMap = array(); |
||
49 | |||
50 | /** |
||
51 | * @var array |
||
52 | */ |
||
53 | private $dateFormatsMap = array(); |
||
54 | |||
55 | /** |
||
56 | * @var array |
||
57 | */ |
||
58 | private $monthMap = array(); |
||
|
|||
59 | |||
60 | /** |
||
61 | * @since 2.4 |
||
62 | * |
||
63 | * @param LanguageContents $languageContents |
||
64 | */ |
||
65 | public function __construct( LanguageContents $languageContents ) { |
||
68 | |||
69 | /** |
||
70 | * @since 2.4 |
||
71 | * |
||
72 | * @return ExtraneousLanguage |
||
73 | */ |
||
74 | public static function getInstance() { |
||
98 | |||
99 | /** |
||
100 | * @since 2.4 |
||
101 | */ |
||
102 | public static function clear() { |
||
105 | |||
106 | /** |
||
107 | * @since 2.5 |
||
108 | * |
||
109 | * @param boolean $historicTypeNamespace |
||
110 | */ |
||
111 | public function setHistoricTypeNamespace( $historicTypeNamespace ) { |
||
114 | |||
115 | /** |
||
116 | * @since 2.4 |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getCode() { |
||
123 | |||
124 | /** |
||
125 | * @since 2.4 |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | public function fetchByLanguageCode( $languageCode ) { |
||
139 | |||
140 | /** |
||
141 | * Function that returns an array of namespace identifiers. |
||
142 | * |
||
143 | * @since 2.4 |
||
144 | * |
||
145 | * @return array |
||
146 | */ |
||
147 | public function getNamespaces() { |
||
173 | |||
174 | /** |
||
175 | * Function that returns an array of namespace aliases, if any |
||
176 | * |
||
177 | * @since 2.4 |
||
178 | * |
||
179 | * @return array |
||
180 | */ |
||
181 | public function getNamespaceAliases() { |
||
209 | |||
210 | /** |
||
211 | * Return all labels that are available as names for built-in datatypes. Those |
||
212 | * are the types that users can access via [[has type::...]] (more built-in |
||
213 | * types may exist for internal purposes but the user won't need to |
||
214 | * know this). The returned array is indexed by (internal) type ids. |
||
215 | * |
||
216 | * @since 2.4 |
||
217 | * |
||
218 | * @return array |
||
219 | */ |
||
220 | public function getDatatypeLabels() { |
||
234 | |||
235 | /** |
||
236 | * @since 2.4 |
||
237 | * |
||
238 | * @return array |
||
239 | */ |
||
240 | public function getCanonicalDatatypeLabels() { |
||
246 | |||
247 | /** |
||
248 | * Return an array that maps aliases to internal type ids. All ids used here |
||
249 | * should also have a primary label defined in m_DatatypeLabels. |
||
250 | * |
||
251 | * @since 2.4 |
||
252 | * |
||
253 | * @return array |
||
254 | */ |
||
255 | public function getDatatypeAliases() { |
||
269 | |||
270 | /** |
||
271 | * @since 2.4 |
||
272 | * |
||
273 | * @return array |
||
274 | */ |
||
275 | public function getCanonicalPropertyLabels() { |
||
291 | |||
292 | /** |
||
293 | * Function that returns the labels for predefined properties. |
||
294 | * |
||
295 | * @since 2.4 |
||
296 | * |
||
297 | * @return array |
||
298 | */ |
||
299 | public function getPropertyLabels() { |
||
313 | |||
314 | /** |
||
315 | * Aliases for predefined properties, if any. |
||
316 | * |
||
317 | * @since 2.4 |
||
318 | * |
||
319 | * @return array |
||
320 | */ |
||
321 | public function getCanonicalPropertyAliases() { |
||
335 | |||
336 | /** |
||
337 | * Aliases for predefined properties, if any. |
||
338 | * |
||
339 | * @since 2.4 |
||
340 | * |
||
341 | * @return array |
||
342 | */ |
||
343 | public function getPropertyAliases() { |
||
357 | |||
358 | /** |
||
359 | * @deprecated use getPropertyIdByLabel |
||
360 | */ |
||
361 | protected function getPropertyId( $propertyLabel ) { |
||
375 | |||
376 | /** |
||
377 | * Function receives property name (for example, `Modificatino date') and |
||
378 | * returns a property id (for example, `_MDAT'). Property name may be |
||
379 | * localized one. If property name is not recognized, a null value returned. |
||
380 | * |
||
381 | * @since 2.4 |
||
382 | * |
||
383 | * @return string|null |
||
384 | */ |
||
385 | public function getPropertyIdByLabel( $propertyLabel ) { |
||
407 | |||
408 | /** |
||
409 | * Function that returns the preferred date formats |
||
410 | * |
||
411 | * Preferred interpretations for dates with 1, 2, and 3 components. There |
||
412 | * is an array for each case, and the constants define the obvious order |
||
413 | * (e.g. SMW_YDM means "first Year, then Day, then Month). Unlisted |
||
414 | * combinations will not be accepted at all. |
||
415 | * |
||
416 | * @since 2.4 |
||
417 | * |
||
418 | * @return array |
||
419 | */ |
||
420 | public function getDateFormats() { |
||
430 | |||
431 | /** |
||
432 | * @since 2.4 |
||
433 | * |
||
434 | * @param integer|null $precision |
||
435 | * |
||
436 | * @return string |
||
437 | */ |
||
438 | public function getPreferredDateFormatByPrecision( $precision = null ) { |
||
454 | |||
455 | /** |
||
456 | * @deprecated use findMonthNumberByLabel |
||
457 | */ |
||
458 | public function findMonth( $label ) { |
||
461 | |||
462 | /** |
||
463 | * Function looks up a month and returns the corresponding number. |
||
464 | * |
||
465 | * @since 2.4 |
||
466 | * |
||
467 | * @param string $label |
||
468 | * |
||
469 | * @return false|integer |
||
470 | */ |
||
471 | public function findMonthNumberByLabel( $label ) { |
||
487 | |||
488 | /** |
||
489 | * @deprecated use getMonthLabelByNumber |
||
490 | */ |
||
491 | public function getMonthLabel( $number ) { |
||
494 | |||
495 | /** |
||
496 | * Return the name of the month with the given number. |
||
497 | * |
||
498 | * @since 2.4 |
||
499 | * |
||
500 | * @param integer $number |
||
501 | * |
||
502 | * @return array |
||
503 | */ |
||
504 | public function getMonthLabelByNumber( $number ) { |
||
519 | |||
520 | private function getDateFormatsByLanguageCode( $languageCode ) { |
||
536 | |||
537 | } |
||
538 |
This check marks private properties in classes that are never used. Those properties can be removed.