Completed
Push — master ( 8ca7bf...84e03d )
by Adrien
08:54
created

CodePage::getEncodings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Shared;
4
5
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
6
7
class CodePage
8
{
9
    private static $pageArray = [
10
        0 => 'CP1252', //    CodePage is not always correctly set when the xls file was saved by Apple's Numbers program
11
        367 => 'ASCII', //    ASCII
12
        437 => 'CP437', //    OEM US
13
        //720 => 'notsupported', //    OEM Arabic
14
        737 => 'CP737', //    OEM Greek
15
        775 => 'CP775', //    OEM Baltic
16
        850 => 'CP850', //    OEM Latin I
17 75
        852 => 'CP852', //    OEM Latin II (Central European)
18
        855 => 'CP855', //    OEM Cyrillic
19
        857 => 'CP857', //    OEM Turkish
20 75
        858 => 'CP858', //    OEM Multilingual Latin I with Euro
21 1
        860 => 'CP860', //    OEM Portugese
22 74
        861 => 'CP861', //    OEM Icelandic
23 1
        862 => 'CP862', //    OEM Hebrew
24 73
        863 => 'CP863', //    OEM Canadian (French)
25 1
        864 => 'CP864', //    OEM Arabic
26 72
        865 => 'CP865', //    OEM Nordic
27 1
        866 => 'CP866', //    OEM Cyrillic (Russian)
28 71
        869 => 'CP869', //    OEM Greek (Modern)
29 1
        874 => 'CP874', //    ANSI Thai
30 70
        932 => 'CP932', //    ANSI Japanese Shift-JIS
31 1
        936 => 'CP936', //    ANSI Chinese Simplified GBK
32 69
        949 => 'CP949', //    ANSI Korean (Wansung)
33 1
        950 => 'CP950', //    ANSI Chinese Traditional BIG5
34 68
        1200 => 'UTF-16LE', //    UTF-16 (BIFF8)
35 1
        1250 => 'CP1250', //    ANSI Latin II (Central European)
36 67
        1251 => 'CP1251', //    ANSI Cyrillic
37 1
        1252 => 'CP1252', //    ANSI Latin I (BIFF4-BIFF7)
38 66
        1253 => 'CP1253', //    ANSI Greek
39 1
        1254 => 'CP1254', //    ANSI Turkish
40 65
        1255 => 'CP1255', //    ANSI Hebrew
41 1
        1256 => 'CP1256', //    ANSI Arabic
42 64
        1257 => 'CP1257', //    ANSI Baltic
43 1
        1258 => 'CP1258', //    ANSI Vietnamese
44 63
        1361 => 'CP1361', //    ANSI Korean (Johab)
45 1
        10000 => 'MAC', //    Apple Roman
46 62
        10001 => 'CP932', //    Macintosh Japanese
47 1
        10002 => 'CP950', //    Macintosh Chinese Traditional
48 61
        10003 => 'CP1361', //    Macintosh Korean
49 1
        10004 => 'MACARABIC', //    Apple Arabic
50 60
        10005 => 'MACHEBREW', //    Apple Hebrew
51 1
        10006 => 'MACGREEK', //    Macintosh Greek
52 59
        10007 => 'MACCYRILLIC', //    Macintosh Cyrillic
53 1
        10008 => 'CP936', //    Macintosh - Simplified Chinese (GB 2312)
54 58
        10010 => 'MACROMANIA', //    Macintosh Romania
55 1
        10017 => 'MACUKRAINE', //    Macintosh Ukraine
56 57
        10021 => 'MACTHAI', //    Macintosh Thai
57 1
        10029 => 'MACCENTRALEUROPE', //    Macintosh Central Europe
58 56
        10079 => 'MACICELAND', //    Macintosh Icelandic
59 1
        10081 => 'MACTURKISH', //    Macintosh Turkish
60 55
        10082 => 'MACCROATIAN', //    Macintosh Croatian
61 1
        21010 => 'UTF-16LE', //    UTF-16 (BIFF8) This isn't correct, but some Excel writer libraries erroneously use Codepage 21010 for UTF-16LE
62 54
        32768 => 'MAC', //    Apple Roman
63 1
        //32769 => 'unsupported', //    ANSI Latin I (BIFF2-BIFF3)
64 53
        65000 => 'UTF-7', //    Unicode (UTF-7)
65 1
        65001 => 'UTF-8', //    Unicode (UTF-8)
66 52
    ];
67 31
68 51
    /**
69 1
     * Convert Microsoft Code Page Identifier to Code Page Name which iconv
70 50
     * and mbstring understands.
71 1
     *
72 49
     * @param int $codePage Microsoft Code Page Indentifier
73
     *
74 48
     * @return string Code Page Name
75 31
     */
76 18
    public static function numberToName(int $codePage): string
77 1
    {
78 17
        if (array_key_exists($codePage, self::$pageArray)) {
79 1
            return self::$pageArray[$codePage];
80 16
        }
81 1
        if ($codePage == 720 || $codePage == 32769) {
82 15
            throw new PhpSpreadsheetException("Code page $codePage not supported."); //    OEM Arabic
83 1
        }
84 14
85 1
        throw new PhpSpreadsheetException('Unknown codepage: ' . $codePage);
86 13
    }
87 1
88 12
    public static function getEncodings(): array
89 1
    {
90 11
        return self::$pageArray;
91 1
    }
92
}
93