1 | <?php |
||
30 | class QRCode{ |
||
31 | |||
32 | /** |
||
33 | * API constants |
||
34 | */ |
||
35 | const OUTPUT_MARKUP_HTML = 'html'; |
||
36 | const OUTPUT_MARKUP_SVG = 'svg'; |
||
37 | # const OUTPUT_MARKUP_EPS = 'eps'; |
||
38 | # const OUTPUT_MARKUP_XML = 'xml'; // anyone? |
||
39 | |||
40 | const OUTPUT_IMAGE_PNG = 'png'; |
||
41 | const OUTPUT_IMAGE_JPG = 'jpg'; |
||
42 | const OUTPUT_IMAGE_GIF = 'gif'; |
||
43 | |||
44 | const OUTPUT_STRING_JSON = 'json'; |
||
45 | const OUTPUT_STRING_TEXT = 'text'; |
||
46 | |||
47 | const OUTPUT_CUSTOM = 'custom'; |
||
48 | |||
49 | const VERSION_AUTO = -1; |
||
50 | const MASK_PATTERN_AUTO = -1; |
||
51 | |||
52 | const ECC_L = 0b01; // 7%. |
||
53 | const ECC_M = 0b00; // 15%. |
||
54 | const ECC_Q = 0b11; // 25%. |
||
55 | const ECC_H = 0b10; // 30%. |
||
56 | |||
57 | const DATA_NUMBER = 0b0001; |
||
58 | const DATA_ALPHANUM = 0b0010; |
||
59 | const DATA_BYTE = 0b0100; |
||
60 | const DATA_KANJI = 0b1000; |
||
61 | |||
62 | const ECC_MODES = [ |
||
63 | self::ECC_L => 0, |
||
64 | self::ECC_M => 1, |
||
65 | self::ECC_Q => 2, |
||
66 | self::ECC_H => 3, |
||
67 | ]; |
||
68 | |||
69 | const DATA_MODES = [ |
||
70 | self::DATA_NUMBER => 0, |
||
71 | self::DATA_ALPHANUM => 1, |
||
72 | self::DATA_BYTE => 2, |
||
73 | self::DATA_KANJI => 3, |
||
74 | ]; |
||
75 | |||
76 | const OUTPUT_MODES = [ |
||
77 | QRMarkup::class => [ |
||
78 | self::OUTPUT_MARKUP_SVG, |
||
79 | self::OUTPUT_MARKUP_HTML, |
||
80 | # self::OUTPUT_MARKUP_EPS, |
||
81 | ], |
||
82 | QRImage::class => [ |
||
83 | self::OUTPUT_IMAGE_PNG, |
||
84 | self::OUTPUT_IMAGE_GIF, |
||
85 | self::OUTPUT_IMAGE_JPG, |
||
86 | ], |
||
87 | QRString::class => [ |
||
88 | self::OUTPUT_STRING_JSON, |
||
89 | self::OUTPUT_STRING_TEXT, |
||
90 | ] |
||
91 | ]; |
||
92 | |||
93 | /** |
||
94 | * @var \chillerlan\QRCode\QROptions |
||
95 | */ |
||
96 | protected $options; |
||
97 | |||
98 | /** |
||
99 | * @var \chillerlan\QRCode\Data\QRDataInterface |
||
100 | */ |
||
101 | protected $dataInterface; |
||
102 | |||
103 | /** |
||
104 | * QRCode constructor. |
||
105 | * |
||
106 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
||
107 | */ |
||
108 | public function __construct(SettingsContainerInterface $options = null){ |
||
113 | |||
114 | /** |
||
115 | * Renders a QR Code for the given $data and QROptions |
||
116 | * |
||
117 | * @param string $data |
||
118 | * |
||
119 | * @return mixed |
||
120 | */ |
||
121 | public function render(string $data){ |
||
124 | |||
125 | /** |
||
126 | * Returns a QRMatrix object for the given $data and current QROptions |
||
127 | * |
||
128 | * @param string $data |
||
129 | * |
||
130 | * @return \chillerlan\QRCode\Data\QRMatrix |
||
131 | * @throws \chillerlan\QRCode\Data\QRCodeDataException |
||
132 | */ |
||
133 | public function getMatrix(string $data):QRMatrix { |
||
159 | |||
160 | /** |
||
161 | * shoves a QRMatrix through the MaskPatternTester to find the lowest penalty mask pattern |
||
162 | * |
||
163 | * @see \chillerlan\QRCode\Data\MaskPatternTester |
||
164 | * |
||
165 | * @return int |
||
166 | */ |
||
167 | protected function getBestMaskPattern():int{ |
||
180 | |||
181 | /** |
||
182 | * returns a fresh QRDataInterface for the given $data |
||
183 | * |
||
184 | * @param string $data |
||
185 | * |
||
186 | * @return \chillerlan\QRCode\Data\QRDataInterface |
||
187 | * @throws \chillerlan\QRCode\Data\QRCodeDataException |
||
188 | */ |
||
189 | public function initDataInterface(string $data):QRDataInterface{ |
||
208 | |||
209 | /** |
||
210 | * returns a fresh (built-in) QROutputInterface |
||
211 | * |
||
212 | * @param string $data |
||
213 | * |
||
214 | * @return \chillerlan\QRCode\Output\QROutputInterface |
||
215 | * @throws \chillerlan\QRCode\Output\QRCodeOutputException |
||
216 | */ |
||
217 | protected function initOutputInterface(string $data):QROutputInterface{ |
||
233 | |||
234 | /** |
||
235 | * checks if a string qualifies as numeric |
||
236 | * |
||
237 | * @param string $string |
||
238 | * |
||
239 | * @return bool |
||
240 | */ |
||
241 | public function isNumber(string $string):bool { |
||
244 | |||
245 | /** |
||
246 | * checks if a string qualifies as alphanumeric |
||
247 | * |
||
248 | * @param string $string |
||
249 | * |
||
250 | * @return bool |
||
251 | */ |
||
252 | public function isAlphaNum(string $string):bool { |
||
255 | |||
256 | /** |
||
257 | * checks is a given $string matches the characters of a given $charmap, returns false on the first invalid occurence. |
||
258 | * |
||
259 | * @param string $string |
||
260 | * @param array $charmap |
||
261 | * |
||
262 | * @return bool |
||
263 | */ |
||
264 | protected function checkString(string $string, array $charmap):bool{ |
||
275 | |||
276 | /** |
||
277 | * checks if a string qualifies as Kanji |
||
278 | * |
||
279 | * @param string $string |
||
280 | * |
||
281 | * @return bool |
||
282 | */ |
||
283 | public function isKanji(string $string):bool { |
||
299 | |||
300 | /** |
||
301 | * a dummy |
||
302 | * |
||
303 | * @param $data |
||
304 | * |
||
305 | * @return bool |
||
306 | */ |
||
307 | protected function isByte(string $data):bool{ |
||
310 | |||
311 | } |
||
312 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.