Util   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 12
eloc 20
c 0
b 0
f 0
dl 0
loc 36
ccs 18
cts 22
cp 0.8182
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A detectUTFEncoding() 0 22 6
A __construct() 0 7 6
1
<?php
2
3
namespace App\Services;
4
5
class Util
6
{
7 17
    public function __construct()
8
    {
9 17
        defined('UTF8_BOM') || define('UTF8_BOM', chr(0xEF).chr(0xBB).chr(0xBF));
10 17
        defined('UTF16_LITTLE_ENDIAN_BOM') || define('UTF16_LITTLE_ENDIAN_BOM', chr(0xFF).chr(0xFE));
11 17
        defined('UTF16_BIG_ENDIAN_BOM') || define('UTF16_BIG_ENDIAN_BOM', chr(0xFE).chr(0xFF));
12 17
        defined('UTF32_LITTLE_ENDIAN_BOM') || define('UTF32_LITTLE_ENDIAN_BOM', chr(0xFF).chr(0xFE).chr(0x00).chr(0x00));
13 17
        defined('UTF32_BIG_ENDIAN_BOM') || define('UTF32_BIG_ENDIAN_BOM', chr(0x00).chr(0x00).chr(0xFE).chr(0xFF));
14 17
    }
15
16
    /**
17
     * Detects higher UTF encoded strings.
18
     */
19 17
    public function detectUTFEncoding(string $str): ?string
20
    {
21 17
        switch (substr($str, 0, 2)) {
22 17
            case UTF16_BIG_ENDIAN_BOM:
23
                return 'UTF-16BE';
24 17
            case UTF16_LITTLE_ENDIAN_BOM:
25 1
                return 'UTF-16LE';
26
        }
27
28 16
        switch (substr($str, 0, 3)) {
29 16
            case UTF8_BOM:
30
                return 'UTF-8';
31
        }
32
33 16
        switch (substr($str, 0, 4)) {
34 16
            case UTF32_BIG_ENDIAN_BOM:
35
                return 'UTF-32BE';
36 16
            case UTF32_LITTLE_ENDIAN_BOM:
37
                return 'UTF-32LE';
38
        }
39
40 16
        return null;
41
    }
42
}
43