Skip to content

Commit 0ef7bc7

Browse files
committed
:octocat: extract QRMatrix::getBooleanMatrix() from QRMatrix::getMatrix() to remove type ambiguity
1 parent 4a13767 commit 0ef7bc7

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/Common/MaskPattern.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static function getBestPattern(QRMatrix $QRMatrix):self{
124124

125125
foreach(self::PATTERNS as $pattern){
126126
$mp = new self($pattern);
127-
$matrix = (clone $QRMatrix)->setFormatInfo($mp)->mask($mp)->getMatrix(true);
127+
$matrix = (clone $QRMatrix)->setFormatInfo($mp)->mask($mp)->getBooleanMatrix();
128128
$penalty = 0;
129129

130130
for($level = 1; $level <= 4; $level++){

src/Data/QRMatrix.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,26 @@ public function initFunctionalPatterns():static{
174174
}
175175

176176
/**
177-
* Returns the data matrix, returns a pure boolean representation if $boolean is set to true
177+
* Returns the data matrix
178178
*
179179
* @return int[][]
180180
*/
181-
public function getMatrix(bool|null $boolean = null):array{
182-
183-
if($boolean !== true){
184-
return $this->matrix;
185-
}
181+
public function getMatrix():array{
182+
return $this->matrix;
183+
}
186184

185+
/**
186+
* Returns a boolean representation of the data matrix
187+
*
188+
* @return bool[][]
189+
*/
190+
public function getBooleanMatrix():array{
187191
$matrix = $this->matrix;
188192

189193
foreach($matrix as &$row){
190194
$row = array_map($this->isDark(...), $row);
191195
}
192-
196+
/** @var bool[][] $matrix (phpstan hates this otherwise) */
193197
return $matrix;
194198
}
195199

tests/Data/QRMatrixTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function setUp():void{
4242
* Tests if size() returns the actual matrix size/count
4343
*/
4444
public function testGetSize():void{
45-
$this::assertCount($this->matrix->getSize(), $this->matrix->getMatrix(true));
45+
$this::assertCount($this->matrix->getSize(), $this->matrix->getBooleanMatrix());
4646
}
4747

4848
/**
@@ -255,8 +255,8 @@ public function testSetQuietZone(QRMatrix $matrix):void{
255255

256256
$s = ($size + 2 * $quietZoneSize);
257257

258-
$this::assertCount($s, $matrix->getMatrix(true));
259-
$this::assertCount($s, $matrix->getMatrix(true)[($size - 1)]);
258+
$this::assertCount($s, $matrix->getBooleanMatrix());
259+
$this::assertCount($s, $matrix->getBooleanMatrix()[($size - 1)]);
260260

261261
$size = $matrix->getSize();
262262

0 commit comments

Comments
 (0)