ソースを参照

Merge remote-tracking branch 'origin/v5.0.x' into v5.0.x

# Conflicts:
#	src/Data/QRData.php
smiley 1 年間 前
コミット
7229fdcb60

+ 1 - 1
README.md

@@ -79,7 +79,7 @@ For the QRCode reader, either `ext-gd` or `ext-imagick` is required!
 
 
 ## Installation with [composer](https://getcomposer.org)
 ## 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
 ### Terminal

+ 1 - 1
src/Data/QRData.php

@@ -195,7 +195,7 @@ final class QRData{
 
 
 		// guess the version number within the given range
 		// guess the version number within the given range
 		for($version = $this->options->versionMin; $version <= $this->options->versionMax; $version++){
 		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);
 				return new Version($version);
 			}
 			}
 		}
 		}

+ 4 - 4
src/Output/QROutputAbstract.php

@@ -146,18 +146,18 @@ abstract class QROutputAbstract implements QROutputInterface{
 	}
 	}
 
 
 	/**
 	/**
-	 * Prepares the value for the given input ()
+	 * Prepares the value for the given input (return value depends on the output class)
 	 *
 	 *
 	 * @param mixed $value
 	 * @param mixed $value
 	 *
 	 *
-	 * @return mixed|null return value depends on the output class
+	 * @return mixed|null
 	 */
 	 */
 	abstract protected function prepareModuleValue($value);
 	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);
 	abstract protected function getDefaultModuleValue(bool $isDark);
 
 

+ 5 - 0
src/QRCode.php

@@ -202,6 +202,11 @@ class QRCode{
 	/**
 	/**
 	 * Renders a QR Code for the given $data and QROptions, saves $file optionally
 	 * 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
 	 * @return mixed
 	 */
 	 */
 	public function render(string $data = null, string $file = null){
 	public function render(string $data = null, string $file = null){

+ 1 - 0
tests/Data/DataInterfaceTestAbstract.php

@@ -11,6 +11,7 @@
 namespace chillerlan\QRCodeTest\Data;
 namespace chillerlan\QRCodeTest\Data;
 
 
 use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Mode, Version};
 use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Mode, Version};
+use PHPUnit\Framework\ExpectationFailedException;
 use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
 use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
 use chillerlan\QRCode\QROptions;
 use chillerlan\QRCode\QROptions;
 use chillerlan\QRCodeTest\QRMaxLengthTrait;
 use chillerlan\QRCodeTest\QRMaxLengthTrait;

+ 27 - 0
tests/Data/QRDataTest.php

@@ -11,7 +11,9 @@
 namespace chillerlan\QRCodeTest\Data;
 namespace chillerlan\QRCodeTest\Data;
 
 
 use chillerlan\QRCode\Common\BitBuffer;
 use chillerlan\QRCode\Common\BitBuffer;
+use chillerlan\QRCode\Common\EccLevel;
 use chillerlan\QRCode\Common\MaskPattern;
 use chillerlan\QRCode\Common\MaskPattern;
+use chillerlan\QRCode\Data\Byte;
 use chillerlan\QRCode\Data\QRData;
 use chillerlan\QRCode\Data\QRData;
 use chillerlan\QRCode\Output\QRGdImagePNG;
 use chillerlan\QRCode\Output\QRGdImagePNG;
 use chillerlan\QRCode\QRCode;
 use chillerlan\QRCode\QRCode;
@@ -63,4 +65,29 @@ final class QRDataTest extends TestCase{
 		$this::assertSame($decodeResult->data, 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s');
 		$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
+	}
+
 }
 }