FilterUtil   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 24
ccs 6
cts 6
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A filterFromConfigValue() 0 4 3
A sanitize() 0 3 1
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