Conditions | 14 |
Paths | 13 |
Total Lines | 36 |
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 |
||
92 | public function convertToModel($key, $value) |
||
93 | { |
||
94 | $bypassTypes = ['string']; |
||
95 | if ((isset($this->attributesDefinitions[$key]) === true) |
||
96 | && (in_array($this->attributesDefinitions[$key], $bypassTypes) === false) |
||
97 | ) { |
||
98 | switch ($this->attributesDefinitions[$key]) { |
||
99 | case 'bool': |
||
100 | case 'boolean': |
||
101 | $value = (bool) $value; |
||
102 | break; |
||
103 | case 'int': |
||
104 | case 'integer': |
||
105 | $value = (int) $value; |
||
106 | break; |
||
107 | case 'array': |
||
108 | if (is_array($value) === false) { |
||
109 | try { |
||
110 | $value = Json::decode($value); |
||
111 | } catch (InvalidArgumentException $e) { |
||
112 | $value = []; |
||
113 | } |
||
114 | } |
||
115 | break; |
||
116 | case 'date': |
||
117 | $value = strtotime($value); |
||
118 | break; |
||
119 | case 'real': |
||
120 | case 'double': |
||
121 | case 'float': |
||
122 | $value = (float) $value; |
||
123 | break; |
||
124 | } |
||
125 | } |
||
126 | return $value; |
||
127 | } |
||
128 | } |
||
129 |