| Conditions | 11 |
| Paths | 9 |
| Total Lines | 31 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 78 | function set($settings, $persistent=false) |
||
| 79 | { |
||
| 80 | if (isset($settings)) { |
||
| 81 | // we will set the settings but wait with saving until the entire batch has been applied. |
||
| 82 | if (is_array($settings)) { |
||
| 83 | foreach ($settings as $setting) { |
||
| 84 | if (isset($setting['path']) && isset($setting['value'])) { |
||
| 85 | if ( !!$persistent ){ |
||
| 86 | $GLOBALS['settings']->setPersistent($setting['path'], $setting['value']); |
||
| 87 | } else { |
||
| 88 | $GLOBALS['settings']->set($setting['path'], $setting['value']); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } |
||
| 92 | } else if (isset($settings['path']) && isset($settings['value'])) { |
||
| 93 | if ( !!$persistent ){ |
||
| 94 | $GLOBALS['settings']->setPersistent($settings['path'], $settings['value']); |
||
| 95 | } else { |
||
| 96 | $GLOBALS['settings']->set($settings['path'], $settings['value']); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | // Finally save the settings, this can throw exception when it fails saving settings |
||
| 101 | if ( !!$persistent ){ |
||
| 102 | $GLOBALS['settings']->savePersistentSettings(); |
||
| 103 | } else { |
||
| 104 | $GLOBALS['settings']->saveSettings(); |
||
| 105 | } |
||
| 106 | |||
| 107 | // send success notification to client |
||
| 108 | $this->sendFeedback(true); |
||
| 109 | } |
||
| 138 |