diff --git a/src/Common/BitBuffer.php b/src/Common/BitBuffer.php index 480340b99..c56bd0ddc 100644 --- a/src/Common/BitBuffer.php +++ b/src/Common/BitBuffer.php @@ -22,14 +22,16 @@ final class BitBuffer{ /** * The buffer content * + * to debug: `array_map(fn($v) => sprintf('%08b', $v), $bitBuffer->buffer)` + * * @var int[] */ - private array $buffer; + private(set) array $buffer; /** * Length of the content (bits) */ - private int $length; + private(set) int $length; /** * Read count (bytes) @@ -82,24 +84,6 @@ final class BitBuffer{ return $this; } - /** - * returns the current buffer length - */ - public function getLength():int{ - return $this->length; - } - - /** - * returns the buffer content - * - * to debug: `array_map(fn($v) => sprintf('%08b', $v), $bitBuffer->getBuffer())` - * - * @return int[] - */ - public function getBuffer():array{ - return $this->buffer; - } - /** * Returns the number of bits that can be read successfully */ diff --git a/src/Data/QRData.php b/src/Data/QRData.php index 32af66319..517afc1bb 100644 --- a/src/Data/QRData.php +++ b/src/Data/QRData.php @@ -99,7 +99,7 @@ final class QRData{ throw new QRCodeDataException('version auto detection is not available'); } - if($bitBuffer->getLength() === 0){ + if($bitBuffer->length === 0){ throw new QRCodeDataException('the given BitBuffer is empty'); } @@ -214,14 +214,14 @@ final class QRData{ } // overflow, likely caused due to invalid version setting - if($this->bitBuffer->getLength() > $MAX_BITS){ + if($this->bitBuffer->length > $MAX_BITS){ throw new QRCodeDataException( - sprintf('code length overflow. (%d > %d bit)', $this->bitBuffer->getLength(), $MAX_BITS), + sprintf('code length overflow. (%d > %d bit)', $this->bitBuffer->length, $MAX_BITS), ); } // add terminator (ISO/IEC 18004:2000 Table 2) - if(($this->bitBuffer->getLength() + 4) <= $MAX_BITS){ + if(($this->bitBuffer->length + 4) <= $MAX_BITS){ $this->bitBuffer->put(Mode::TERMINATOR, 4); } @@ -229,9 +229,9 @@ final class QRData{ // if the final codeword is not exactly 8 bits in length, it shall be made 8 bits long // by the addition of padding bits with binary value 0 - while(($this->bitBuffer->getLength() % 8) !== 0){ + while(($this->bitBuffer->length % 8) !== 0){ - if($this->bitBuffer->getLength() === $MAX_BITS){ + if($this->bitBuffer->length === $MAX_BITS){ break; } @@ -243,7 +243,7 @@ final class QRData{ // Codewords 11101100 and 00010001 alternately. $alternate = false; - while(($this->bitBuffer->getLength() + 8) <= $MAX_BITS){ + while(($this->bitBuffer->length + 8) <= $MAX_BITS){ $this->bitBuffer->put(($alternate) ? 0b00010001 : 0b11101100, 8); $alternate = !$alternate; @@ -251,7 +251,7 @@ final class QRData{ // In certain versions of symbol, it may be necessary to add 3, 4 or 7 Remainder Bits (all zeros) // to the end of the message in order exactly to fill the symbol capacity - while($this->bitBuffer->getLength() <= $MAX_BITS){ + while($this->bitBuffer->length <= $MAX_BITS){ $this->bitBuffer->putBit(false); } diff --git a/src/Data/ReedSolomonEncoder.php b/src/Data/ReedSolomonEncoder.php index 4fca1fe6c..38b64b9d6 100644 --- a/src/Data/ReedSolomonEncoder.php +++ b/src/Data/ReedSolomonEncoder.php @@ -50,7 +50,7 @@ final class ReedSolomonEncoder{ $rsBlocks = array_merge($rsBlocks, array_fill(0, $l2, [($numEccCodewords + $b2), $b2])); } - $bitBufferData = $bitBuffer->getBuffer(); + $bitBufferData = $bitBuffer->buffer; $dataBytes = []; $ecBytes = []; $maxDataBytes = 0; diff --git a/tests/Common/BitBufferTest.php b/tests/Common/BitBufferTest.php index 141120520..2a9eef394 100644 --- a/tests/Common/BitBufferTest.php +++ b/tests/Common/BitBufferTest.php @@ -36,8 +36,8 @@ final class BitBufferTest extends TestCase{ public function put(int $data, int $expected):void{ $this->bitBuffer->put($data, 4); - $this::assertSame($expected, $this->bitBuffer->getBuffer()[0]); - $this::assertSame(4, $this->bitBuffer->getLength()); + $this::assertSame($expected, $this->bitBuffer->buffer[0]); + $this::assertSame(4, $this->bitBuffer->length); } #[Test]