| Conditions | 9 |
| Paths | 13 |
| Total Lines | 51 |
| Code Lines | 29 |
| 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 |
||
| 145 | public function archiveSingle($file, $desination = false) |
||
| 146 | { |
||
| 147 | if ($file == '') { |
||
| 148 | throw new CompressException('__exception_compress_file_value_empty'); |
||
| 149 | } |
||
| 150 | |||
| 151 | if (! file_exists($file)) { |
||
| 152 | throw new CompressException('__exception_compress_file_not_exist'); |
||
| 153 | } |
||
| 154 | |||
| 155 | if (! is_readable($file)) { |
||
| 156 | throw new CompressException('__exception_compress_file_not_readable'); |
||
| 157 | } |
||
| 158 | |||
| 159 | // work out path stuff |
||
| 160 | $old_cwd = getcwd(); |
||
| 161 | $path = dirname($file); |
||
| 162 | chdir($path); |
||
| 163 | |||
| 164 | $name = $this->getArchiveName(); |
||
| 165 | $zip = $this->getArchiver(); |
||
| 166 | $zip->open($name, \ZipArchive::CREATE); |
||
| 167 | if (file_exists($file)) { |
||
| 168 | $zip->addFile(basename($file)); |
||
| 169 | } |
||
| 170 | |||
| 171 | if ($zip->status != '0') { |
||
| 172 | throw new CompressException('__exception_compression'); |
||
| 173 | } |
||
| 174 | |||
| 175 | $zip->close(); |
||
| 176 | |||
| 177 | if (! $this->getKeepOriginal() && file_exists($file)) { |
||
| 178 | unlink($file); |
||
| 179 | } |
||
| 180 | |||
| 181 | if ($desination) { |
||
|
|
|||
| 182 | $desination = realpath($desination) . DIRECTORY_SEPARATOR . $name; |
||
| 183 | copy($name, $desination); |
||
| 184 | unlink($name); |
||
| 185 | |||
| 186 | $name = $desination; |
||
| 187 | } else { |
||
| 188 | $name = $path . DIRECTORY_SEPARATOR . $name; |
||
| 189 | } |
||
| 190 | |||
| 191 | // reset path |
||
| 192 | chdir($old_cwd); |
||
| 193 | |||
| 194 | return $name; |
||
| 195 | } |
||
| 196 | |||
| 218 | } |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: