| Conditions | 42 |
| Paths | 769 |
| Total Lines | 105 |
| Code Lines | 57 |
| Lines | 16 |
| Ratio | 15.24 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 141 | public function initialize() { |
||
| 142 | // Checking module status - is it installed and active |
||
| 143 | $this->check_status(); |
||
| 144 | if(!$this->manifest['active']) { |
||
| 145 | return; |
||
| 146 | } |
||
| 147 | |||
| 148 | // Setting constants - if any |
||
| 149 | if(isset($this->manifest['constants']) && is_array($this->manifest['constants']) && !empty($this->manifest['constants'])) { |
||
| 150 | foreach($this->manifest['constants'] as $constant_name => $constant_value) { |
||
| 151 | defined($constant_name) or define($constant_name, $constant_value); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | // Adding vars - if any |
||
| 156 | // Due to possible introduce of new constants in previous step vars is assigned via special method to honor new constants |
||
| 157 | // Assignation can work with simple variables and with multidimensional arrays - for ex. 'sn_data[groups][test]' |
||
| 158 | // New values from module variables will overwrite previous values (for root variables) and array elements with corresponding indexes (for arrays) |
||
| 159 | // Constants as array indexes are honored - it's make valid such declarations as 'sn_data[ques][QUE_STRUCTURES]' |
||
| 160 | $this->manifest['vars'] = $this->__assign_vars(); |
||
| 161 | if(!empty($this->manifest['vars'])) { |
||
| 162 | $vars_assigned = array(); |
||
| 163 | foreach($this->manifest['vars'] as $var_name => $var_value) { |
||
| 164 | $sub_vars = explode('[', str_replace(']', '', $var_name)); |
||
| 165 | $var_name = $sub_vars[0]; |
||
| 166 | |||
| 167 | if(!isset($vars_assigned[$var_name])) { |
||
| 168 | $vars_assigned[$var_name] = true; |
||
| 169 | global $$var_name; |
||
| 170 | } |
||
| 171 | |||
| 172 | $pointer = &$$var_name; |
||
| 173 | if(($n = count($sub_vars)) > 1) { |
||
| 174 | for($i = 1; $i < $n; $i++) { |
||
| 175 | if(defined($sub_vars[$i])) { |
||
| 176 | $sub_vars[$i] = constant($sub_vars[$i]); |
||
| 177 | } |
||
| 178 | |||
| 179 | if(!isset($pointer[$sub_vars[$i]]) && $i != $n) { |
||
| 180 | $pointer[$sub_vars[$i]] = array(); |
||
| 181 | } |
||
| 182 | $pointer = &$pointer[$sub_vars[$i]]; |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | if(!isset($pointer) || !is_array($pointer)) { |
||
| 187 | $pointer = $var_value; |
||
| 188 | } elseif(is_array($$var_name)) { |
||
| 189 | $pointer = array_merge_recursive_numeric($pointer, $var_value); |
||
| 190 | } |
||
| 191 | } |
||
| 192 | } |
||
| 193 | |||
| 194 | // Overriding function if any |
||
| 195 | global $functions; |
||
| 196 | sn_sys_handler_add($functions, $this->manifest['functions'], $this); |
||
| 197 | |||
| 198 | // Patching game menu - if any |
||
| 199 | global $sn_menu_extra, $sn_menu_admin_extra; |
||
| 200 | isset($this->manifest['menu']) and $this->__patch_menu($sn_menu_extra, $this->manifest['menu']); |
||
| 201 | isset($this->manifest['menu_admin']) and $this->__patch_menu($sn_menu_admin_extra, $this->manifest['menu_admin']); |
||
| 202 | |||
| 203 | global $sn_mvc; |
||
| 204 | foreach($sn_mvc as $handler_type => &$handler_data) { |
||
| 205 | sn_sys_handler_add($handler_data, $this->manifest['mvc'][$handler_type], $this, $handler_type); |
||
| 206 | } |
||
| 207 | |||
| 208 | if(isset($this->manifest['i18n']) && is_array($this->manifest['i18n']) && !empty($this->manifest['i18n'])) { |
||
| 209 | foreach($this->manifest['i18n'] as $i18n_page_name => &$i18n_file_list) { |
||
| 210 | foreach($i18n_file_list as &$i18n_file_data) { |
||
| 211 | if(is_array($i18n_file_data) && !$i18n_file_data['path']) { |
||
| 212 | $i18n_file_data['path'] = $this->manifest['root_relative']; |
||
| 213 | } |
||
| 214 | } |
||
| 215 | if(!isset($sn_mvc['i18n'][$i18n_page_name])) { |
||
| 216 | $sn_mvc['i18n'][$i18n_page_name] = array(); |
||
| 217 | } |
||
| 218 | $sn_mvc['i18n'][$i18n_page_name] += $i18n_file_list; |
||
| 219 | } |
||
| 220 | } |
||
| 221 | |||
| 222 | View Code Duplication | if(!empty($this->manifest['javascript']) && is_array($this->manifest['javascript'])) { |
|
| 223 | foreach($this->manifest['javascript'] as $javascript_page_name => &$javascript_list) { |
||
| 224 | !isset($sn_mvc['javascript'][$javascript_page_name]) ? $sn_mvc['javascript'][$javascript_page_name] = array() : false; |
||
| 225 | foreach($javascript_list as $script_name => &$script_content) { |
||
| 226 | $sn_mvc['javascript'][$javascript_page_name][$script_name] = $script_content; |
||
| 227 | } |
||
| 228 | } |
||
| 229 | } |
||
| 230 | |||
| 231 | View Code Duplication | if(!empty($this->manifest['css']) && is_array($this->manifest['css'])) { |
|
| 232 | foreach($this->manifest['css'] as $javascript_page_name => &$javascript_list) { |
||
| 233 | !isset($sn_mvc['css'][$javascript_page_name]) ? $sn_mvc['css'][$javascript_page_name] = array() : false; |
||
| 234 | foreach($javascript_list as $script_name => &$script_content) { |
||
| 235 | $sn_mvc['css'][$javascript_page_name][$script_name] = $script_content; |
||
| 236 | } |
||
| 237 | } |
||
| 238 | } |
||
| 239 | |||
| 240 | if(!empty($this->manifest['navbar_prefix_button']) && is_array($this->manifest['navbar_prefix_button'])) { |
||
| 241 | foreach($this->manifest['navbar_prefix_button'] as $button_image => $button_url_relative) { |
||
| 242 | $sn_mvc['navbar_prefix_button'][$button_image] = $button_url_relative; |
||
| 243 | } |
||
| 244 | } |
||
| 245 | } |
||
| 246 | |||
| 251 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.