Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+4 -12
View File
@@ -16,21 +16,13 @@ final class BitArray
*
* @var SplFixedArray<int>
*/
private $bits;
/**
* Size of the bit array in bits.
*
* @var int
*/
private $size;
private SplFixedArray $bits;
/**
* Creates a new bit array with a given size.
*/
public function __construct(int $size = 0)
public function __construct(private int $size = 0)
{
$this->size = $size;
$this->bits = SplFixedArray::fromArray(array_fill(0, ($this->size + 31) >> 3, 0));
}
@@ -107,7 +99,7 @@ final class BitArray
}
$result = ($bitsOffset << 5) + BitUtils::numberOfTrailingZeros($currentBits);
return $result > $this->size ? $this->size : $result;
return min($result, $this->size);
}
/**
@@ -133,7 +125,7 @@ final class BitArray
}
$result = ($bitsOffset << 5) + BitUtils::numberOfTrailingZeros($currentBits);
return $result > $this->size ? $this->size : $result;
return min($result, $this->size);
}
/**
+6 -12
View File
@@ -17,36 +17,30 @@ class BitMatrix
{
/**
* Width of the bit matrix.
*
* @var int
*/
private $width;
private int $width;
/**
* Height of the bit matrix.
*
* @var int
*/
private $height;
private ?int $height;
/**
* Size in bits of each individual row.
*
* @var int
*/
private $rowSize;
private int $rowSize;
/**
* Bits representation.
*
* @var SplFixedArray<int>
*/
private $bits;
private SplFixedArray $bits;
/**
* @throws InvalidArgumentException if a dimension is smaller than zero
*/
public function __construct(int $width, int $height = null)
public function __construct(int $width, ?int $height = null)
{
if (null === $height) {
$height = $width;
@@ -138,7 +132,7 @@ class BitMatrix
/**
* A fast method to retrieve one row of data from the matrix as a BitArray.
*/
public function getRow(int $y, BitArray $row = null) : BitArray
public function getRow(int $y, ?BitArray $row = null) : BitArray
{
if (null === $row || $row->getSize() < $this->width) {
$row = new BitArray($this->width);
+7 -10
View File
@@ -69,29 +69,26 @@ final class CharacterSetEci extends AbstractEnum
protected const GB18030 = [[29], 'GB2312', 'EUC_CN', 'GBK'];
protected const EUC_KR = [[30], 'EUC-KR'];
/**
* @var int[]
*/
private $values;
/**
* @var string[]
*/
private $otherEncodingNames;
private array $otherEncodingNames;
/**
* @var array<int, self>|null
*/
private static $valueToEci;
private static ?array $valueToEci;
/**
* @var array<string, self>|null
*/
private static $nameToEci;
private static ?array $nameToEci = null;
public function __construct(array $values, string ...$otherEncodingNames)
/**
* @param int[] $values
*/
public function __construct(private readonly array $values, string ...$otherEncodingNames)
{
$this->values = $values;
$this->otherEncodingNames = $otherEncodingNames;
}
+1 -17
View File
@@ -11,24 +11,8 @@ namespace BaconQrCode\Common;
*/
final class EcBlock
{
/**
* How many times the block is used.
*
* @var int
*/
private $count;
/**
* Number of data codewords.
*
* @var int
*/
private $dataCodewords;
public function __construct(int $count, int $dataCodewords)
public function __construct(private readonly int $count, private readonly int $dataCodewords)
{
$this->count = $count;
$this->dataCodewords = $dataCodewords;
}
/**
+2 -10
View File
@@ -12,23 +12,15 @@ namespace BaconQrCode\Common;
*/
final class EcBlocks
{
/**
* Number of EC codewords per block.
*
* @var int
*/
private $ecCodewordsPerBlock;
/**
* List of EC blocks.
*
* @var EcBlock[]
*/
private $ecBlocks;
private array $ecBlocks;
public function __construct(int $ecCodewordsPerBlock, EcBlock ...$ecBlocks)
public function __construct(private readonly int $ecCodewordsPerBlock, EcBlock ...$ecBlocks)
{
$this->ecCodewordsPerBlock = $ecCodewordsPerBlock;
$this->ecBlocks = $ecBlocks;
}
@@ -21,14 +21,8 @@ final class ErrorCorrectionLevel extends AbstractEnum
protected const Q = [0x03];
protected const H = [0x02];
/**
* @var int
*/
private $bits;
protected function __construct(int $bits)
protected function __construct(private readonly int $bits)
{
$this->bits = $bits;
}
/**
@@ -62,23 +62,16 @@ class FormatInformation
/**
* Offset i holds the number of 1 bits in the binary representation of i.
*
* @var array
* @var int[]
*/
private const BITS_SET_IN_HALF_BYTE = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4];
/**
* Error correction level.
*
* @var ErrorCorrectionLevel
*/
private $ecLevel;
private ErrorCorrectionLevel $ecLevel;
/**
* Data mask.
*
* @var int
*/
private $dataMask;
private int $dataMask;
protected function __construct(int $formatInfo)
{
+5 -12
View File
@@ -33,19 +33,12 @@ final class Mode extends AbstractEnum
protected const HANZI = [[8, 10, 12], 0x0d];
/**
* @var int[]
* @param int[] $characterCountBitsForVersions
*/
private $characterCountBitsForVersions;
/**
* @var int
*/
private $bits;
protected function __construct(array $characterCountBitsForVersions, int $bits)
{
$this->characterCountBitsForVersions = $characterCountBitsForVersions;
$this->bits = $bits;
protected function __construct(
private readonly array $characterCountBitsForVersions,
private readonly int $bits
) {
}
/**
+11 -25
View File
@@ -16,73 +16,59 @@ final class ReedSolomonCodec
{
/**
* Symbol size in bits.
*
* @var int
*/
private $symbolSize;
private int $symbolSize;
/**
* Block size in symbols.
*
* @var int
*/
private $blockSize;
private int $blockSize;
/**
* First root of RS code generator polynomial, index form.
*
* @var int
*/
private $firstRoot;
private int $firstRoot;
/**
* Primitive element to generate polynomial roots, index form.
*
* @var int
*/
private $primitive;
private int $primitive;
/**
* Prim-th root of 1, index form.
*
* @var int
*/
private $iPrimitive;
private int $iPrimitive;
/**
* RS code generator polynomial degree (number of roots).
*
* @var int
*/
private $numRoots;
private int $numRoots;
/**
* Padding bytes at front of shortened block.
*
* @var int
*/
private $padding;
private int $padding;
/**
* Log lookup table.
*
* @var SplFixedArray
*/
private $alphaTo;
private SplFixedArray $alphaTo;
/**
* Anti-Log lookup table.
*
* @var SplFixedArray
*/
private $indexOf;
private SplFixedArray $indexOf;
/**
* Generator polynomial.
*
* @var SplFixedArray
*/
private $generatorPoly;
private SplFixedArray $generatorPoly;
/**
* @throws InvalidArgumentException if symbol size ist not between 0 and 8
@@ -222,7 +208,7 @@ final class ReedSolomonCodec
/**
* Decodes received data.
*/
public function decode(SplFixedArray $data, SplFixedArray $erasures = null) : ?int
public function decode(SplFixedArray $data, ?SplFixedArray $erasures = null) : ?int
{
// This speeds up the initialization a bit.
$numRootsPlusOne = SplFixedArray::fromArray(array_fill(0, $this->numRoots + 1, 0), false);
+7 -11
View File
@@ -50,38 +50,34 @@ final class Version
/**
* Version number of this version.
*
* @var int
*/
private $versionNumber;
private int $versionNumber;
/**
* Alignment pattern centers.
*
* @var SplFixedArray
* @var SplFixedArray|array
*/
private $alignmentPatternCenters;
private SplFixedArray|array $alignmentPatternCenters;
/**
* Error correction blocks.
*
* @var EcBlocks[]
*/
private $ecBlocks;
private array $ecBlocks;
/**
* Total number of codewords.
*
* @var int
*/
private $totalCodewords;
private null|int|float $totalCodewords;
/**
* Cached version instances.
*
* @var array<int, self>|null
*/
private static $versions;
private static ?array $versions = null;
/**
* @param int[] $alignmentPatternCenters
@@ -300,7 +296,7 @@ final class Version
[6, 26],
new EcBlocks(20, new EcBlock(1, 80)),
new EcBlocks(18, new EcBlock(2, 32)),
new EcBlocks(26, new EcBlock(3, 24)),
new EcBlocks(26, new EcBlock(2, 24)),
new EcBlocks(16, new EcBlock(4, 9))
),
new self(