mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-19 19:20:12 +00:00
🔧 estimated bit length was correct, add a safety margin instead
This commit is contained in:
+4
-4
@@ -165,9 +165,9 @@ final class QRData{
|
||||
|
||||
// it seems that in some cases the estimated total length is not 100% accurate,
|
||||
// so we substract 4 bits from the total when not in mixed mode
|
||||
# if(count($this->dataSegments) <= 1){
|
||||
# $length -= 4;
|
||||
# }
|
||||
if(count($this->dataSegments) <= 1){
|
||||
$length -= 4;
|
||||
}
|
||||
|
||||
// we've got a match!
|
||||
// or let's see if there's a higher version number available
|
||||
@@ -195,7 +195,7 @@ final class QRData{
|
||||
|
||||
// guess the version number within the given range
|
||||
for($version = $this->options->versionMin; $version <= $this->options->versionMax; $version++){
|
||||
if($total <= $this->maxBitsForEcc[$version]){
|
||||
if($total <= ($this->maxBitsForEcc[$version] - 4)){
|
||||
return new Version($version);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
namespace chillerlan\QRCodeTest\Data;
|
||||
|
||||
use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Mode, Version};
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
|
||||
use chillerlan\QRCode\QROptions;
|
||||
use chillerlan\QRCodeTest\QRMaxLengthTrait;
|
||||
@@ -187,7 +188,13 @@ abstract class DataInterfaceTestAbstract extends TestCase{
|
||||
|
||||
$minimumVersionNumber = $this->QRData->getMinimumVersion()->getVersionNumber();
|
||||
|
||||
$this::assertSame($version->getVersionNumber(), $minimumVersionNumber);
|
||||
try{
|
||||
$this::assertSame($version->getVersionNumber(), $minimumVersionNumber);
|
||||
}
|
||||
catch(ExpectationFailedException $e){
|
||||
$this::assertSame(($version->getVersionNumber() + 1), $minimumVersionNumber, 'safety margin');
|
||||
}
|
||||
|
||||
// verify the encoded data
|
||||
$this::assertSame($this->dataMode::DATAMODE, $bitBuffer->read(4));
|
||||
$this::assertSame($str, $this->dataMode::decodeSegment($bitBuffer, $minimumVersionNumber));
|
||||
|
||||
@@ -86,7 +86,8 @@ final class QRDataTest extends TestCase{
|
||||
|
||||
$qrData = new QRData($options, [new Byte($str)]);
|
||||
|
||||
$this::assertSame(980, $qrData->estimateTotalBitLength());
|
||||
$this::assertSame(976, $qrData->estimateTotalBitLength());
|
||||
$this::assertSame(11, $qrData->getMinimumVersion()->getVersionNumber()); // version adjusted to 11
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user