| Conditions | 12 |
| Paths | 66 |
| Total Lines | 57 |
| Code Lines | 38 |
| 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 |
||
| 74 | * @param bool $backup backup current file? (remove any existing backup) |
||
| 75 | * @return bool succesful? |
||
| 76 | */ |
||
| 77 | public function save_settings($id, $header = '', $backup = true) { |
||
| 78 | global $conf; |
||
| 79 | |||
| 80 | if($this->locked) return false; |
||
| 81 | |||
| 82 | // write back to the last file in the local config cascade |
||
| 83 | $file = end($this->_local_files); |
||
| 84 | |||
| 85 | // backup current file (remove any existing backup) |
||
| 86 | if(file_exists($file) && $backup) { |
||
| 87 | if(file_exists($file . '.bak')) @unlink($file . '.bak'); |
||
|
1 ignored issue
–
show
|
|||
| 88 | if(!io_rename($file, $file . '.bak')) return false; |
||
| 89 | } |
||
| 90 | |||
| 91 | if(!$fh = @fopen($file, 'wb')) { |
||
| 92 | io_rename($file . '.bak', $file); // problem opening, restore the backup |
||
| 93 | return false; |
||
| 94 | } |
||
| 95 | |||
| 96 | if(empty($header)) $header = $this->_heading; |
||
| 97 | |||
| 98 | $out = $this->_out_header($id, $header); |
||
| 99 | |||
| 100 | foreach($this->confset->getSettings() as $setting) { |
||
| 101 | $out .= $setting->out($this->_name, $this->_format); |
||
| 102 | } |
||
| 103 | |||
| 104 | $out .= $this->_out_footer(); |
||
| 105 | |||
| 106 | @fwrite($fh, $out); |
||
|
1 ignored issue
–
show
|
|||
| 107 | fclose($fh); |
||
| 108 | if($conf['fperm']) chmod($file, $conf['fperm']); |
||
| 109 | return true; |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Update last modified time stamp of the config file |
||
| 114 | * |
||
| 115 | * @return bool |
||
| 116 | */ |
||
| 117 | public function touch_settings() { |
||
| 118 | if($this->locked) return false; |
||
| 119 | $file = end($this->_local_files); |
||
| 120 | return @touch($file); |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Returns header of rewritten settings file |
||
| 125 | * |
||
| 126 | * @param string $id plugin name of which generated this output |
||
| 127 | * @param string $header additional text for at top of the file |
||
| 128 | * @return string text of header |
||
| 129 | */ |
||
| 130 | protected function _out_header($id, $header) { |
||
| 131 | $out = ''; |
||
| 178 |
If you suppress an error, we recommend checking for the error condition explicitly: