Conditions | 12 |
Paths | 48 |
Total Lines | 23 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
18 | public function valid() |
||
19 | { |
||
20 | $result = false; |
||
21 | |||
22 | $max_upload = ini_get('post_max_size'); |
||
23 | $unit = strtoupper(substr($max_upload, -1)); |
||
24 | $multiplier = ($unit == 'M') ? 1048576 : (($unit == 'K') ? 1024 : (($unit == 'G') ? 1073741824 : 1)); |
||
25 | |||
26 | if ($max_upload && ((int) $_SERVER['CONTENT_LENGTH'] > $multiplier * (int) $max_upload)) { |
||
27 | return self::ERROR_MAX_POST_SIZE; |
||
28 | } |
||
29 | |||
30 | if (!$this->getPath()) { |
||
31 | return false; |
||
32 | } elseif (isset($this->error) && $this->error != 0) { |
||
33 | return false; |
||
34 | } elseif (!isset($this->_tmp_name) || !@is_uploaded_file($this->_tmp_name)) { |
||
35 | return false; |
||
36 | } elseif (!isset($this->_name)) { |
||
37 | return false; |
||
38 | } |
||
39 | |||
40 | return true; |
||
41 | } |
||
48 |