BitArray.php
9 months ago
BitMatrix.php
9 months ago
BitUtils.php
9 months ago
CharacterSetEci.php
9 months ago
EcBlock.php
9 months ago
EcBlocks.php
9 months ago
ErrorCorrectionLevel.php
9 months ago
FormatInformation.php
9 months ago
Mode.php
9 months ago
ReedSolomonCodec.php
9 months ago
Version.php
9 months ago
EcBlocks.php
75 lines
| 1 | <?php |
| 2 | declare(strict_types = 1); |
| 3 | |
| 4 | namespace 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 | /** |
| 23 | * List of EC blocks. |
| 24 | * |
| 25 | * @var EcBlock[] |
| 26 | */ |
| 27 | private $ecBlocks; |
| 28 | |
| 29 | public function __construct(int $ecCodewordsPerBlock, EcBlock ...$ecBlocks) |
| 30 | { |
| 31 | $this->ecCodewordsPerBlock = $ecCodewordsPerBlock; |
| 32 | $this->ecBlocks = $ecBlocks; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Returns the number of EC codewords per block. |
| 37 | */ |
| 38 | public function getEcCodewordsPerBlock() : int |
| 39 | { |
| 40 | return $this->ecCodewordsPerBlock; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns the total number of EC block appearances. |
| 45 | */ |
| 46 | public function getNumBlocks() : int |
| 47 | { |
| 48 | $total = 0; |
| 49 | |
| 50 | foreach ($this->ecBlocks as $ecBlock) { |
| 51 | $total += $ecBlock->getCount(); |
| 52 | } |
| 53 | |
| 54 | return $total; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Returns the total count of EC codewords. |
| 59 | */ |
| 60 | public function getTotalEcCodewords() : int |
| 61 | { |
| 62 | return $this->ecCodewordsPerBlock * $this->getNumBlocks(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns the EC blocks included in this collection. |
| 67 | * |
| 68 | * @return EcBlock[] |
| 69 | */ |
| 70 | public function getEcBlocks() : array |
| 71 | { |
| 72 | return $this->ecBlocks; |
| 73 | } |
| 74 | } |
| 75 |