FilterUtil::sanitize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * This file is part of CaptainHook.
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Git\Diff;
13
14
abstract class FilterUtil
15
{
16
    /**
17
     * Converts a value into a valid diff filter array
18
     *
19
     * @param  mixed $value
20
     * @return array<int, string>
21
     */
22 16
    public static function filterFromConfigValue($value): array
23
    {
24 16
        return self::sanitize(
25 16
            is_array($value) ? $value : str_split((string) strtoupper($value === null ? '' : $value))
0 ignored issues
show
Bug introduced by
It seems like is_array($value) ? $valu...== null ? '' : $value)) can also be of type true; however, parameter $data of CaptainHook\App\Git\Diff\FilterUtil::sanitize() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
            /** @scrutinizer ignore-type */ is_array($value) ? $value : str_split((string) strtoupper($value === null ? '' : $value))
Loading history...
26 16
        );
27
    }
28
29
    /**
30
     * Remove all invalid filter options
31
     *
32
     * @param  array<int, string> $data
33
     * @return array<int, string>
34
     */
35 27
    public static function sanitize(array $data): array
36
    {
37 27
        return array_filter($data, fn($e) => in_array($e, ['A', 'C', 'D', 'M', 'R', 'T', 'U', 'X', 'B', '*']));
38
    }
39
}
40