From 6b59d01c9efed1ae1b6a590b5e155e205f7db2ca Mon Sep 17 00:00:00 2001 From: smiley Date: Wed, 18 Mar 2026 02:04:33 +0100 Subject: [PATCH] :octocat: EccLevel::$level remove property getter in favor of asymmetric visibility --- benchmark/DecoderBenchmark.php | 2 +- benchmark/MaskPatternBenchmark.php | 2 +- benchmark/OutputBenchmark.php | 2 +- benchmark/QRCodeBenchmark.php | 2 +- benchmark/QRDataBenchmark.php | 2 +- src/Common/EccLevel.php | 15 ++++----------- src/Data/QRMatrix.php | 2 +- tests/Common/EccLevelTest.php | 2 +- tests/Data/DataInterfaceTestAbstract.php | 6 +++--- tests/Data/QRMatrixTest.php | 2 +- tests/QRCodeReaderTestAbstract.php | 4 ++-- 11 files changed, 17 insertions(+), 24 deletions(-) diff --git a/benchmark/DecoderBenchmark.php b/benchmark/DecoderBenchmark.php index 4f8cb8edc..9c85ded6c 100644 --- a/benchmark/DecoderBenchmark.php +++ b/benchmark/DecoderBenchmark.php @@ -33,7 +33,7 @@ final class DecoderBenchmark extends BenchmarkAbstract{ $options = [ 'version' => $this->version->getVersionNumber(), - 'eccLevel' => $this->eccLevel->getLevel(), + 'eccLevel' => $this->eccLevel->level, 'scale' => 2, 'imageTransparent' => false, 'outputBase64' => false, diff --git a/benchmark/MaskPatternBenchmark.php b/benchmark/MaskPatternBenchmark.php index 551b59cff..1013b0e3e 100644 --- a/benchmark/MaskPatternBenchmark.php +++ b/benchmark/MaskPatternBenchmark.php @@ -33,7 +33,7 @@ final class MaskPatternBenchmark extends BenchmarkAbstract{ $options = [ 'version' => $this->version->getVersionNumber(), - 'eccLevel' => $this->eccLevel->getLevel(), + 'eccLevel' => $this->eccLevel->level, ]; $this->initQROptions($options); diff --git a/benchmark/OutputBenchmark.php b/benchmark/OutputBenchmark.php index c2cee6eb4..f4f4c091e 100644 --- a/benchmark/OutputBenchmark.php +++ b/benchmark/OutputBenchmark.php @@ -30,7 +30,7 @@ final class OutputBenchmark extends BenchmarkAbstract{ $options = [ 'version' => $this->version->getVersionNumber(), - 'eccLevel' => $this->eccLevel->getLevel(), + 'eccLevel' => $this->eccLevel->level, 'connectPaths' => true, 'drawLightModules' => true, 'drawCircularModules' => true, diff --git a/benchmark/QRCodeBenchmark.php b/benchmark/QRCodeBenchmark.php index 7c508327f..fdccfe410 100644 --- a/benchmark/QRCodeBenchmark.php +++ b/benchmark/QRCodeBenchmark.php @@ -23,7 +23,7 @@ abstract class QRCodeBenchmark extends BenchmarkAbstract{ $options = [ 'version' => $this->version->getVersionNumber(), - 'eccLevel' => $this->eccLevel->getLevel(), + 'eccLevel' => $this->eccLevel->level, ]; $this->initQROptions($options); diff --git a/benchmark/QRDataBenchmark.php b/benchmark/QRDataBenchmark.php index 8d4203a23..719240ba6 100644 --- a/benchmark/QRDataBenchmark.php +++ b/benchmark/QRDataBenchmark.php @@ -29,7 +29,7 @@ final class QRDataBenchmark extends BenchmarkAbstract{ $options = [ 'version' => $this->version->getVersionNumber(), - 'eccLevel' => $this->eccLevel->getLevel(), + 'eccLevel' => $this->eccLevel->level, ]; $this->initQROptions($options); diff --git a/src/Common/EccLevel.php b/src/Common/EccLevel.php index 1e525e0eb..c49c239e5 100644 --- a/src/Common/EccLevel.php +++ b/src/Common/EccLevel.php @@ -134,7 +134,7 @@ final class EccLevel{ * Q: 0b11 * H: 0b10 */ - private int $eccLevel; + private(set) int $level; /** * @param int $eccLevel containing the two bits encoding a QR Code's error correction level @@ -147,7 +147,7 @@ final class EccLevel{ throw new QRCodeException('invalid ECC level'); } - $this->eccLevel = $eccLevel; + $this->level = $eccLevel; } /** @@ -159,14 +159,7 @@ final class EccLevel{ self::M => 'M', self::Q => 'Q', self::H => 'H', - ][$this->eccLevel]; - } - - /** - * returns the current ECC level - */ - public function getLevel():int{ - return $this->eccLevel; + ][$this->level]; } /** @@ -184,7 +177,7 @@ final class EccLevel{ self::M => 1, self::Q => 2, self::H => 3, - ][$this->eccLevel]; + ][$this->level]; } /** diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index aa08b6cc5..1b0758187 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -578,7 +578,7 @@ class QRMatrix{ } // for logos, we operate in ECC H (30%) only - if($this->eccLevel->getLevel() !== EccLevel::H){ + if($this->eccLevel->level !== EccLevel::H){ throw new QRCodeDataException('ECC level "H" required to add logo space'); } diff --git a/tests/Common/EccLevelTest.php b/tests/Common/EccLevelTest.php index fa695a9d4..849f619ca 100644 --- a/tests/Common/EccLevelTest.php +++ b/tests/Common/EccLevelTest.php @@ -40,7 +40,7 @@ final class EccLevelTest extends TestCase{ public function getLevel():void{ $ecc = new EccLevel(EccLevel::L); - $this::assertSame(EccLevel::L, $ecc->getLevel()); + $this::assertSame(EccLevel::L, $ecc->level); } #[Test] diff --git a/tests/Data/DataInterfaceTestAbstract.php b/tests/Data/DataInterfaceTestAbstract.php index 9a7baf072..43615bfef 100644 --- a/tests/Data/DataInterfaceTestAbstract.php +++ b/tests/Data/DataInterfaceTestAbstract.php @@ -179,7 +179,7 @@ abstract class DataInterfaceTestAbstract extends TestCase{ public function maxLength(Version $version, EccLevel $eccLevel, string $str, string $str1, int $len):void{ $options = new QROptions; $options->version = $version->getVersionNumber(); - $options->eccLevel = $eccLevel->getLevel(); + $options->eccLevel = $eccLevel->level; $this->dataMode = static::getDataModeInterface($str); $this->QRData = new QRData($options, [$this->dataMode]); @@ -198,7 +198,7 @@ abstract class DataInterfaceTestAbstract extends TestCase{ public function getMinimumVersion(Version $version, EccLevel $eccLevel, string $str, string $str1, int $len):void{ $options = new QROptions; $options->version = Version::AUTO; - $options->eccLevel = $eccLevel->getLevel(); + $options->eccLevel = $eccLevel->level; $this->dataMode = static::getDataModeInterface($str); $this->QRData = new QRData($options, [$this->dataMode]); @@ -232,7 +232,7 @@ abstract class DataInterfaceTestAbstract extends TestCase{ $options = new QROptions; $options->version = $version->getVersionNumber(); - $options->eccLevel = $eccLevel->getLevel(); + $options->eccLevel = $eccLevel->level; new QRData($options, [static::getDataModeInterface($str1)]); diff --git a/tests/Data/QRMatrixTest.php b/tests/Data/QRMatrixTest.php index 2bd0cf514..a87c1d14b 100755 --- a/tests/Data/QRMatrixTest.php +++ b/tests/Data/QRMatrixTest.php @@ -59,7 +59,7 @@ final class QRMatrixTest extends TestCase{ */ #[Test] public function getECC():void{ - $this::assertSame(EccLevel::L, $this->matrix->eccLevel->getLevel()); + $this::assertSame(EccLevel::L, $this->matrix->eccLevel->level); } /** diff --git a/tests/QRCodeReaderTestAbstract.php b/tests/QRCodeReaderTestAbstract.php index 1f4892bb3..9839bc79d 100644 --- a/tests/QRCodeReaderTestAbstract.php +++ b/tests/QRCodeReaderTestAbstract.php @@ -162,7 +162,7 @@ abstract class QRCodeReaderTestAbstract extends TestCase{ public function readData(Version $version, EccLevel $ecc, string $expected):void{ $this->options->outputInterface = QRGdImagePNG::class; $this->options->imageTransparent = false; - $this->options->eccLevel = $ecc->getLevel(); + $this->options->eccLevel = $ecc->level; $this->options->version = $version->getVersionNumber(); $this->options->outputBase64 = false; // what's interesting is that a smaller scale seems to produce fewer reader errors??? @@ -178,7 +178,7 @@ abstract class QRCodeReaderTestAbstract extends TestCase{ $this::assertSame($expected, $result->data); $this::assertSame($version->getVersionNumber(), $result->version->getVersionNumber()); - $this::assertSame($ecc->getLevel(), $result->eccLevel->getLevel()); + $this::assertSame($ecc->level, $result->eccLevel->level); } catch(Exception $e){ $this::markTestSkipped(sprintf('skipped version %s%s: %s', $version, $ecc, $e->getMessage()));