| Conditions | 18 |
| Paths | 12 |
| Total Lines | 40 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 48 | static function save () { |
||
| 49 | $Index = Index::instance(); |
||
| 50 | $Config = Config::instance(); |
||
| 51 | if (isset($_POST['apply']) || isset($_POST['save'])) { |
||
| 52 | foreach (['core', 'db', 'storage', 'components'] as $part) { |
||
| 53 | if (isset($_POST[$part])) { |
||
| 54 | $temp = &$Config->$part; |
||
| 55 | foreach ($_POST[$part] as $item => $value) { |
||
| 56 | switch ($item) { |
||
| 57 | case 'ip_black_list': |
||
| 58 | case 'ip_admin_list': |
||
| 59 | $value = _trim(explode("\n", $value)); |
||
| 60 | if ($value[0] == '') { |
||
| 61 | $value = []; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | $temp[$item] = xap($value, true); |
||
| 65 | } |
||
| 66 | unset($item, $value); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | unset($part); |
||
| 70 | } |
||
| 71 | $Cache = Cache::instance(); |
||
| 72 | if (isset($_POST['apply']) && $Cache->cache_state()) { |
||
| 73 | /** @noinspection NotOptimalIfConditionsInspection */ |
||
| 74 | if ($Index->apply() && !$Config->core['cache_compress_js_css']) { |
||
| 75 | clean_pcache(); |
||
| 76 | Event::instance()->fire('admin/System/general/optimization/clean_pcache'); |
||
| 77 | } |
||
| 78 | } elseif (isset($_POST['save'])) { |
||
| 79 | $save = $Index->save(); |
||
| 80 | if ($save && !$Config->core['cache_compress_js_css']) { |
||
| 81 | clean_pcache(); |
||
| 82 | Event::instance()->fire('admin/System/general/optimization/clean_pcache'); |
||
| 83 | } |
||
| 84 | } /** @noinspection NotOptimalIfConditionsInspection */ elseif (isset($_POST['cancel']) && $Cache->cache_state()) { |
||
| 85 | $Index->cancel(); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 |