| Conditions | 14 |
| Paths | 4 |
| Total Lines | 114 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 170 | private function decodeBitStream(array $bytes):DecoderResult{ |
||
| 171 | $bits = new BitBuffer($bytes); |
||
| 172 | $symbolSequence = -1; |
||
| 173 | $parityData = -1; |
||
| 174 | $versionNumber = $this->version->getVersionNumber(); |
||
| 175 | |||
| 176 | $result = ''; |
||
| 177 | $eciCharset = null; |
||
| 178 | # $fc1InEffect = false; |
||
| 179 | |||
| 180 | // While still another segment to read... |
||
| 181 | while($bits->available() >= 4){ |
||
| 182 | $datamode = $bits->read(4); // mode is encoded by 4 bits |
||
| 183 | |||
| 184 | // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here |
||
| 185 | if($datamode === Mode::TERMINATOR){ |
||
| 186 | break; |
||
| 187 | } |
||
| 188 | |||
| 189 | if($datamode === Mode::ECI){ |
||
| 190 | // Count doesn't apply to ECI |
||
| 191 | $eciCharset = ECI::parseValue($bits); |
||
| 192 | } |
||
| 193 | /** @noinspection PhpStatementHasEmptyBodyInspection */ |
||
| 194 | elseif($datamode === Mode::FNC1_FIRST || $datamode === Mode::FNC1_SECOND){ |
||
| 195 | // We do little with FNC1 except alter the parsed result a bit according to the spec |
||
| 196 | # $fc1InEffect = true; |
||
| 197 | } |
||
| 198 | elseif($datamode === Mode::STRCTURED_APPEND){ |
||
| 199 | if($bits->available() < 16){ |
||
| 200 | throw new QRCodeDecoderException('structured append: not enough bits left'); |
||
| 201 | } |
||
| 202 | // sequence number and parity is added later to the result metadata |
||
| 203 | // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue |
||
| 204 | $symbolSequence = $bits->read(8); |
||
| 205 | $parityData = $bits->read(8); |
||
| 206 | } |
||
| 207 | else{ |
||
| 208 | // First handle Hanzi mode which does not start with character count |
||
| 209 | /* if($datamode === Mode::DATA_HANZI){ |
||
| 210 | //chinese mode contains a sub set indicator right after mode indicator |
||
| 211 | $subset = $bits->read(4); |
||
| 212 | $length = $bits->read(Mode::getLengthBitsForVersion($datamode, $versionNumber)); |
||
| 213 | if($subset === self::GB2312_SUBSET){ |
||
| 214 | $result .= $this->decodeHanziSegment($bits, $length); |
||
| 215 | } |
||
| 216 | }*/ |
||
| 217 | # else{ |
||
| 218 | // "Normal" QR code modes: |
||
| 219 | if($datamode === Mode::NUMBER){ |
||
| 220 | $result .= Number::decodeSegment($bits, $versionNumber); |
||
| 221 | } |
||
| 222 | elseif($datamode === Mode::ALPHANUM){ |
||
| 223 | $str = AlphaNum::decodeSegment($bits, $versionNumber); |
||
| 224 | |||
| 225 | // See section 6.4.8.1, 6.4.8.2 |
||
| 226 | /* if($fc1InEffect){ |
||
| 227 | $start = \strlen($str); |
||
| 228 | // We need to massage the result a bit if in an FNC1 mode: |
||
| 229 | for($i = $start; $i < $start; $i++){ |
||
| 230 | if($str[$i] === '%'){ |
||
| 231 | if($i < $start - 1 && $str[$i + 1] === '%'){ |
||
| 232 | // %% is rendered as % |
||
| 233 | $str = \substr_replace($str, '', $i + 1, 1);//deleteCharAt(i + 1); |
||
| 234 | } |
||
| 235 | # else{ |
||
| 236 | // In alpha mode, % should be converted to FNC1 separator 0x1D @todo |
||
| 237 | # $str = setCharAt($i, \chr(0x1D)); // ??? |
||
| 238 | # } |
||
| 239 | } |
||
| 240 | } |
||
| 241 | } |
||
| 242 | */ |
||
| 243 | $result .= $str; |
||
| 244 | } |
||
| 245 | elseif($datamode === Mode::BYTE){ |
||
| 246 | $str = Byte::decodeSegment($bits, $versionNumber); |
||
| 247 | |||
| 248 | if($eciCharset !== null){ |
||
| 249 | $encoding = $eciCharset->getName(); |
||
| 250 | |||
| 251 | if($encoding === null){ |
||
| 252 | // The spec isn't clear on this mode; see |
||
| 253 | // section 6.4.5: t does not say which encoding to assuming |
||
| 254 | // upon decoding. I have seen ISO-8859-1 used as well as |
||
| 255 | // Shift_JIS -- without anything like an ECI designator to |
||
| 256 | // give a hint. |
||
| 257 | $encoding = mb_detect_encoding($str, ['ISO-8859-1', 'SJIS', 'UTF-8']); |
||
| 258 | } |
||
| 259 | |||
| 260 | $eciCharset = null; |
||
| 261 | $str = mb_convert_encoding($str, $encoding); |
||
| 262 | } |
||
| 263 | |||
| 264 | $result .= $str; |
||
| 265 | } |
||
| 266 | elseif($datamode === Mode::KANJI){ |
||
| 267 | $result .= Kanji::decodeSegment($bits, $versionNumber); |
||
| 268 | } |
||
| 269 | else{ |
||
| 270 | throw new QRCodeDecoderException('invalid data mode'); |
||
| 271 | } |
||
| 272 | # } |
||
| 273 | } |
||
| 274 | } |
||
| 275 | |||
| 276 | return new DecoderResult([ |
||
| 277 | 'rawBytes' => $bytes, |
||
| 278 | 'data' => $result, |
||
| 279 | 'version' => $this->version, |
||
| 280 | 'eccLevel' => $this->eccLevel, |
||
| 281 | 'maskPattern' => $this->formatInfo->getMaskPattern(), |
||
| 282 | 'structuredAppendParity' => $parityData, |
||
| 283 | 'structuredAppendSequence' => $symbolSequence |
||
| 284 | ]); |
||
| 288 |
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.