| Conditions | 14 |
| Paths | 14 |
| Total Lines | 32 |
| 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 |
||
| 53 | public function convertToDatabase($key, $value) |
||
| 54 | { |
||
| 55 | $bypassTypes = ['string']; |
||
| 56 | if ((isset($this->attributesDefinitions[$key]) === true) |
||
| 57 | && (in_array($this->attributesDefinitions[$key], $bypassTypes) === false) |
||
| 58 | ) { |
||
| 59 | switch($this->attributesDefinitions[$key]) { |
||
| 60 | case 'bool': |
||
| 61 | case 'boolean': |
||
| 62 | $value = $value ? 1 : 0; |
||
| 63 | break; |
||
| 64 | case 'int': |
||
| 65 | case 'integer': |
||
| 66 | break; |
||
| 67 | case 'array': |
||
| 68 | if (is_array($value) === false) { |
||
| 69 | $value = []; |
||
| 70 | } |
||
| 71 | $value = Json::encode($value); |
||
| 72 | break; |
||
| 73 | case 'date': |
||
| 74 | $value = date('Y-m-d H:i:s', (int)$value); |
||
| 75 | break; |
||
| 76 | case 'real': |
||
| 77 | case 'double': |
||
| 78 | case 'float': |
||
| 79 | break; |
||
| 80 | } |
||
| 81 | |||
| 82 | } |
||
| 83 | return $value; |
||
| 84 | } |
||
| 85 | |||
| 129 |