From 0ef7bc7bf2f3e108aa7cb6e190b9e444b9a70ffc Mon Sep 17 00:00:00 2001 From: smiley Date: Tue, 1 Apr 2025 12:43:05 +0200 Subject: [PATCH] :octocat: extract QRMatrix::getBooleanMatrix() from QRMatrix::getMatrix() to remove type ambiguity --- src/Common/MaskPattern.php | 2 +- src/Data/QRMatrix.php | 18 +++++++++++------- tests/Data/QRMatrixTest.php | 6 +++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Common/MaskPattern.php b/src/Common/MaskPattern.php index e22d5511a..106fc5922 100644 --- a/src/Common/MaskPattern.php +++ b/src/Common/MaskPattern.php @@ -124,7 +124,7 @@ final class MaskPattern{ foreach(self::PATTERNS as $pattern){ $mp = new self($pattern); - $matrix = (clone $QRMatrix)->setFormatInfo($mp)->mask($mp)->getMatrix(true); + $matrix = (clone $QRMatrix)->setFormatInfo($mp)->mask($mp)->getBooleanMatrix(); $penalty = 0; for($level = 1; $level <= 4; $level++){ diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index 2ebda54af..e72d065b4 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -174,22 +174,26 @@ class QRMatrix{ } /** - * Returns the data matrix, returns a pure boolean representation if $boolean is set to true + * Returns the data matrix * * @return int[][] */ - public function getMatrix(bool|null $boolean = null):array{ - - if($boolean !== true){ - return $this->matrix; - } + public function getMatrix():array{ + return $this->matrix; + } + /** + * Returns a boolean representation of the data matrix + * + * @return bool[][] + */ + public function getBooleanMatrix():array{ $matrix = $this->matrix; foreach($matrix as &$row){ $row = array_map($this->isDark(...), $row); } - + /** @var bool[][] $matrix (phpstan hates this otherwise) */ return $matrix; } diff --git a/tests/Data/QRMatrixTest.php b/tests/Data/QRMatrixTest.php index 036bcfcdc..d2ffec8e8 100755 --- a/tests/Data/QRMatrixTest.php +++ b/tests/Data/QRMatrixTest.php @@ -42,7 +42,7 @@ final class QRMatrixTest extends TestCase{ * Tests if size() returns the actual matrix size/count */ public function testGetSize():void{ - $this::assertCount($this->matrix->getSize(), $this->matrix->getMatrix(true)); + $this::assertCount($this->matrix->getSize(), $this->matrix->getBooleanMatrix()); } /** @@ -255,8 +255,8 @@ final class QRMatrixTest extends TestCase{ $s = ($size + 2 * $quietZoneSize); - $this::assertCount($s, $matrix->getMatrix(true)); - $this::assertCount($s, $matrix->getMatrix(true)[($size - 1)]); + $this::assertCount($s, $matrix->getBooleanMatrix()); + $this::assertCount($s, $matrix->getBooleanMatrix()[($size - 1)]); $size = $matrix->getSize();