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