| Conditions | 11 |
| Paths | 12 |
| Total Lines | 42 |
| Code Lines | 35 |
| 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 | } |
||
|
1 ignored issue
–
show
|
|||
| 169 | |||
| 170 | if($param >= 0 && $param < (1 << 15)) { |
||
|
1 ignored issue
–
show
|
|||
| 171 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_SHORT; |
||
| 172 | $value = \Plasma\BinaryBuffer::writeInt2($param); |
||
| 173 | } elseif(\PHP_INT_SIZE === 4) { |
||
|
1 ignored issue
–
show
|
|||
| 174 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONG; |
||
| 175 | $value = \Plasma\BinaryBuffer::writeInt4($param); |
||
| 176 | } else { |
||
|
1 ignored issue
–
show
|
|||
| 177 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONGLONG; |
||
| 178 | $value = \Plasma\BinaryBuffer::writeInt8($param); |
||
| 179 | } |
||
|
1 ignored issue
–
show
|
|||
| 180 | break; |
||
|
1 ignored issue
–
show
|
|||
| 181 | case 'double': |
||
|
1 ignored issue
–
show
|
|||
| 182 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_DOUBLE; |
||
| 183 | $value = \Plasma\BinaryBuffer::writeDouble($param); |
||
| 184 | break; |
||
|
1 ignored issue
–
show
|
|||
| 185 | case 'string': |
||
|
1 ignored issue
–
show
|
|||
| 186 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_LONG_BLOB; |
||
| 187 | $value = \Plasma\BinaryBuffer::writeStringLength($param); |
||
| 188 | break; |
||
|
1 ignored issue
–
show
|
|||
| 189 | case 'NULL': |
||
|
1 ignored issue
–
show
|
|||
| 190 | $type = \Plasma\Drivers\MySQL\FieldFlags::FIELD_TYPE_NULL; |
||
| 191 | $value = ''; |
||
| 192 | break; |
||
|
1 ignored issue
–
show
|
|||
| 193 | default: |
||
|
1 ignored issue
–
show
|
|||
| 194 | throw new \Plasma\Exception('Unexpected type for binding parameter: '.\gettype($param)); |
||
| 195 | break; |
||
| 196 | } |
||
| 197 | |||
| 198 | return array($unsigned, $type, $value); |
||
| 199 | } |
||
| 370 |