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 |
||
167 | protected function stdEncodeValue($param): array { |
||
168 | $unsigned = false; |
||
169 | |||
170 | switch(\gettype($param)) { |
||
171 | case 'boolean': |
||
1 ignored issue
–
show
|
|||
172 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_TINY; |
||
173 | $value = ($param ? "\x01" : "\0"); |
||
174 | break; |
||
1 ignored issue
–
show
|
|||
175 | case 'integer': |
||
1 ignored issue
–
show
|
|||
176 | if($param >= 0) { |
||
1 ignored issue
–
show
|
|||
177 | $unsigned = true; |
||
178 | } |
||
179 | |||
180 | // TODO: Check if short, long or long long |
||
181 | if($param >= 0 && $param < (1 << 15)) { |
||
182 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_SHORT; |
||
183 | $value = \Plasma\BinaryBuffer::writeInt2($param); |
||
184 | } elseif(\PHP_INT_SIZE === 4) { |
||
1 ignored issue
–
show
|
|||
185 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONG; |
||
186 | $value = \Plasma\BinaryBuffer::writeInt4($param); |
||
187 | } else { |
||
1 ignored issue
–
show
|
|||
188 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONGLONG; |
||
189 | $value = \Plasma\BinaryBuffer::writeInt8($param); |
||
190 | } |
||
1 ignored issue
–
show
|
|||
191 | break; |
||
1 ignored issue
–
show
|
|||
192 | case 'double': |
||
1 ignored issue
–
show
|
|||
193 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_DOUBLE; |
||
194 | $value = \Plasma\BinaryBuffer::writeFloat($param); |
||
195 | break; |
||
1 ignored issue
–
show
|
|||
196 | case 'string': |
||
1 ignored issue
–
show
|
|||
197 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONG_BLOB; |
||
198 | |||
199 | $value = \Plasma\BinaryBuffer::writeInt4(\strlen($param)); |
||
200 | $value .= $param; |
||
201 | break; |
||
202 | case 'NULL': |
||
1 ignored issue
–
show
|
|||
203 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_NULL; |
||
204 | $value = ''; |
||
205 | break; |
||
1 ignored issue
–
show
|
|||
206 | default: |
||
1 ignored issue
–
show
|
|||
207 | throw new \Plasma\Exception('Unexpected type for binding parameter: '.\gettype($param)); |
||
208 | break; |
||
209 | } |
||
210 | |||
211 | return array($unsigned, $type, $value); |
||
212 | } |
||
382 |