| Conditions | 16 |
| Paths | 16 |
| Total Lines | 70 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 10 | public function decode(string $bytes) |
||
| 11 | { |
||
| 12 | $type = $this->detectType($bytes); |
||
| 13 | |||
| 14 | switch ($type) { |
||
| 15 | case Binn::BINN_NULL: |
||
| 16 | return null; |
||
| 17 | |||
| 18 | case Binn::BINN_TRUE: |
||
| 19 | return true; |
||
| 20 | |||
| 21 | case Binn::BINN_FALSE: |
||
| 22 | return false; |
||
| 23 | |||
| 24 | case Binn::BINN_FLOAT32: |
||
| 25 | return Unpacker::unpackFloat32( |
||
| 26 | substr($bytes, 1, 4) |
||
| 27 | ); |
||
| 28 | |||
| 29 | case Binn::BINN_FLOAT64: |
||
| 30 | return Unpacker::unpackFloat64( |
||
| 31 | substr($bytes, 1, 8) |
||
| 32 | ); |
||
| 33 | |||
| 34 | case Binn::BINN_INT64: |
||
| 35 | return Unpacker::unpackInt64( |
||
| 36 | substr($bytes, 1, 8) |
||
| 37 | ); |
||
| 38 | |||
| 39 | case Binn::BINN_INT32: |
||
| 40 | return Unpacker::unpackInt32( |
||
| 41 | substr($bytes, 1, 4) |
||
| 42 | ); |
||
| 43 | |||
| 44 | case Binn::BINN_INT16: |
||
| 45 | return Unpacker::unpackInt16( |
||
| 46 | substr($bytes, 1, 2) |
||
| 47 | ); |
||
| 48 | |||
| 49 | case Binn::BINN_INT8: |
||
| 50 | return Unpacker::unpackInt8( |
||
| 51 | $bytes[1] |
||
| 52 | ); |
||
| 53 | |||
| 54 | case Binn::BINN_UINT64: |
||
| 55 | return Unpacker::unpackUint64( |
||
| 56 | substr($bytes, 1, 8) |
||
| 57 | ); |
||
| 58 | |||
| 59 | case Binn::BINN_UINT32: |
||
| 60 | return Unpacker::unpackUint32( |
||
| 61 | substr($bytes, 1, 4) |
||
| 62 | ); |
||
| 63 | |||
| 64 | case Binn::BINN_UINT16: |
||
| 65 | return Unpacker::unpackUint16( |
||
| 66 | substr($bytes, 1, 2) |
||
| 67 | ); |
||
| 68 | |||
| 69 | case Binn::BINN_UINT8: |
||
| 70 | return Unpacker::unpackUint8($bytes[1]); |
||
| 71 | |||
| 72 | case Binn::BINN_STRING: |
||
| 73 | return $this->decodeString($bytes); |
||
| 74 | |||
| 75 | case Binn::BINN_STORAGE_BLOB: |
||
| 76 | return $this->decodeString($bytes); |
||
| 77 | } |
||
| 78 | |||
| 79 | return null; |
||
| 80 | } |
||
| 121 |