mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-17 12:13:05 +00:00
:octocat: BitBuffer: remove property getters in favor of asymmetric visibility
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
+8
-8
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user