BitArray.php
11 months ago
BitMatrix.php
11 months ago
BitUtils.php
11 months ago
CharacterSetEci.php
11 months ago
EcBlock.php
11 months ago
EcBlocks.php
11 months ago
ErrorCorrectionLevel.php
11 months ago
FormatInformation.php
11 months ago
Mode.php
11 months ago
ReedSolomonCodec.php
11 months ago
Version.php
11 months ago
EcBlocks.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace WP2FA_Vendor\BaconQrCode\Common; |
| 5 | |
| 6 | /** |
| 7 | * Encapsulates a set of error-correction blocks in one symbol version. |
| 8 | * |
| 9 | * Most versions will use blocks of differing sizes within one version, so, this encapsulates the parameters for each |
| 10 | * set of blocks. It also holds the number of error-correction codewords per block since it will be the same across all |
| 11 | * blocks within one version. |
| 12 | */ |
| 13 | final class EcBlocks |
| 14 | { |
| 15 | /** |
| 16 | * Number of EC codewords per block. |
| 17 | * |
| 18 | * @var int |
| 19 | */ |
| 20 | private $ecCodewordsPerBlock; |
| 21 | /** |
| 22 | * List of EC blocks. |
| 23 | * |
| 24 | * @var EcBlock[] |
| 25 | */ |
| 26 | private $ecBlocks; |
| 27 | public function __construct(int $ecCodewordsPerBlock, EcBlock ...$ecBlocks) |
| 28 | { |
| 29 | $this->ecCodewordsPerBlock = $ecCodewordsPerBlock; |
| 30 | $this->ecBlocks = $ecBlocks; |
| 31 | } |
| 32 | /** |
| 33 | * Returns the number of EC codewords per block. |
| 34 | */ |
| 35 | public function getEcCodewordsPerBlock() : int |
| 36 | { |
| 37 | return $this->ecCodewordsPerBlock; |
| 38 | } |
| 39 | /** |
| 40 | * Returns the total number of EC block appearances. |
| 41 | */ |
| 42 | public function getNumBlocks() : int |
| 43 | { |
| 44 | $total = 0; |
| 45 | foreach ($this->ecBlocks as $ecBlock) { |
| 46 | $total += $ecBlock->getCount(); |
| 47 | } |
| 48 | return $total; |
| 49 | } |
| 50 | /** |
| 51 | * Returns the total count of EC codewords. |
| 52 | */ |
| 53 | public function getTotalEcCodewords() : int |
| 54 | { |
| 55 | return $this->ecCodewordsPerBlock * $this->getNumBlocks(); |
| 56 | } |
| 57 | /** |
| 58 | * Returns the EC blocks included in this collection. |
| 59 | * |
| 60 | * @return EcBlock[] |
| 61 | */ |
| 62 | public function getEcBlocks() : array |
| 63 | { |
| 64 | return $this->ecBlocks; |
| 65 | } |
| 66 | } |
| 67 |