SluggerFilter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A filter() 0 3 2
A __construct() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Common\Validation;
6
7
use Laminas\Filter\Exception;
8
use Laminas\Filter\FilterInterface;
9
use Symfony\Component\String\Slugger;
10
11
use function is_string;
12
13
class SluggerFilter implements FilterInterface
14
{
15
    private Slugger\SluggerInterface $slugger;
16
17 9
    public function __construct(?Slugger\SluggerInterface $slugger = null)
18
    {
19 9
        $this->slugger = $slugger ?: new Slugger\AsciiSlugger();
20
    }
21
22
    /**
23
     * Returns the result of filtering $value
24
     *
25
     * @param  mixed $value
26
     * @throws Exception\RuntimeException If filtering $value is impossible
27
     * @return mixed
28
     */
29 9
    public function filter($value)
30
    {
31 9
        return is_string($value) ? (string) $this->slugger->slug($value) : $value;
32
    }
33
}
34