Conditions | 10 |
Paths | 8 |
Total Lines | 25 |
Code Lines | 12 |
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 |
||
46 | protected function _default(Jam_Validated $model, $value) |
||
47 | { |
||
48 | $return = FALSE; |
||
49 | |||
50 | $value = $this->run_filters($model, $value); |
||
51 | if ((is_string($value) AND is_numeric($value)) OR is_int($value) ) { |
||
52 | $value = (float) $value; |
||
53 | } |
||
54 | |||
55 | // Convert empty values to NULL, if needed |
||
56 | if ($this->convert_empty AND empty($value) AND $value !== 0 AND $value !== 0.0) |
||
57 | { |
||
58 | $value = $this->empty_value; |
||
59 | $return = TRUE; |
||
60 | } |
||
61 | |||
62 | // Allow NULL values to pass through untouched by the field |
||
63 | if ($this->allow_null AND $value === NULL) |
||
64 | { |
||
65 | $value = NULL; |
||
66 | $return = TRUE; |
||
67 | } |
||
68 | |||
69 | return array($value, $return); |
||
70 | } |
||
71 | |||
102 |
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.