Completed
Push — master ( 473a0b...a42475 )
by ignace nyamagana
05:17 queued 03:11
created

functions.php ➔ bom_match()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 14
ccs 6
cts 6
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
* This file is part of the League.csv library
4
*
5
* @license http://opensource.org/licenses/MIT
6
* @link https://github.com/thephpleague/csv/
7
* @version 9.0.0
8
* @package League.csv
9
*
10
* For the full copyright and license information, please view the LICENSE
11
* file that was distributed with this source code.
12
*/
13
declare(strict_types=1);
14
15
namespace League\Csv;
16
17
use ReflectionClass;
18
19
/**
20
 * Returns the BOM sequence found at the start of the string
21
 *
22
 * If no valid BOM sequence is found an empty string is returned
23
 *
24
 * @param string $str
25
 *
26
 * @return string
27
 */
28
function bom_match(string $str): string
29
{
30 162
    static $list;
31
32 162
    $list = $list ?? (new ReflectionClass(BOM::class))->getConstants();
33
34 162
    foreach ($list as $sequence) {
35 162
        if (0 === strpos($str, $sequence)) {
36 94
            return $sequence;
37
        }
38
    }
39
40 136
    return '';
41
}
42
43
/**
44
 * Tell whether the submitted sequence is a valid BOM sequence
45
 *
46
 * @param string $sequence
47
 *
48
 * @return bool
49
 */
50
function is_bom(string $sequence): bool
51
{
52 6
    static $list;
53
54 6
    $list = $list ?? (new ReflectionClass(BOM::class))->getConstants();
55
56 6
    return in_array($sequence, $list, true);
57
}
58