Conditions | 9 |
Paths | 2 |
Total Lines | 77 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Tests | 51 |
CRAP Score | 9.0005 |
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 |
||
47 | 10 | ->_bindTextDomain() |
|
48 | ->_textDomain() |
||
49 | ->_setLocale() |
||
50 | 10 | ->_putEnv() |
|
51 | 10 | ->_checkLocaleFile() |
|
52 | 10 | ; |
|
53 | 10 | } |
|
54 | |||
55 | 10 | /** |
|
56 | 10 | * Load a domain |
|
57 | * @param string $domain |
||
58 | 10 | */ |
|
59 | 10 | public function changeDomain($domain) |
|
60 | { |
||
61 | log_message('info', 'Gettext Library Class -> Change domain'); |
||
62 | 10 | ||
63 | 10 | $this->_textDomain = $domain; |
|
64 | 10 | ||
65 | 10 | $this |
|
66 | ->_bindTextDomainCodeSet() |
||
67 | 10 | ->_bindTextDomain() |
|
68 | 10 | ->_textDomain() |
|
69 | ->_checkLocaleFile() |
||
70 | 10 | ; |
|
71 | 10 | } |
|
72 | |||
73 | /** |
||
74 | 10 | * Merge config as parameter and default config (config/gettext.php file) |
|
75 | 10 | * @param array $config |
|
76 | 10 | */ |
|
77 | private function _setConfig(array $config = array()) |
||
78 | 10 | { |
|
79 | 10 | $this->_localeDir = isset($config['gettext_locale_dir']) |
|
80 | ? $config['gettext_locale_dir'] : config_item('gettext_locale_dir'); |
||
81 | 10 | ||
82 | 10 | $this->_textDomain = isset($config['gettext_text_domain']) |
|
83 | ? $config['gettext_text_domain'] : config_item('gettext_text_domain'); |
||
84 | |||
85 | 10 | $this->_catalogCodeSet = isset($config['gettext_catalog_codeset']) |
|
86 | 10 | ? $config['gettext_catalog_codeset'] : config_item('gettext_catalog_codeset'); |
|
87 | 10 | ||
88 | 10 | $this->_locale = isset($config['gettext_locale']) |
|
89 | ? $config['gettext_locale'] : config_item('gettext_locale'); |
||
90 | 10 | ||
91 | 10 | $this->_category = LC_ALL; |
|
92 | } |
||
93 | 10 | ||
94 | 10 | /** |
|
95 | * Gettext catalog codeset |
||
96 | 10 | * @return $this |
|
97 | */ |
||
98 | private function _bindTextDomainCodeSet() |
||
99 | 10 | { |
|
100 | 10 | $isBindTextDomainCodeSet = bind_textdomain_codeset($this->_textDomain, $this->_catalogCodeSet); |
|
101 | 10 | ||
102 | 10 | log_message( |
|
103 | 10 | (is_string($isBindTextDomainCodeSet) ? 'info' : 'error'), |
|
104 | 'Gettext Library -> Bind ' . |
||
105 | 10 | 'text domain: ' . $this->_textDomain . ' - ' . |
|
106 | 10 | 'with code set: ' . $this->_catalogCodeSet |
|
107 | ); |
||
108 | 10 | ||
109 | return $this; |
||
110 | } |
||
111 | 10 | ||
112 | 10 | /** |
|
113 | 10 | * Path to gettext locales directory relative to APPPATH |
|
114 | 10 | * @return $this |
|
115 | 10 | */ |
|
116 | 10 | View Code Duplication | private function _bindTextDomain() |
1 ignored issue
–
show
|
|||
117 | { |
||
118 | 10 | $isBindTextDomain = bindtextdomain($this->_textDomain, APPPATH . $this->_localeDir); |
|
119 | 10 | ||
120 | log_message( |
||
121 | (is_string($isBindTextDomain) ? 'info' : 'error'), |
||
122 | 10 | 'Gettext Library -> Bind ' . |
|
123 | 10 | 'text domain: ' . $this->_textDomain . ' - ' . |
|
124 | 'with directory: ' . APPPATH . $this->_localeDir |
||
201 | /* Location: ./libraries/gettext.php */ |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.