diff --git a/README.md b/README.md index b38592e14..582703ade 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ For the QRCode reader, either `ext-gd` or `ext-imagick` is required! ## Installation with [composer](https://getcomposer.org) -See [the installation guide](https://php-qrcode.readthedocs.io/en/v5.0.x/Usage-Installation.html) for more info! +See [the installation guide](https://php-qrcode.readthedocs.io/en/v5.0.x/Usage/Installation.html) for more info! ### Terminal diff --git a/src/Data/QRData.php b/src/Data/QRData.php index 366b0671f..1d03a9d6b 100644 --- a/src/Data/QRData.php +++ b/src/Data/QRData.php @@ -195,7 +195,7 @@ public function getMinimumVersion():Version{ // guess the version number within the given range for($version = $this->options->versionMin; $version <= $this->options->versionMax; $version++){ - if($total <= $this->maxBitsForEcc[$version] - 4){ + if($total <= ($this->maxBitsForEcc[$version] - 4)){ return new Version($version); } } diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php index fe6e08611..7ac64fffa 100644 --- a/src/Output/QROutputAbstract.php +++ b/src/Output/QROutputAbstract.php @@ -146,18 +146,18 @@ protected function setModuleValues():void{ } /** - * Prepares the value for the given input () + * Prepares the value for the given input (return value depends on the output class) * * @param mixed $value * - * @return mixed|null return value depends on the output class + * @return mixed|null */ abstract protected function prepareModuleValue($value); /** - * Returns a default value for either dark or light modules + * Returns a default value for either dark or light modules (return value depends on the output class) * - * @return mixed|null return value depends on the output class + * @return mixed|null */ abstract protected function getDefaultModuleValue(bool $isDark); diff --git a/src/QRCode.php b/src/QRCode.php index 8caa1d739..bca6ac584 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -202,6 +202,11 @@ public function setOptions(SettingsContainerInterface $options):self{ /** * Renders a QR Code for the given $data and QROptions, saves $file optionally * + * Note: it is possible to add several data segments before calling this method with a valid $data string + * which will result in a mixed-mode QR Code with the given parameter as last element. + * + * @see https://github.com/chillerlan/php-qrcode/issues/246 + * * @return mixed */ public function render(string $data = null, string $file = null){ diff --git a/tests/Data/DataInterfaceTestAbstract.php b/tests/Data/DataInterfaceTestAbstract.php index be970cf78..0b65d5bfb 100644 --- a/tests/Data/DataInterfaceTestAbstract.php +++ b/tests/Data/DataInterfaceTestAbstract.php @@ -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; diff --git a/tests/Data/QRDataTest.php b/tests/Data/QRDataTest.php index 74ce298d3..b47bc0f3d 100644 --- a/tests/Data/QRDataTest.php +++ b/tests/Data/QRDataTest.php @@ -11,7 +11,9 @@ namespace chillerlan\QRCodeTest\Data; use chillerlan\QRCode\Common\BitBuffer; +use chillerlan\QRCode\Common\EccLevel; use chillerlan\QRCode\Common\MaskPattern; +use chillerlan\QRCode\Data\Byte; use chillerlan\QRCode\Data\QRData; use chillerlan\QRCode\Output\QRGdImagePNG; use chillerlan\QRCode\QRCode; @@ -63,4 +65,29 @@ public function testSetBitBuffer():void{ $this::assertSame($decodeResult->data, 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'); } + public function testEstimateTotalBitLength():void{ + + $options = new QROptions([ + 'versionMin' => 10, + 'quietzoneSize' => 2, + 'eccLevel' => EccLevel::H, +# 'outputType' => QROutputInterface::CUSTOM, +# 'outputInterface' => PmaQrCodeSVG::class, + 'outputBase64' => false, + 'cssClass' => 'pma-2fa-qrcode', + 'drawCircularModules' => true, + ]); + + // version 10H has a maximum of 976 bits, which is the exact length of the string below + // QRData::estimateTotalBitLength() used to substract 4 bits for a hypothetical data mode indicator + // we're now going the safe route and do not do that anymore... + $str = 'otpauth://totp/user?secret=P2SXMJFJ7DJGHLVEQYBNH2EYM4FH66CR'. + '&issuer=phpMyAdmin%20%28%29&digits=6&algorithm=SHA1&period=30'; + + $qrData = new QRData($options, [new Byte($str)]); + + $this::assertSame(976, $qrData->estimateTotalBitLength()); + $this::assertSame(11, $qrData->getMinimumVersion()->getVersionNumber()); // version adjusted to 11 + } + }