SluggerFilter::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
ccs 2
cts 2
cp 1
cc 2
nc 1
nop 1
crap 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