Conditions | 11 |
Paths | 12 |
Total Lines | 45 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 132 |
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 |
||
157 | protected function stdEncodeValue($param): array { |
||
158 | $unsigned = false; |
||
159 | |||
160 | switch(\gettype($param)) { |
||
161 | case 'boolean': |
||
1 ignored issue
–
show
|
|||
162 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_TINY; |
||
163 | $value = ($param ? "\x01" : "\0"); |
||
164 | break; |
||
1 ignored issue
–
show
|
|||
165 | case 'integer': |
||
1 ignored issue
–
show
|
|||
166 | if($param >= 0) { |
||
1 ignored issue
–
show
|
|||
167 | $unsigned = true; |
||
168 | } |
||
169 | |||
170 | // TODO: Check if short, long or long long |
||
171 | if($param >= 0 && $param < (1 << 15)) { |
||
172 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_SHORT; |
||
173 | $value = \Plasma\Drivers\MySQL\Messages\MessageUtility::writeInt2($param); |
||
174 | } elseif(\PHP_INT_SIZE === 4) { |
||
1 ignored issue
–
show
|
|||
175 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONG; |
||
176 | $value = \Plasma\Drivers\MySQL\Messages\MessageUtility::writeInt4($param); |
||
177 | } else { |
||
1 ignored issue
–
show
|
|||
178 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONGLONG; |
||
179 | $value = \Plasma\Drivers\MySQL\Messages\MessageUtility::writeInt8($param); |
||
180 | } |
||
181 | break; |
||
182 | case 'double': |
||
1 ignored issue
–
show
|
|||
183 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_DOUBLE; |
||
184 | $value = \Plasma\Drivers\MySQL\Messages\MessageUtility::writeFloat($param); |
||
185 | break; |
||
186 | case 'string': |
||
1 ignored issue
–
show
|
|||
187 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONG_BLOB; |
||
188 | |||
189 | $value = \Plasma\Drivers\MySQL\Messages\MessageUtility::writeInt4(\strlen($param)); |
||
190 | $value .= $param; |
||
191 | break; |
||
192 | case 'NULL': |
||
1 ignored issue
–
show
|
|||
193 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_NULL; |
||
194 | $value = ''; |
||
195 | break; |
||
1 ignored issue
–
show
|
|||
196 | default: |
||
1 ignored issue
–
show
|
|||
197 | throw new \Plasma\Exception('Unexpected type for binding parameter: '.\gettype($param)); |
||
198 | break; |
||
199 | } |
||
200 | |||
201 | return array($unsigned, $type, $value); |
||
202 | } |
||
212 |