StringTrim   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 33
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A filterSingle() 0 15 4
1
<?php
2
declare(strict_types=1);
3
namespace Sirius\Filtration\Filter;
4
5
class StringTrim extends AbstractFilter
6
{
7
    const OPTION_CHARACTERS = 'characters';
8
9
    const OPTION_SIDE = 'side';
10
11
    const VALUE_SIDE_LEFT = 'left';
12
13
    const VALUE_SIDE_RIGHT = 'right';
14
15
    const VALUE_SIDE_BOTH = 'both';
16
17
    protected $options = [
18
        self::OPTION_SIDE => self::VALUE_SIDE_BOTH,
19
        self::OPTION_CHARACTERS => " \n\r\t"
20
    ];
21
22 15
    public function filterSingle($value, string $valueIdentifier = null)
23
    {
24
        // not a string, move along
25 15
        if (! is_string($value)) {
26 1
            return $value;
27
        }
28
        
29 14
        $function = '\trim';
30 14
        if ($this->options['side'] == 'left') {
31 3
            $function = '\ltrim';
32 13
        } elseif ($this->options['side'] == 'right') {
33 3
            $function = '\rtrim';
34
        }
35 14
        return call_user_func($function, $value, $this->options['characters']);
36
    }
37
}
38