Debian Codegraph @

vendor/chillerlan/php-qrcode/src/Decoder/DecoderResult.php

raw
1 <?php
2 /**
3 * Class DecoderResult
4 *
5 * @created 17.01.2021
6 * @author ZXing Authors
7 * @author Smiley <[email protected]>
8 * @copyright 2021 Smiley
9 * @license Apache-2.0
10 */
11 declare(strict_types=1);
12
13 namespace chillerlan\QRCode\Decoder;
14
15 use chillerlan\QRCode\Common\{BitBuffer, EccLevel, MaskPattern, Version};
16 use chillerlan\QRCode\Data\QRMatrix;
17 use function property_exists;
18
19 /**
20 * Encapsulates the result of decoding a matrix of bits. This typically
21 * applies to 2D barcode formats. For now, it contains the raw bytes obtained
22 * as well as a String interpretation of those bytes, if applicable.
23 *
24 * @property string $data
25 * @property \chillerlan\QRCode\Common\EccLevel $eccLevel
26 * @property \chillerlan\QRCode\Detector\FinderPattern[] $finderPatterns
27 * @property \chillerlan\QRCode\Common\MaskPattern $maskPattern
28 * @property \chillerlan\QRCode\Common\BitBuffer $rawBytes
29 * @property int $structuredAppendParity
30 * @property int $structuredAppendSequence
31 * @property \chillerlan\QRCode\Common\Version $version
32 */
33 final class DecoderResult{
34
35 private string $data = '';
36 private EccLevel $eccLevel;
37 /** @var \chillerlan\QRCode\Detector\FinderPattern[] */
38 private array $finderPatterns = [];
39 private MaskPattern $maskPattern;
40 private BitBuffer $rawBytes;
41 private int $structuredAppendParity = -1;
42 private int $structuredAppendSequence = -1;
43 private Version $version;
44
45 /**
46 * DecoderResult constructor.
47 *
48 * @phpstan-param array<string, mixed> $properties
49 */
50 public function __construct(iterable|null $properties = null){
51
52 if($properties !== null){
53
54 foreach($properties as $property => $value){
55
56 if(!property_exists($this, $property)){
57 continue;
58 }
59
60 $this->{$property} = $value;
61 }
62
63 }
64
65 }
66
67 public function __get(string $property):mixed{
68
69 if(property_exists($this, $property)){
70 return $this->{$property};
71 }
72
73 return null;
74 }
75
76 public function __toString():string{
77 return $this->data;
78 }
79
80 public function hasStructuredAppend():bool{
81 return $this->structuredAppendParity >= 0 && $this->structuredAppendSequence >= 0;
82 }
83
84 /**
85 * Returns a QRMatrix instance with the settings and data of the reader result
86 */
87 public function getQRMatrix():QRMatrix{
88 return (new QRMatrix($this->version, $this->eccLevel))
89 ->initFunctionalPatterns()
90 ->writeCodewords($this->rawBytes)
91 ->setFormatInfo($this->maskPattern)
92 ->mask($this->maskPattern)
93 ;
94 }
95
96 }