Passed
Push — v5 ( 93618e...84eb31 )
by smiley
01:52
created

FormatInformation::getDataMask()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
/**
3
 * Class FormatInformation
4
 *
5
 * @created      24.01.2021
6
 * @author       ZXing Authors
7
 * @author       Smiley <[email protected]>
8
 * @copyright    2021 Smiley
9
 * @license      Apache-2.0
10
 */
11
12
namespace chillerlan\QRCode\Common;
13
14
/**
15
 * <p>Encapsulates a QR Code's format information, including the data mask used and
16
 * error correction level.</p>
17
 *
18
 * @author Sean Owen
19
 * @see    \chillerlan\QRCode\Common\ErrorCorrectionLevel
20
 */
21
final class FormatInformation{
22
23
	public const MASK_QR = 0x5412;
24
25
	/**
26
	 * See ISO 18004:2006, Annex C, Table C.1
27
	 *
28
	 * [data bits, sequence after masking]
29
	 */
30
	public const DECODE_LOOKUP = [
31
		[0x00, 0x5412],
32
		[0x01, 0x5125],
33
		[0x02, 0x5E7C],
34
		[0x03, 0x5B4B],
35
		[0x04, 0x45F9],
36
		[0x05, 0x40CE],
37
		[0x06, 0x4F97],
38
		[0x07, 0x4AA0],
39
		[0x08, 0x77C4],
40
		[0x09, 0x72F3],
41
		[0x0A, 0x7DAA],
42
		[0x0B, 0x789D],
43
		[0x0C, 0x662F],
44
		[0x0D, 0x6318],
45
		[0x0E, 0x6C41],
46
		[0x0F, 0x6976],
47
		[0x10, 0x1689],
48
		[0x11, 0x13BE],
49
		[0x12, 0x1CE7],
50
		[0x13, 0x19D0],
51
		[0x14, 0x0762],
52
		[0x15, 0x0255],
53
		[0x16, 0x0D0C],
54
		[0x17, 0x083B],
55
		[0x18, 0x355F],
56
		[0x19, 0x3068],
57
		[0x1A, 0x3F31],
58
		[0x1B, 0x3A06],
59
		[0x1C, 0x24B4],
60
		[0x1D, 0x2183],
61
		[0x1E, 0x2EDA],
62
		[0x1F, 0x2BED],
63
	];
64
65
	private int $errorCorrectionLevel;
66
	private int $dataMask;
67
68
	public function __construct(int $formatInfo){
69
		$this->errorCorrectionLevel = ($formatInfo >> 3) & 0x03; // Bits 3,4
70
		$this->dataMask             = ($formatInfo & 0x07); // Bottom 3 bits
71
	}
72
73
	public function getErrorCorrectionLevel():EccLevel{
74
		return new EccLevel($this->errorCorrectionLevel);
75
	}
76
77
	public function getDataMask():MaskPattern{
78
		return new MaskPattern($this->dataMask);
79
	}
80
81
}
82
83