Conditions | 12 |
Paths | 48 |
Total Lines | 27 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 156 |
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 |
||
19 | public function valid() |
||
20 | { |
||
21 | $result = false; |
||
22 | |||
23 | $max_upload = ini_get("post_max_size"); |
||
24 | $unit = strtoupper(substr($max_upload, -1)); |
||
25 | $multiplier = ($unit == 'M') ? 1048576 : (($unit == 'K') ? 1024 : (($unit == 'G') ? 1073741824 : 1)); |
||
26 | |||
27 | if ($max_upload && ((int) $_SERVER['CONTENT_LENGTH'] > $multiplier * (int) $max_upload)) { |
||
28 | return self::ERROR_MAX_POST_SIZE; |
||
29 | } |
||
30 | |||
31 | if (!$this->getPath()) { |
||
32 | return false; |
||
33 | |||
34 | } else if (isset($this->error) && $this->error != 0) { |
||
35 | return false; |
||
36 | |||
37 | } else if (!isset($this->_tmp_name) || !@is_uploaded_file($this->_tmp_name)) { |
||
38 | return false; |
||
39 | |||
40 | } else if (!isset($this->_name)) { |
||
41 | return false; |
||
42 | } |
||
43 | |||
44 | return true; |
||
45 | } |
||
46 | |||
52 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.