| Conditions | 11 |
| Paths | 128 |
| Total Lines | 44 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 defined('SYSPATH') or die('No direct access allowed.'); |
||
| 25 | public static function save($file, $filename = null, $directory = null, $chmod = 0644) |
||
| 26 | { |
||
| 27 | // Load file data from FILES if not passed as array |
||
| 28 | $file = is_array($file) ? $file : $_FILES[$file]; |
||
| 29 | |||
| 30 | if ($filename === null) { |
||
| 31 | // Use the default filename, with a timestamp pre-pended |
||
| 32 | $filename = time().$file['name']; |
||
| 33 | } |
||
| 34 | |||
| 35 | if (Kohana::config('upload.remove_spaces') === true) { |
||
| 36 | // Remove spaces from the filename |
||
| 37 | $filename = preg_replace('/\s+/', '_', $filename); |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($directory === null) { |
||
| 41 | // Use the pre-configured upload directory |
||
| 42 | $directory = Kohana::config('upload.directory', true); |
||
| 43 | } |
||
| 44 | |||
| 45 | // Make sure the directory ends with a slash |
||
| 46 | $directory = rtrim($directory, '/').'/'; |
||
| 47 | |||
| 48 | if (! is_dir($directory) and Kohana::config('upload.create_directories') === true) { |
||
| 49 | // Create the upload directory |
||
| 50 | mkdir($directory, 0777, true); |
||
| 51 | } |
||
| 52 | |||
| 53 | if (! is_writable($directory)) { |
||
| 54 | throw new Kohana_Exception('upload.not_writable', $directory); |
||
| 55 | } |
||
| 56 | |||
| 57 | if (is_uploaded_file($file['tmp_name']) and move_uploaded_file($file['tmp_name'], $filename = $directory.$filename)) { |
||
| 58 | if ($chmod !== false) { |
||
| 59 | // Set permissions on filename |
||
| 60 | chmod($filename, $chmod); |
||
| 61 | } |
||
| 62 | |||
| 63 | // Return new file path |
||
| 64 | return $filename; |
||
| 65 | } |
||
| 66 | |||
| 67 | return false; |
||
| 68 | } |
||
| 69 | |||
| 156 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.