Skip to content

Commit 7229fdc

Browse files
committed
Merge remote-tracking branch 'origin/v5.0.x' into v5.0.x
# Conflicts: # src/Data/QRData.php
2 parents 0f186c6 + da5bdb8 commit 7229fdc

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ For the QRCode reader, either `ext-gd` or `ext-imagick` is required!
7979

8080
## Installation with [composer](https://getcomposer.org)
8181

82-
See [the installation guide](https://php-qrcode.readthedocs.io/en/v5.0.x/Usage-Installation.html) for more info!
82+
See [the installation guide](https://php-qrcode.readthedocs.io/en/v5.0.x/Usage/Installation.html) for more info!
8383

8484

8585
### Terminal

src/Data/QRData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function getMinimumVersion():Version{
195195

196196
// guess the version number within the given range
197197
for($version = $this->options->versionMin; $version <= $this->options->versionMax; $version++){
198-
if($total <= $this->maxBitsForEcc[$version] - 4){
198+
if($total <= ($this->maxBitsForEcc[$version] - 4)){
199199
return new Version($version);
200200
}
201201
}

src/Output/QROutputAbstract.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,18 @@ protected function setModuleValues():void{
146146
}
147147

148148
/**
149-
* Prepares the value for the given input ()
149+
* Prepares the value for the given input (return value depends on the output class)
150150
*
151151
* @param mixed $value
152152
*
153-
* @return mixed|null return value depends on the output class
153+
* @return mixed|null
154154
*/
155155
abstract protected function prepareModuleValue($value);
156156

157157
/**
158-
* Returns a default value for either dark or light modules
158+
* Returns a default value for either dark or light modules (return value depends on the output class)
159159
*
160-
* @return mixed|null return value depends on the output class
160+
* @return mixed|null
161161
*/
162162
abstract protected function getDefaultModuleValue(bool $isDark);
163163

src/QRCode.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ public function setOptions(SettingsContainerInterface $options):self{
202202
/**
203203
* Renders a QR Code for the given $data and QROptions, saves $file optionally
204204
*
205+
* Note: it is possible to add several data segments before calling this method with a valid $data string
206+
* which will result in a mixed-mode QR Code with the given parameter as last element.
207+
*
208+
* @see https://github.com/chillerlan/php-qrcode/issues/246
209+
*
205210
* @return mixed
206211
*/
207212
public function render(string $data = null, string $file = null){

tests/Data/DataInterfaceTestAbstract.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace chillerlan\QRCodeTest\Data;
1212

1313
use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Mode, Version};
14+
use PHPUnit\Framework\ExpectationFailedException;
1415
use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
1516
use chillerlan\QRCode\QROptions;
1617
use chillerlan\QRCodeTest\QRMaxLengthTrait;

tests/Data/QRDataTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
namespace chillerlan\QRCodeTest\Data;
1212

1313
use chillerlan\QRCode\Common\BitBuffer;
14+
use chillerlan\QRCode\Common\EccLevel;
1415
use chillerlan\QRCode\Common\MaskPattern;
16+
use chillerlan\QRCode\Data\Byte;
1517
use chillerlan\QRCode\Data\QRData;
1618
use chillerlan\QRCode\Output\QRGdImagePNG;
1719
use chillerlan\QRCode\QRCode;
@@ -63,4 +65,29 @@ public function testSetBitBuffer():void{
6365
$this::assertSame($decodeResult->data, 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s');
6466
}
6567

68+
public function testEstimateTotalBitLength():void{
69+
70+
$options = new QROptions([
71+
'versionMin' => 10,
72+
'quietzoneSize' => 2,
73+
'eccLevel' => EccLevel::H,
74+
# 'outputType' => QROutputInterface::CUSTOM,
75+
# 'outputInterface' => PmaQrCodeSVG::class,
76+
'outputBase64' => false,
77+
'cssClass' => 'pma-2fa-qrcode',
78+
'drawCircularModules' => true,
79+
]);
80+
81+
// version 10H has a maximum of 976 bits, which is the exact length of the string below
82+
// QRData::estimateTotalBitLength() used to substract 4 bits for a hypothetical data mode indicator
83+
// we're now going the safe route and do not do that anymore...
84+
$str = 'otpauth://totp/user?secret=P2SXMJFJ7DJGHLVEQYBNH2EYM4FH66CR'.
85+
'&issuer=phpMyAdmin%20%28%29&digits=6&algorithm=SHA1&period=30';
86+
87+
$qrData = new QRData($options, [new Byte($str)]);
88+
89+
$this::assertSame(976, $qrData->estimateTotalBitLength());
90+
$this::assertSame(11, $qrData->getMinimumVersion()->getVersionNumber()); // version adjusted to 11
91+
}
92+
6693
}

0 commit comments

Comments
 (0)