codemasher 5 лет назад
Родитель
Сommit
b5a7f903b1

+ 1 - 1
src/Data/MaskPatternTester.php

@@ -76,7 +76,7 @@ class MaskPatternTester{
 							continue;
 						}
 
-						if($this->matrix->check($x + $rx, $y + $ry) === ($val >> 8 > 0)){
+						if($this->matrix->check($x + $rx, $y + $ry) === (($val >> 8) > 0)){
 							$count++;
 						}
 

+ 5 - 8
src/Data/QRDataAbstract.php

@@ -12,7 +12,7 @@
 
 namespace chillerlan\QRCode\Data;
 
-use chillerlan\QRCode\{QRCode, QRCodeException};
+use chillerlan\QRCode\QRCode;
 use chillerlan\QRCode\Helpers\{BitBuffer, Polynomial};
 use chillerlan\Settings\SettingsContainerInterface;
 
@@ -93,10 +93,8 @@ abstract class QRDataAbstract implements QRDataInterface{
 			? $this->getMinimumVersion()
 			: $this->options->version;
 
-		$this->matrixdata = $this
-			->writeBitBuffer($data)
-			->maskECC()
-		;
+		$this->writeBitBuffer($data);
+		$this->matrixdata = $this->maskECC();
 
 		return $this;
 	}
@@ -170,7 +168,7 @@ abstract class QRDataAbstract implements QRDataInterface{
 	 *
 	 * @throws \chillerlan\QRCode\QRCodeException
 	 */
-	protected function writeBitBuffer(string $data):QRDataInterface{
+	protected function writeBitBuffer(string $data):void{
 		$this->bitBuffer = new BitBuffer;
 
 		$MAX_BITS = $this::MAX_BITS[$this->version][QRCode::ECC_MODES[$this->options->eccLevel]];
@@ -214,7 +212,6 @@ abstract class QRDataAbstract implements QRDataInterface{
 			$this->bitBuffer->put(0x11, 8);
 		}
 
-		return $this;
 	}
 
 	/**
@@ -283,7 +280,7 @@ abstract class QRDataAbstract implements QRDataInterface{
 	}
 
 	/**
-	 * @return int[]
+	 *
 	 */
 	protected function poly(int $key, int $count):array{
 		$rsPoly  = new Polynomial;

+ 1 - 1
src/Data/QRMatrix.php

@@ -216,7 +216,7 @@ class QRMatrix{
 	}
 
 	/**
-	 *
+	 * @return int[][]
 	 */
 	public function matrix():array{
 		return $this->matrix;

+ 3 - 0
src/Helpers/Polynomial.php

@@ -59,6 +59,9 @@ class Polynomial{
 		[ 27, 116], [ 54, 214], [108, 244], [216, 234], [173, 168], [ 71,  80], [142,  88], [  1, 175],
 	];
 
+	/**
+	 * @var int[]
+	 */
 	protected array $num = [];
 
 	/**

+ 2 - 2
src/QROptions.php

@@ -21,7 +21,7 @@ use chillerlan\Settings\SettingsContainerAbstract;
  * @property int    $eccLevel
  * @property int    $maskPattern
  * @property bool   $addQuietzone
- * @property bool   $quietzoneSize
+ * @property int    $quietzoneSize
  *
  * @property string $dataMode
  * @property string $outputType
@@ -32,7 +32,7 @@ use chillerlan\Settings\SettingsContainerAbstract;
  * @property int    $scale
  *
  * @property string $cssClass
- * @property string $svgOpacity
+ * @property float  $svgOpacity
  * @property string $svgDefs
  * @property int    $svgViewBoxSize
  *

+ 1 - 1
src/QROptionsTrait.php

@@ -12,7 +12,7 @@
 
 namespace chillerlan\QRCode;
 
-use function array_values, count, is_array, is_numeric, max, min, sprintf;
+use function array_values, count, is_numeric, max, min, sprintf;
 
 trait QROptionsTrait{
 

+ 25 - 9
tests/QROptionsTest.php

@@ -22,10 +22,18 @@ class QROptionsTest extends TestCase{
 	protected SettingsContainerInterface $options;
 
 	public function testVersionClamp():void{
-		$this::assertSame(40, (new QROptions(['version' => 42]))->version);
-		$this::assertSame(1, (new QROptions(['version' => -42]))->version);
-		$this::assertSame(21, (new QROptions(['version' => 21]))->version);
-		$this::assertSame(QRCode::VERSION_AUTO, (new QROptions)->version); // QRCode::VERSION_AUTO = -1, default
+		$o = new QROptions(['version' => 42]);
+		$this::assertSame(40, $o->version);
+
+		$o = new QROptions(['version' => -42]);
+		$this::assertSame(1, $o->version);
+
+		$o = new QROptions(['version' => 21]);
+		$this::assertSame(21, $o->version);
+
+		// QRCode::VERSION_AUTO = -1, default
+		$o = new QROptions;
+		$this::assertSame(QRCode::VERSION_AUTO, $o->version);
 	}
 
 	public function testVersionMinMaxClamp():void{
@@ -50,16 +58,23 @@ class QROptionsTest extends TestCase{
 	}
 
 	public function testMaskPatternClamp():void{
-		$this::assertSame(7, (new QROptions(['maskPattern' => 42]))->maskPattern);
-		$this::assertSame(0, (new QROptions(['maskPattern' => -42]))->maskPattern);
-		$this::assertSame(QRCode::MASK_PATTERN_AUTO, (new QROptions)->maskPattern); // QRCode::MASK_PATTERN_AUTO = -1, default
+		$o = new QROptions(['maskPattern' => 42]);
+		$this::assertSame(7, $o->maskPattern);
+
+		$o = new QROptions(['maskPattern' => -42]);
+		$this::assertSame(0, $o->maskPattern);
+
+		// QRCode::MASK_PATTERN_AUTO = -1, default
+		$o = new QROptions;
+		$this::assertSame(QRCode::MASK_PATTERN_AUTO, $o->maskPattern);
 	}
 
 	public function testInvalidEccLevelException():void{
 		$this->expectException(QRCodeException::class);
 		$this->expectExceptionMessage('Invalid error correct level: 42');
 
-		new QROptions(['eccLevel' => 42]);
+		/** @noinspection PhpUnusedLocalVariableInspection */
+		$o = new QROptions(['eccLevel' => 42]);
 	}
 
 	public function testClampRGBValues():void{
@@ -74,6 +89,7 @@ class QROptionsTest extends TestCase{
 		$this->expectException(QRCodeException::class);
 		$this->expectExceptionMessage('Invalid RGB value.');
 
-		new QROptions(['imageTransparencyBG' => ['r', 'g', 'b']]);
+		/** @noinspection PhpUnusedLocalVariableInspection */
+		$o = new QROptions(['imageTransparencyBG' => ['r', 'g', 'b']]);
 	}
 }