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