Conditions | 16 |
Paths | 15 |
Total Lines | 66 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Tests | 48 |
CRAP Score | 16.052 |
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 |
||
74 | 35 | static function decode(\Plasma\ColumnDefinitionInterface $column, \Plasma\BinaryBuffer $buffer) { |
|
75 | 35 | $flags = $column->getFlags(); |
|
76 | 35 | $type = $column->getType(); |
|
77 | |||
78 | switch(true) { |
||
79 | 35 | case static::isTypeString($type): |
|
80 | 18 | $value = $buffer->readStringLength(); |
|
81 | 18 | break; |
|
82 | 17 | case ($type === 'TINY'): |
|
83 | 7 | $value = $buffer->readInt1(); |
|
84 | 7 | $value = static::zeroFillInts($column, $value); |
|
85 | 7 | break; |
|
86 | 17 | case static::isTypeShortOrYear($type): |
|
87 | 7 | $value = $buffer->readInt2(); |
|
88 | 7 | $value = static::zeroFillInts($column, $value); |
|
89 | 7 | break; |
|
90 | 17 | case static::isTypeInt24orLong($type): |
|
91 | 7 | $value = $buffer->readInt4(); |
|
92 | |||
93 | 7 | if($column->isUnsigned() && \PHP_INT_SIZE <= 4) { |
|
1 ignored issue
–
show
|
|||
94 | $value = \bcadd($value, '18446744073709551616'); |
||
95 | } |
||
96 | |||
97 | 7 | $value = static::zeroFillInts($column, $value); |
|
98 | 7 | break; |
|
99 | 17 | case ($type === 'LONGLONG'): |
|
100 | 7 | $value = $buffer->readInt8(); |
|
101 | |||
102 | 7 | if($column->isUnsigned()) { |
|
1 ignored issue
–
show
|
|||
103 | $value = \bcadd($value, '18446744073709551616'); |
||
104 | 7 | } elseif(\PHP_INT_SIZE > 4) { |
|
105 | 7 | $value = (int) $value; |
|
106 | } |
||
107 | |||
108 | 7 | $value = static::zeroFillInts($column, $value); |
|
109 | 7 | break; |
|
110 | 10 | case ($type === 'FLOAT'): |
|
111 | 2 | $value = $buffer->readFloat(); |
|
112 | 2 | break; |
|
113 | 10 | case ($type === 'DOUBLE'): |
|
114 | 2 | $value = $buffer->readDouble(); |
|
115 | 2 | break; |
|
116 | 8 | case static::isTypeDate($type): |
|
117 | 8 | $length = $buffer->readIntLength(); |
|
118 | 8 | if($length > 0) { |
|
119 | 1 | $year = $buffer->readInt2(); |
|
120 | 1 | $month = $buffer->readInt1(); |
|
121 | 1 | $day = $buffer->readInt1(); |
|
122 | |||
123 | 1 | $value = \sprintf('%04d-%02d-%02d', $year, $month, $day); |
|
124 | } else { |
||
125 | 7 | $value = '0000-00-00'; |
|
126 | } |
||
127 | 8 | break; |
|
128 | 8 | case static::isTypeDateTime($type): |
|
129 | 8 | $value = static::parseDateTime($type, $buffer); |
|
130 | 8 | break; |
|
131 | 8 | case ($type === 'TIME'): |
|
132 | 8 | $value = static::parseTime($buffer); |
|
133 | 8 | break; |
|
134 | default: |
||
135 | throw new \InvalidArgumentException('Unknown column type (flags: '.$flags.', type: '.$type.')'); |
||
136 | break; |
||
137 | } |
||
138 | |||
139 | 35 | return $value; |
|
140 | } |
||
285 |