Conditions | 20 |
Paths | 540 |
Total Lines | 61 |
Lines | 10 |
Ratio | 16.39 % |
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 |
||
24 | public function __construct($name, $title, $excludeLocales = array(), |
||
25 | $translatingClass = 'SiteTree', $list = 'Common-English', $instance = null |
||
26 | ) { |
||
27 | $usedLocalesWithTitle = Translatable::get_existing_content_languages($translatingClass); |
||
28 | $usedLocalesWithTitle = array_diff_key($usedLocalesWithTitle, $excludeLocales); |
||
29 | |||
30 | if ('Common-English' == $list) { |
||
31 | $allLocalesWithTitle = i18n::get_common_languages(); |
||
32 | } elseif ('Common-Native' == $list) { |
||
33 | $allLocalesWithTitle = i18n::get_common_languages(true); |
||
34 | } elseif ('Locale-English' == $list) { |
||
35 | $allLocalesWithTitle = i18n::get_common_locales(); |
||
36 | } elseif ('Locale-Native' == $list) { |
||
37 | $allLocalesWithTitle = i18n::get_common_locales(true); |
||
38 | } else { |
||
39 | $allLocalesWithTitle = i18n::config()->all_locales; |
||
40 | } |
||
41 | |||
42 | if (isset($allLocales[Translatable::default_locale()])) { |
||
|
|||
43 | unset($allLocales[Translatable::default_locale()]); |
||
44 | } |
||
45 | |||
46 | // Limit to allowed locales if defined |
||
47 | // Check for canTranslate() if an $instance is given |
||
48 | $allowedLocales = Translatable::get_allowed_locales(); |
||
49 | foreach ($allLocalesWithTitle as $locale => $localeTitle) { |
||
50 | if ( |
||
51 | ($allowedLocales && !in_array($locale, $allowedLocales)) |
||
52 | || ($excludeLocales && in_array($locale, $excludeLocales)) |
||
53 | || ($usedLocalesWithTitle && array_key_exists($locale, $usedLocalesWithTitle)) |
||
54 | ) { |
||
55 | unset($allLocalesWithTitle[$locale]); |
||
56 | } |
||
57 | } |
||
58 | // instance specific permissions |
||
59 | View Code Duplication | foreach ($allLocalesWithTitle as $locale => $localeTitle) { |
|
60 | if ($instance && !$instance->canTranslate(null, $locale)) { |
||
61 | unset($allLocalesWithTitle[$locale]); |
||
62 | } |
||
63 | } |
||
64 | View Code Duplication | foreach ($usedLocalesWithTitle as $locale => $localeTitle) { |
|
65 | if ($instance && !$instance->canTranslate(null, $locale)) { |
||
66 | unset($usedLocalesWithTitle[$locale]); |
||
67 | } |
||
68 | } |
||
69 | |||
70 | // Sort by title (array value) |
||
71 | asort($allLocalesWithTitle); |
||
72 | |||
73 | if (count($usedLocalesWithTitle)) { |
||
74 | asort($usedLocalesWithTitle); |
||
75 | $source = array( |
||
76 | _t('Form.LANGAVAIL', "Available languages") => $usedLocalesWithTitle, |
||
77 | _t('Form.LANGAOTHER', "Other languages") => $allLocalesWithTitle |
||
78 | ); |
||
79 | } else { |
||
80 | $source = $allLocalesWithTitle; |
||
81 | } |
||
82 | |||
83 | parent::__construct($name, $title, $source); |
||
84 | } |
||
85 | |||
121 |
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.