Conditions | 17 |
Paths | 14 |
Total Lines | 34 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Tests | 4 |
CRAP Score | 179.9279 |
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 |
||
27 | 1 | protected function typecast($value) |
|
28 | { |
||
29 | |||
30 | 1 | if ($value === '' && $this->type !== Schema::TYPE_TEXT && $this->type !== Schema::TYPE_STRING && $this->type !== Schema::TYPE_BINARY) { |
|
31 | return null; |
||
32 | } |
||
33 | 1 | if ($value === null || gettype($value) === $this->phpType || $value instanceof Expression) { |
|
34 | 1 | return $value; |
|
35 | } |
||
36 | |||
37 | switch ($this->phpType) { |
||
38 | case 'resource': |
||
39 | case 'string': |
||
40 | if (is_resource($value)) { |
||
41 | return $value; |
||
42 | } |
||
43 | if (is_float($value)) { |
||
44 | // ensure type cast always has . as decimal separator in all locales |
||
45 | return str_replace(',', '.', (string) $value); |
||
46 | } |
||
47 | return (string) $value; |
||
48 | case 'integer': |
||
49 | if (is_bool($value)) { |
||
50 | return ($value) ? 1 : 0; |
||
51 | } |
||
52 | return (int) $value; |
||
53 | case 'boolean': |
||
54 | return (boolean) $value; |
||
55 | case 'double': |
||
56 | return (double) $value; |
||
57 | } |
||
58 | |||
59 | return $value; |
||
60 | } |
||
61 | } |
||
62 |