Passed
Push — v5 ( abf6c2...81dcab )
by smiley
01:49
created

ECICharset   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 65
c 1
b 0
f 0
dl 0
loc 88
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 2 1
A __construct() 0 7 2
A getID() 0 2 1
1
<?php
2
/**
3
 * Class ECICharset
4
 *
5
 * @filesource   ECICharset.php
6
 * @created      21.01.2021
7
 * @package      chillerlan\QRCode\Common
8
 * @author       smiley <[email protected]>
9
 * @copyright    2021 smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\QRCode\Common;
14
15
use InvalidArgumentException;
16
use function array_key_exists;
17
18
class ECICharset{
19
20
	public const CP437                 = 0;  // Code page 437, DOS Latin US
21
	public const ISO_IEC_8859_1_GLI    = 1;  // GLI encoding with characters 0 to 127 identical to ISO/IEC 646 and characters 128 to 255 identical to ISO 8859-1
22
	public const CP437_WO_GLI          = 2;  // An equivalent code table to CP437, without the return-to-GLI 0 logic
23
	public const ISO_IEC_8859_1        = 3;  // Latin-1 (Default)
24
	public const ISO_IEC_8859_2        = 4;  // Latin-2
25
	public const ISO_IEC_8859_3        = 5;  // Latin-3
26
	public const ISO_IEC_8859_4        = 6;  // Latin-4
27
	public const ISO_IEC_8859_5        = 7;  // Latin/Cyrillic
28
	public const ISO_IEC_8859_6        = 8;  // Latin/Arabic
29
	public const ISO_IEC_8859_7        = 9;  // Latin/Greek
30
	public const ISO_IEC_8859_8        = 10; // Latin/Hebrew
31
	public const ISO_IEC_8859_9        = 11; // Latin-5
32
	public const ISO_IEC_8859_10       = 12; // Latin-6
33
	public const ISO_IEC_8859_11       = 13; // Latin/Thai
34
	// 14 reserved
35
	public const ISO_IEC_8859_13       = 15; // Latin-7 (Baltic Rim)
36
	public const ISO_IEC_8859_14       = 16; // Latin-8 (Celtic)
37
	public const ISO_IEC_8859_15       = 17; // Latin-9
38
	public const ISO_IEC_8859_16       = 18; // Latin-10
39
	// 19 reserved
40
	public const SHIFT_JIS             = 20; // JIS X 0208 Annex 1 + JIS X 0201
41
	public const WINDOWS_1250_LATIN_2  = 21; // Superset of Latin-2, Central Europe
42
	public const WINDOWS_1251_CYRILLIC = 22; // Latin/Cyrillic
43
	public const WINDOWS_1252_LATIN_1  = 23; // Superset of Latin-1
44
	public const WINDOWS_1256_ARABIC   = 24;
45
	public const ISO_IEC_10646_UCS_2   = 25; // High order byte first (UTF-16BE)
46
	public const ISO_IEC_10646_UTF_8   = 26; // UTF-8
47
	public const ISO_IEC_646_1991      = 27; // International Reference Version of ISO 7-bit coded character set (US-ASCII)
48
	public const BIG5                  = 28; // Big 5 (Taiwan) Chinese Character Set
49
	public const GB18030               = 29; // GB (PRC) Chinese Character Set
50
	public const EUC_KR                = 30; // Korean Character Set
51
52
	/**
53
	 * map of charset id -> name
54
	 *
55
	 * @see \mb_list_encodings()
56
	 */
57
	public const MB_ENCODINGS = [
58
		self::CP437                 => null,
59
		self::ISO_IEC_8859_1_GLI    => null,
60
		self::CP437_WO_GLI          => null,
61
		self::ISO_IEC_8859_1        => 'ISO-8859-1',
62
		self::ISO_IEC_8859_2        => 'ISO-8859-2',
63
		self::ISO_IEC_8859_3        => 'ISO-8859-3',
64
		self::ISO_IEC_8859_4        => 'ISO-8859-4',
65
		self::ISO_IEC_8859_5        => 'ISO-8859-5',
66
		self::ISO_IEC_8859_6        => 'ISO-8859-6',
67
		self::ISO_IEC_8859_7        => 'ISO-8859-7',
68
		self::ISO_IEC_8859_8        => 'ISO-8859-8',
69
		self::ISO_IEC_8859_9        => 'ISO-8859-9',
70
		self::ISO_IEC_8859_10       => 'ISO-8859-10',
71
		self::ISO_IEC_8859_11       => null,
72
		self::ISO_IEC_8859_13       => 'ISO-8859-13',
73
		self::ISO_IEC_8859_14       => 'ISO-8859-14',
74
		self::ISO_IEC_8859_15       => 'ISO-8859-15',
75
		self::ISO_IEC_8859_16       => 'ISO-8859-16',
76
		self::SHIFT_JIS             => 'SJIS',
77
		self::WINDOWS_1250_LATIN_2  => null, // @see https://www.php.net/manual/en/function.mb-convert-encoding.php#112547
78
		self::WINDOWS_1251_CYRILLIC => 'Windows-1251',
79
		self::WINDOWS_1252_LATIN_1  => 'Windows-1252',
80
		self::WINDOWS_1256_ARABIC   => null, // @see https://stackoverflow.com/a/8592995
81
		self::ISO_IEC_10646_UCS_2   => 'UTF-16BE',
82
		self::ISO_IEC_10646_UTF_8   => 'UTF-8',
83
		self::ISO_IEC_646_1991      => 'ASCII',
84
		self::BIG5                  => 'BIG-5',
85
		self::GB18030               => 'GB18030',
86
		self::EUC_KR                => 'EUC-KR',
87
	];
88
89
	private int $charsetID;
90
91
	public function __construct(int $charsetID){
92
93
		if(!array_key_exists($charsetID, self::MB_ENCODINGS)){
94
			throw new InvalidArgumentException('invalid charset id: '.$charsetID);
95
		}
96
97
		$this->charsetID = $charsetID;
98
	}
99
100
	public function getID():int{
101
		return $this->charsetID;
102
	}
103
104
	public function getName():?string{
105
		return self::MB_ENCODINGS[$this->charsetID];
106
	}
107
108
}
109