Conditions | 17 |
Paths | 216 |
Total Lines | 59 |
Code Lines | 36 |
Lines | 10 |
Ratio | 16.95 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
34 | public function __construct( |
||
35 | $name, |
||
36 | $title, |
||
37 | $excludeLocales = array(), |
||
38 | $translatingClass = SiteTree::class, |
||
39 | $list = 'Common-English', |
||
40 | $instance = null |
||
41 | ) { |
||
42 | $usedLocalesWithTitle = Translatable::get_existing_content_languages($translatingClass); |
||
43 | $usedLocalesWithTitle = array_diff_key($usedLocalesWithTitle, $excludeLocales); |
||
44 | |||
45 | if ('Common-English' == $list) { |
||
46 | $allLocalesWithTitle = i18n::getData()->getLanguages(); |
||
47 | } else { |
||
48 | $allLocalesWithTitle = i18n::getData()->getLocales(); |
||
49 | } |
||
50 | |||
51 | if (isset($allLocales[Translatable::default_locale()])) { |
||
52 | unset($allLocales[Translatable::default_locale()]); |
||
53 | } |
||
54 | |||
55 | // Limit to allowed locales if defined |
||
56 | // Check for canTranslate() if an $instance is given |
||
57 | $allowedLocales = Translatable::get_allowed_locales(); |
||
58 | foreach ($allLocalesWithTitle as $locale => $localeTitle) { |
||
59 | if (($allowedLocales && !in_array($locale, $allowedLocales)) |
||
60 | || ($excludeLocales && in_array($locale, $excludeLocales)) |
||
61 | || ($usedLocalesWithTitle && array_key_exists($locale, $usedLocalesWithTitle)) |
||
62 | ) { |
||
63 | unset($allLocalesWithTitle[$locale]); |
||
64 | } |
||
65 | } |
||
66 | // instance specific permissions |
||
67 | View Code Duplication | foreach ($allLocalesWithTitle as $locale => $localeTitle) { |
|
68 | if ($instance && !$instance->canTranslate(null, $locale)) { |
||
69 | unset($allLocalesWithTitle[$locale]); |
||
70 | } |
||
71 | } |
||
72 | View Code Duplication | foreach ($usedLocalesWithTitle as $locale => $localeTitle) { |
|
73 | if ($instance && !$instance->canTranslate(null, $locale)) { |
||
74 | unset($usedLocalesWithTitle[$locale]); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | // Sort by title (array value) |
||
79 | asort($allLocalesWithTitle); |
||
80 | |||
81 | if (count($usedLocalesWithTitle)) { |
||
82 | asort($usedLocalesWithTitle); |
||
83 | $source = array( |
||
84 | _t('Form.LANGAVAIL', "Available languages") => $usedLocalesWithTitle, |
||
85 | _t('Form.LANGAOTHER', "Other languages") => $allLocalesWithTitle |
||
86 | ); |
||
87 | } else { |
||
88 | $source = $allLocalesWithTitle; |
||
89 | } |
||
90 | |||
91 | parent::__construct($name, $title, $source); |
||
92 | } |
||
93 | |||
129 |