Conditions | 18 |
Paths | 6 |
Total Lines | 98 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
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 |
||
91 | private function decodeBitStream(BitBuffer $bitBuffer):DecoderResult{ |
||
92 | $versionNumber = $this->version->getVersionNumber(); |
||
|
|||
93 | $symbolSequence = -1; |
||
94 | $parityData = -1; |
||
95 | $eciCharset = null; |
||
96 | $fc1InEffect = false; |
||
97 | $result = ''; |
||
98 | |||
99 | // While still another segment to read... |
||
100 | while($bitBuffer->available() >= 4){ |
||
101 | $datamode = $bitBuffer->read(4); // mode is encoded by 4 bits |
||
102 | |||
103 | // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here |
||
104 | if($datamode === Mode::TERMINATOR){ |
||
105 | break; |
||
106 | } |
||
107 | elseif($datamode === Mode::ECI){ |
||
108 | $eciCharset = ECI::parseValue($bitBuffer); |
||
109 | } |
||
110 | elseif($datamode === Mode::FNC1_FIRST || $datamode === Mode::FNC1_SECOND){ |
||
111 | // We do little with FNC1 except alter the parsed result a bit according to the spec |
||
112 | $fc1InEffect = true; |
||
113 | } |
||
114 | elseif($datamode === Mode::STRCTURED_APPEND){ |
||
115 | |||
116 | if($bitBuffer->available() < 16){ |
||
117 | throw new QRCodeDecoderException('structured append: not enough bits left'); |
||
118 | } |
||
119 | // sequence number and parity is added later to the result metadata |
||
120 | // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue |
||
121 | $symbolSequence = $bitBuffer->read(8); |
||
122 | $parityData = $bitBuffer->read(8); |
||
123 | } |
||
124 | elseif($datamode === Mode::NUMBER){ |
||
125 | $result .= Number::decodeSegment($bitBuffer, $versionNumber); |
||
126 | } |
||
127 | elseif($datamode === Mode::ALPHANUM){ |
||
128 | $str = AlphaNum::decodeSegment($bitBuffer, $versionNumber); |
||
129 | |||
130 | // See section 6.4.8.1, 6.4.8.2 |
||
131 | if($fc1InEffect){ // ??? |
||
132 | // We need to massage the result a bit if in an FNC1 mode: |
||
133 | $str = str_replace(chr(0x1d), '%', $str); |
||
134 | $str = str_replace('%%', '%', $str); |
||
135 | } |
||
136 | |||
137 | $result .= $str; |
||
138 | } |
||
139 | elseif($datamode === Mode::BYTE){ |
||
140 | $str = Byte::decodeSegment($bitBuffer, $versionNumber); |
||
141 | |||
142 | if($eciCharset !== null){ |
||
143 | $encoding = $eciCharset->getName(); |
||
144 | |||
145 | if($encoding === null){ |
||
146 | // The spec isn't clear on this mode; see |
||
147 | // section 6.4.5: t does not say which encoding to assuming |
||
148 | // upon decoding. I have seen ISO-8859-1 used as well as |
||
149 | // Shift_JIS -- without anything like an ECI designator to |
||
150 | // give a hint. |
||
151 | $encoding = mb_detect_encoding($str, ['ISO-8859-1', 'Windows-1252', 'SJIS', 'UTF-8'], true); |
||
152 | |||
153 | if($encoding === false){ |
||
154 | throw new QRCodeDecoderException('could not determine encoding in ECI mode'); |
||
155 | } |
||
156 | } |
||
157 | |||
158 | $eciCharset = null; |
||
159 | $str = mb_convert_encoding($str, mb_internal_encoding(), $encoding); |
||
160 | } |
||
161 | |||
162 | $result .= $str; |
||
163 | } |
||
164 | elseif($datamode === Mode::KANJI){ |
||
165 | $result .= Kanji::decodeSegment($bitBuffer, $versionNumber); |
||
166 | } |
||
167 | elseif($datamode === Mode::HANZI){ |
||
168 | // Hanzi mode contains a subset indicator right after mode indicator |
||
169 | if($bitBuffer->read(4) !== Hanzi::GB2312_SUBSET){ |
||
170 | throw new QRCodeDecoderException('ecpected subset indicator for Hanzi mode'); |
||
171 | } |
||
172 | |||
173 | $result .= Hanzi::decodeSegment($bitBuffer, $versionNumber); |
||
174 | } |
||
175 | else{ |
||
176 | throw new QRCodeDecoderException('invalid data mode'); |
||
177 | } |
||
178 | |||
179 | } |
||
180 | |||
181 | return new DecoderResult([ |
||
182 | 'rawBytes' => $bitBuffer, |
||
183 | 'data' => $result, |
||
184 | 'version' => $this->version, |
||
185 | 'eccLevel' => $this->eccLevel, |
||
186 | 'maskPattern' => $this->maskPattern, |
||
187 | 'structuredAppendParity' => $parityData, |
||
188 | 'structuredAppendSequence' => $symbolSequence |
||
189 | ]); |
||
193 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.