mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-25 09:17:56 +00:00
:octocat: Version::$versionNumber: remove property getter in favor of asymmetric visibility
This commit is contained in:
@@ -32,7 +32,7 @@ final class DecoderBenchmark extends BenchmarkAbstract{
|
||||
public function initOptions():void{
|
||||
|
||||
$options = [
|
||||
'version' => $this->version->getVersionNumber(),
|
||||
'version' => $this->version->versionNumber,
|
||||
'eccLevel' => $this->eccLevel->level,
|
||||
'scale' => 2,
|
||||
'imageTransparent' => false,
|
||||
|
||||
@@ -32,7 +32,7 @@ final class MaskPatternBenchmark extends BenchmarkAbstract{
|
||||
public function initOptions():void{
|
||||
|
||||
$options = [
|
||||
'version' => $this->version->getVersionNumber(),
|
||||
'version' => $this->version->versionNumber,
|
||||
'eccLevel' => $this->eccLevel->level,
|
||||
];
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ final class OutputBenchmark extends BenchmarkAbstract{
|
||||
public function initOptions():void{
|
||||
|
||||
$options = [
|
||||
'version' => $this->version->getVersionNumber(),
|
||||
'version' => $this->version->versionNumber,
|
||||
'eccLevel' => $this->eccLevel->level,
|
||||
'connectPaths' => true,
|
||||
'drawLightModules' => true,
|
||||
|
||||
@@ -22,7 +22,7 @@ abstract class QRCodeBenchmark extends BenchmarkAbstract{
|
||||
public function initOptions():void{
|
||||
|
||||
$options = [
|
||||
'version' => $this->version->getVersionNumber(),
|
||||
'version' => $this->version->versionNumber,
|
||||
'eccLevel' => $this->eccLevel->level,
|
||||
];
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ final class QRDataBenchmark extends BenchmarkAbstract{
|
||||
public function initOptions():void{
|
||||
|
||||
$options = [
|
||||
'version' => $this->version->getVersionNumber(),
|
||||
'version' => $this->version->versionNumber,
|
||||
'eccLevel' => $this->eccLevel->level,
|
||||
];
|
||||
|
||||
@@ -71,7 +71,7 @@ final class QRDataBenchmark extends BenchmarkAbstract{
|
||||
#[Subject]
|
||||
#[BeforeMethods(['assignParams', 'generateTestData', 'initOptions', 'initQRData', 'initBitBuffer'])]
|
||||
public function decodeSegment():void{
|
||||
$this->dataMode->decodeSegment(clone $this->bitBuffer, $this->version->getVersionNumber());
|
||||
$this->dataMode->decodeSegment(clone $this->bitBuffer, $this->version->versionNumber);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ final class EccLevel{
|
||||
* Returns the maximum bit length for the given version and current ECC level
|
||||
*/
|
||||
public function getMaxBitsForVersion(Version $version):int{
|
||||
return self::MAX_BITS[$version->getVersionNumber()][$this->getOrdinal()];
|
||||
return self::MAX_BITS[$version->versionNumber][$this->getOrdinal()];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-15
@@ -216,7 +216,7 @@ final class Version{
|
||||
/**
|
||||
* QR Code version number
|
||||
*/
|
||||
private int $version;
|
||||
private(set) int $versionNumber;
|
||||
|
||||
/**
|
||||
* Version constructor.
|
||||
@@ -229,35 +229,28 @@ final class Version{
|
||||
throw new QRCodeException('invalid version given');
|
||||
}
|
||||
|
||||
$this->version = $version;
|
||||
$this->versionNumber = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the current version number as string
|
||||
*/
|
||||
public function __toString():string{
|
||||
return (string)$this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the current version number
|
||||
*/
|
||||
public function getVersionNumber():int{
|
||||
return $this->version;
|
||||
return (string)$this->versionNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* the matrix size for the given version
|
||||
*/
|
||||
public function getDimension():int{
|
||||
return (($this->version * 4) + 17);
|
||||
return (($this->versionNumber * 4) + 17);
|
||||
}
|
||||
|
||||
/**
|
||||
* the version pattern for the given version
|
||||
*/
|
||||
public function getVersionPattern():int|null{
|
||||
return (self::VERSION_PATTERN[$this->version] ?? null);
|
||||
return (self::VERSION_PATTERN[$this->versionNumber] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,21 +259,21 @@ final class Version{
|
||||
* @return int[]
|
||||
*/
|
||||
public function getAlignmentPattern():array{
|
||||
return self::ALIGNMENT_PATTERN[$this->version];
|
||||
return self::ALIGNMENT_PATTERN[$this->versionNumber];
|
||||
}
|
||||
|
||||
/**
|
||||
* returns ECC block information for the given $version and $eccLevel
|
||||
*/
|
||||
public function getRSBlocks(EccLevel $eccLevel):array{
|
||||
return self::RSBLOCKS[$this->version][$eccLevel->getOrdinal()];
|
||||
return self::RSBLOCKS[$this->versionNumber][$eccLevel->getOrdinal()];
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the maximum codewords for the current version
|
||||
*/
|
||||
public function getTotalCodewords():int{
|
||||
return self::TOTAL_CODEWORDS[$this->version];
|
||||
return self::TOTAL_CODEWORDS[$this->versionNumber];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -210,7 +210,7 @@ final class QRData{
|
||||
$MAX_BITS = $this->eccLevel->getMaxBitsForVersion($this->version);
|
||||
|
||||
foreach($this->dataSegments as $segment){
|
||||
$segment->write($this->bitBuffer, $this->version->getVersionNumber());
|
||||
$segment->write($this->bitBuffer, $this->version->versionNumber);
|
||||
}
|
||||
|
||||
// overflow, likely caused due to invalid version setting
|
||||
|
||||
@@ -107,7 +107,7 @@ final class Decoder{
|
||||
*/
|
||||
private function decodeBitStream(BitBuffer $bitBuffer):DecoderResult{
|
||||
$this->bitBuffer = $bitBuffer;
|
||||
$versionNumber = $this->version->getVersionNumber();
|
||||
$versionNumber = $this->version->versionNumber;
|
||||
$symbolSequence = -1;
|
||||
$parityData = -1;
|
||||
$fc1InEffect = false;
|
||||
|
||||
@@ -50,7 +50,7 @@ class QRStringJSON extends QROutputAbstract{
|
||||
$json = [
|
||||
'$schema' => $this::SCHEMA,
|
||||
'qrcode' => [
|
||||
'version' => $version->getVersionNumber(),
|
||||
'version' => $version->versionNumber,
|
||||
'eccLevel' => (string)$this->matrix->eccLevel,
|
||||
'matrix' => [
|
||||
'size' => $dimension,
|
||||
|
||||
@@ -34,7 +34,7 @@ final class VersionTest extends TestCase{
|
||||
|
||||
#[Test]
|
||||
public function getVersionNumber():void{
|
||||
$this::assertSame(7, $this->version->getVersionNumber());
|
||||
$this::assertSame(7, $this->version->versionNumber);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
|
||||
@@ -178,7 +178,7 @@ abstract class DataInterfaceTestAbstract extends TestCase{
|
||||
#[DataProvider('maxLengthProvider')]
|
||||
public function maxLength(Version $version, EccLevel $eccLevel, string $str, string $str1, int $len):void{
|
||||
$options = new QROptions;
|
||||
$options->version = $version->getVersionNumber();
|
||||
$options->version = $version->versionNumber;
|
||||
$options->eccLevel = $eccLevel->level;
|
||||
|
||||
$this->dataMode = static::getDataModeInterface($str);
|
||||
@@ -207,13 +207,13 @@ abstract class DataInterfaceTestAbstract extends TestCase{
|
||||
|
||||
$this::assertLessThanOrEqual($eccLevel->getMaxBitsForVersion($version), $this->QRData->estimateTotalBitLength());
|
||||
|
||||
$minimumVersionNumber = $this->QRData->getMinimumVersion()->getVersionNumber();
|
||||
$minimumVersionNumber = $this->QRData->getMinimumVersion()->versionNumber;
|
||||
|
||||
try{
|
||||
$this::assertSame($version->getVersionNumber(), $minimumVersionNumber);
|
||||
$this::assertSame($version->versionNumber, $minimumVersionNumber);
|
||||
}
|
||||
catch(ExpectationFailedException){
|
||||
$this::assertSame(($version->getVersionNumber() + 1), $minimumVersionNumber, 'safety margin');
|
||||
$this::assertSame(($version->versionNumber + 1), $minimumVersionNumber, 'safety margin');
|
||||
}
|
||||
|
||||
// verify the encoded data
|
||||
@@ -231,7 +231,7 @@ abstract class DataInterfaceTestAbstract extends TestCase{
|
||||
$this->expectExceptionMessage('code length overflow');
|
||||
|
||||
$options = new QROptions;
|
||||
$options->version = $version->getVersionNumber();
|
||||
$options->version = $version->versionNumber;
|
||||
$options->eccLevel = $eccLevel->level;
|
||||
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ final class QRDataTest extends TestCase{
|
||||
|
||||
$matrix->setFormatInfo($maskPattern)->mask($maskPattern);
|
||||
|
||||
$this::assertSame(3, $matrix->version->getVersionNumber());
|
||||
$this::assertSame(3, $matrix->version->versionNumber);
|
||||
|
||||
// attempt to read
|
||||
$options->outputBase64 = false;
|
||||
@@ -82,7 +82,7 @@ final class QRDataTest extends TestCase{
|
||||
$qrData = new QRData($options, [new Byte($str)]);
|
||||
|
||||
$this::assertSame(976, $qrData->estimateTotalBitLength());
|
||||
$this::assertSame(11, $qrData->getMinimumVersion()->getVersionNumber()); // version adjusted to 11
|
||||
$this::assertSame(11, $qrData->getMinimumVersion()->versionNumber); // version adjusted to 11
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ final class QRMatrixTest extends TestCase{
|
||||
*/
|
||||
#[Test]
|
||||
public function getVersion():void{
|
||||
$this::assertSame($this::version, $this->matrix->version->getVersionNumber());
|
||||
$this::assertSame($this::version, $this->matrix->version->versionNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +162,7 @@ final class QRMatrixTest extends TestCase{
|
||||
public function setAlignmentPattern(QRMatrix $matrix):void{
|
||||
$version = $matrix->version;
|
||||
|
||||
if($version->getVersionNumber() === 1){
|
||||
if($version->versionNumber === 1){
|
||||
$this::markTestSkipped('N/A (Version 1 has no alignment pattern)');
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ final class QRMatrixTest extends TestCase{
|
||||
#[DataProvider('matrixProvider')]
|
||||
public function setVersionNumber(QRMatrix $matrix):void{
|
||||
|
||||
if($matrix->version->getVersionNumber() < 7){
|
||||
if($matrix->version->versionNumber < 7){
|
||||
$this::markTestSkipped('N/A (Version < 7)');
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ abstract class QRCodeReaderTestAbstract extends TestCase{
|
||||
$this->options->outputInterface = QRGdImagePNG::class;
|
||||
$this->options->imageTransparent = false;
|
||||
$this->options->eccLevel = $ecc->level;
|
||||
$this->options->version = $version->getVersionNumber();
|
||||
$this->options->version = $version->versionNumber;
|
||||
$this->options->outputBase64 = false;
|
||||
// what's interesting is that a smaller scale seems to produce fewer reader errors???
|
||||
// usually from version 20 up, independend of the luminance source
|
||||
@@ -177,7 +177,7 @@ abstract class QRCodeReaderTestAbstract extends TestCase{
|
||||
$result = $qrcode->readFromBlob($imagedata);
|
||||
|
||||
$this::assertSame($expected, $result->data);
|
||||
$this::assertSame($version->getVersionNumber(), $result->version->getVersionNumber());
|
||||
$this::assertSame($version->versionNumber, $result->version->versionNumber);
|
||||
$this::assertSame($ecc->level, $result->eccLevel->level);
|
||||
}
|
||||
catch(Exception $e){
|
||||
|
||||
@@ -85,7 +85,7 @@ trait QRMatrixDebugTrait{
|
||||
|
||||
// limit
|
||||
/** @noinspection PhpUndefinedConstantInspection - see phpunit.xml.dist */
|
||||
if(!defined('MATRIX_DEBUG_VERSION') || $matrix->version->getVersionNumber() !== MATRIX_DEBUG_VERSION){
|
||||
if(!defined('MATRIX_DEBUG_VERSION') || $matrix->version->versionNumber !== MATRIX_DEBUG_VERSION){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ trait QRMaxLengthTrait{
|
||||
throw new QRCodeException('invalid $mode');
|
||||
}
|
||||
|
||||
$ver = $version->getVersionNumber();
|
||||
$ver = $version->versionNumber;
|
||||
$ecc = $eccLevel->getOrdinal();
|
||||
|
||||
if(!isset(static::MAX_LENGTH[$ver])){
|
||||
|
||||
Reference in New Issue
Block a user