Passed
Pull Request — master (#11)
by Steve
01:59
created

Sanitizer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 272
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 259
dl 0
loc 272
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDocType() 0 11 2
1
<?php
2
/**
3
 * (c) Steve Nebes <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
declare(strict_types=1);
10
11
namespace SN\DaisyDiff\Xml;
12
13
/**
14
 * Sanitizing methods.
15
 */
16
class Sanitizer
17
{
18
    /** @var string[] */
19
    static $htmlEntities = [
20
        'Aacute'   => '193',
21
        'aacute'   => '225',
22
        'Acirc'    => '194',
23
        'acirc'    => '226',
24
        'acute'    => '180',
25
        'AElig'    => '198',
26
        'aelig'    => '230',
27
        'Agrave'   => '192',
28
        'agrave'   => '224',
29
        'alefsym'  => '8501',
30
        'Alpha'    => '913',
31
        'alpha'    => '945',
32
        'amp'      => '38',
33
        'and'      => '8743',
34
        'ang'      => '8736',
35
        'Aring'    => '197',
36
        'aring'    => '229',
37
        'asymp'    => '8776',
38
        'Atilde'   => '195',
39
        'atilde'   => '227',
40
        'Auml'     => '196',
41
        'auml'     => '228',
42
        'bdquo'    => '8222',
43
        'Beta'     => '914',
44
        'beta'     => '946',
45
        'brvbar'   => '166',
46
        'bull'     => '8226',
47
        'cap'      => '8745',
48
        'Ccedil'   => '199',
49
        'ccedil'   => '231',
50
        'cedil'    => '184',
51
        'cent'     => '162',
52
        'Chi'      => '935',
53
        'chi'      => '967',
54
        'circ'     => '710',
55
        'clubs'    => '9827',
56
        'cong'     => '8773',
57
        'copy'     => '169',
58
        'crarr'    => '8629',
59
        'cup'      => '8746',
60
        'curren'   => '164',
61
        'dagger'   => '8224',
62
        'Dagger'   => '8225',
63
        'darr'     => '8595',
64
        'dArr'     => '8659',
65
        'deg'      => '176',
66
        'Delta'    => '916',
67
        'delta'    => '948',
68
        'diams'    => '9830',
69
        'divide'   => '247',
70
        'Eacute'   => '201',
71
        'eacute'   => '233',
72
        'Ecirc'    => '202',
73
        'ecirc'    => '234',
74
        'Egrave'   => '200',
75
        'egrave'   => '232',
76
        'empty'    => '8709',
77
        'emsp'     => '8195',
78
        'ensp'     => '8194',
79
        'Epsilon'  => '917',
80
        'epsilon'  => '949',
81
        'equiv'    => '8801',
82
        'Eta'      => '919',
83
        'eta'      => '951',
84
        'ETH'      => '208',
85
        'eth'      => '240',
86
        'Euml'     => '203',
87
        'euml'     => '235',
88
        'euro'     => '8364',
89
        'exist'    => '8707',
90
        'fnof'     => '402',
91
        'forall'   => '8704',
92
        'frac12'   => '189',
93
        'frac14'   => '188',
94
        'frac34'   => '190',
95
        'frasl'    => '8260',
96
        'Gamma'    => '915',
97
        'gamma'    => '947',
98
        'ge'       => '8805',
99
        'gt'       => '62',
100
        'harr'     => '8596',
101
        'hArr'     => '8660',
102
        'hearts'   => '9829',
103
        'hellip'   => '8230',
104
        'Iacute'   => '205',
105
        'iacute'   => '237',
106
        'Icirc'    => '206',
107
        'icirc'    => '238',
108
        'iexcl'    => '161',
109
        'Igrave'   => '204',
110
        'igrave'   => '236',
111
        'image'    => '8465',
112
        'infin'    => '8734',
113
        'int'      => '8747',
114
        'Iota'     => '921',
115
        'iota'     => '953',
116
        'iquest'   => '191',
117
        'isin'     => '8712',
118
        'Iuml'     => '207',
119
        'iuml'     => '239',
120
        'Kappa'    => '922',
121
        'kappa'    => '954',
122
        'Lambda'   => '923',
123
        'lambda'   => '955',
124
        'lang'     => '9001',
125
        'laquo'    => '171',
126
        'larr'     => '8592',
127
        'lArr'     => '8656',
128
        'lceil'    => '8968',
129
        'ldquo'    => '8220',
130
        'le'       => '8804',
131
        'lfloor'   => '8970',
132
        'lowast'   => '8727',
133
        'loz'      => '9674',
134
        'lrm'      => '8206',
135
        'lsaquo'   => '8249',
136
        'lsquo'    => '8216',
137
        'lt'       => '60',
138
        'macr'     => '175',
139
        'mdash'    => '8212',
140
        'micro'    => '181',
141
        'middot'   => '183',
142
        'minus'    => '8722',
143
        'Mu'       => '924',
144
        'mu'       => '956',
145
        'nabla'    => '8711',
146
        'nbsp'     => '160',
147
        'ndash'    => '8211',
148
        'ne'       => '8800',
149
        'ni'       => '8715',
150
        'not'      => '172',
151
        'notin'    => '8713',
152
        'nsub'     => '8836',
153
        'Ntilde'   => '209',
154
        'ntilde'   => '241',
155
        'Nu'       => '925',
156
        'nu'       => '957',
157
        'Oacute'   => '211',
158
        'oacute'   => '243',
159
        'Ocirc'    => '212',
160
        'ocirc'    => '244',
161
        'OElig'    => '338',
162
        'oelig'    => '339',
163
        'Ograve'   => '210',
164
        'ograve'   => '242',
165
        'oline'    => '8254',
166
        'Omega'    => '937',
167
        'omega'    => '969',
168
        'Omicron'  => '927',
169
        'omicron'  => '959',
170
        'oplus'    => '8853',
171
        'or'       => '8744',
172
        'ordf'     => '170',
173
        'ordm'     => '186',
174
        'Oslash'   => '216',
175
        'oslash'   => '248',
176
        'Otilde'   => '213',
177
        'otilde'   => '245',
178
        'otimes'   => '8855',
179
        'Ouml'     => '214',
180
        'ouml'     => '246',
181
        'para'     => '182',
182
        'part'     => '8706',
183
        'permil'   => '8240',
184
        'perp'     => '8869',
185
        'Phi'      => '934',
186
        'phi'      => '966',
187
        'Pi'       => '928',
188
        'pi'       => '960',
189
        'piv'      => '982',
190
        'plusmn'   => '177',
191
        'pound'    => '163',
192
        'prime'    => '8242',
193
        'Prime'    => '8243',
194
        'prod'     => '8719',
195
        'prop'     => '8733',
196
        'Psi'      => '936',
197
        'psi'      => '968',
198
        'quot'     => '34',
199
        'radic'    => '8730',
200
        'rang'     => '9002',
201
        'raquo'    => '187',
202
        'rarr'     => '8594',
203
        'rArr'     => '8658',
204
        'rceil'    => '8969',
205
        'rdquo'    => '8221',
206
        'real'     => '8476',
207
        'reg'      => '174',
208
        'rfloor'   => '8971',
209
        'Rho'      => '929',
210
        'rho'      => '961',
211
        'rlm'      => '8207',
212
        'rsaquo'   => '8250',
213
        'rsquo'    => '8217',
214
        'sbquo'    => '8218',
215
        'Scaron'   => '352',
216
        'scaron'   => '353',
217
        'sdot'     => '8901',
218
        'sect'     => '167',
219
        'shy'      => '173',
220
        'Sigma'    => '931',
221
        'sigma'    => '963',
222
        'sigmaf'   => '962',
223
        'sim'      => '8764',
224
        'spades'   => '9824',
225
        'sub'      => '8834',
226
        'sube'     => '8838',
227
        'sum'      => '8721',
228
        'sup'      => '8835',
229
        'sup1'     => '185',
230
        'sup2'     => '178',
231
        'sup3'     => '179',
232
        'supe'     => '8839',
233
        'szlig'    => '223',
234
        'Tau'      => '932',
235
        'tau'      => '964',
236
        'there4'   => '8756',
237
        'Theta'    => '920',
238
        'theta'    => '952',
239
        'thetasym' => '977',
240
        'thinsp'   => '8201',
241
        'THORN'    => '222',
242
        'thorn'    => '254',
243
        'tilde'    => '732',
244
        'times'    => '215',
245
        'trade'    => '8482',
246
        'Uacute'   => '218',
247
        'uacute'   => '250',
248
        'uarr'     => '8593',
249
        'uArr'     => '8657',
250
        'Ucirc'    => '219',
251
        'ucirc'    => '251',
252
        'Ugrave'   => '217',
253
        'ugrave'   => '249',
254
        'uml'      => '168',
255
        'upsih'    => '978',
256
        'Upsilon'  => '933',
257
        'upsilon'  => '965',
258
        'Uuml'     => '220',
259
        'uuml'     => '252',
260
        'weierp'   => '8472',
261
        'Xi'       => '926',
262
        'xi'       => '958',
263
        'Yacute'   => '221',
264
        'yacute'   => '253',
265
        'yen'      => '165',
266
        'Yuml'     => '376',
267
        'yuml'     => '255',
268
        'Zeta'     => '918',
269
        'zeta'     => '950',
270
        'zwj'      => '8205',
271
        'zwnj'     => '8204',
272
    ];
273
274
    /**
275
     * @return string
276
     */
277 16
    public static function getDocType(): string
278
    {
279 16
        $docType = "<!DOCTYPE html [\n";
280
281 16
        foreach (self::$htmlEntities as $entity => $hex) {
282 16
            $docType .= \sprintf('<!ENTITY %s "&#%s;">', $entity, $hex);
283
        }
284
285 16
        $docType .= "]>\n";
286
287 16
        return $docType;
288
    }
289
}
290