Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v5.0.x' into v5.0.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Data/QRData.php
  • Loading branch information
codemasher committed Apr 19, 2024
2 parents 0f186c6 + da5bdb8 commit 7229fdc
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Data/QRData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Output/QROutputAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions src/QRCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
1 change: 1 addition & 0 deletions tests/Data/DataInterfaceTestAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions tests/Data/QRDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

}

0 comments on commit 7229fdc

Please sign in to comment.