| Conditions | 13 |
| Paths | 4 |
| Total Lines | 62 |
| Code Lines | 39 |
| 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 |
||
| 92 | private function decodeBitStream(BitBuffer $bitBuffer):DecoderResult{ |
||
| 93 | $this->bitBuffer = $bitBuffer; |
||
| 94 | $versionNumber = $this->version->getVersionNumber(); |
||
|
|
|||
| 95 | $symbolSequence = -1; |
||
| 96 | $parityData = -1; |
||
| 97 | $fc1InEffect = false; |
||
| 98 | $result = ''; |
||
| 99 | |||
| 100 | // While still another segment to read... |
||
| 101 | while($this->bitBuffer->available() >= 4){ |
||
| 102 | $datamode = $this->bitBuffer->read(4); // mode is encoded by 4 bits |
||
| 103 | |||
| 104 | // OK, assume we're done |
||
| 105 | if($datamode === Mode::TERMINATOR){ |
||
| 106 | break; |
||
| 107 | } |
||
| 108 | elseif($datamode === Mode::NUMBER){ |
||
| 109 | $result .= Number::decodeSegment($this->bitBuffer, $versionNumber); |
||
| 110 | } |
||
| 111 | elseif($datamode === Mode::ALPHANUM){ |
||
| 112 | $result .= $this->decodeAlphanumSegment($versionNumber, $fc1InEffect); |
||
| 113 | } |
||
| 114 | elseif($datamode === Mode::BYTE){ |
||
| 115 | $result .= Byte::decodeSegment($this->bitBuffer, $versionNumber); |
||
| 116 | } |
||
| 117 | elseif($datamode === Mode::KANJI){ |
||
| 118 | $result .= Kanji::decodeSegment($this->bitBuffer, $versionNumber); |
||
| 119 | } |
||
| 120 | elseif($datamode === Mode::STRCTURED_APPEND){ |
||
| 121 | |||
| 122 | if($this->bitBuffer->available() < 16){ |
||
| 123 | throw new QRCodeDecoderException('structured append: not enough bits left'); |
||
| 124 | } |
||
| 125 | // sequence number and parity is added later to the result metadata |
||
| 126 | // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue |
||
| 127 | $symbolSequence = $this->bitBuffer->read(8); |
||
| 128 | $parityData = $this->bitBuffer->read(8); |
||
| 129 | } |
||
| 130 | elseif($datamode === Mode::FNC1_FIRST || $datamode === Mode::FNC1_SECOND){ |
||
| 131 | // We do little with FNC1 except alter the parsed result a bit according to the spec |
||
| 132 | $fc1InEffect = true; |
||
| 133 | } |
||
| 134 | elseif($datamode === Mode::ECI){ |
||
| 135 | $result .= ECI::decodeSegment($this->bitBuffer, $versionNumber); |
||
| 136 | } |
||
| 137 | elseif($datamode === Mode::HANZI){ |
||
| 138 | $result .= Hanzi::decodeSegment($this->bitBuffer, $versionNumber); |
||
| 139 | } |
||
| 140 | else{ |
||
| 141 | throw new QRCodeDecoderException('invalid data mode'); |
||
| 142 | } |
||
| 143 | |||
| 144 | } |
||
| 145 | |||
| 146 | return new DecoderResult([ |
||
| 147 | 'rawBytes' => $this->bitBuffer, |
||
| 148 | 'data' => $result, |
||
| 149 | 'version' => $this->version, |
||
| 150 | 'eccLevel' => $this->eccLevel, |
||
| 151 | 'maskPattern' => $this->maskPattern, |
||
| 152 | 'structuredAppendParity' => $parityData, |
||
| 153 | 'structuredAppendSequence' => $symbolSequence, |
||
| 154 | ]); |
||
| 174 |
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.