Skip to content

Commit

Permalink
Replace error suppression with initializing the wordData correctly (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
gersonfs authored Jun 4, 2024
1 parent b3c35ac commit c38b7fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/QrCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,14 @@ private function encode()

$flag = true;
while ($flag) {
$this->wordData[$wordCount] = isset($this->wordData[$wordCount]) ? $this->wordData[$wordCount] : 0;
if ($remainingBit > $bufferBit) {
$this->wordData[$wordCount] = ((@$this->wordData[$wordCount] << $bufferBit) | $bufferVal);
$this->wordData[$wordCount] = (($this->wordData[$wordCount] << $bufferBit) | $bufferVal);
$remainingBit -= $bufferBit;
$flag = false;
} else {
$bufferBit -= $remainingBit;
$this->wordData[$wordCount] = ((@$this->wordData[$wordCount] << $remainingBit) | ($bufferVal >> $bufferBit));
$this->wordData[$wordCount] = (($this->wordData[$wordCount] << $remainingBit) | ($bufferVal >> $bufferBit));
$wordCount++;

if ($bufferBit === 0) {
Expand Down
7 changes: 7 additions & 0 deletions tests/QrCode/QrCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ public function testTooLongData()
new QrCode(base64_encode(random_bytes(1024 * 3)));
}

public function testUndefinedIndex()
{
$value = '1234567890123456.gov.bcb.pix0114028268660001815204000053039865406119.925802BR5912Clip Oba Oba6013Monten Matriz62120508v10173176304F297';
$qr = new QrCode($value);
$this->assertInstanceOf(QrCode::class, $qr);
}

}

0 comments on commit c38b7fb

Please sign in to comment.