Passed
Pull Request — master (#343)
by Alejandro
05:42
created

SluggerFilter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 20
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A filter() 0 3 2
A __construct() 0 3 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Common\Validation;
5
6
use Cocur\Slugify;
7
use Zend\Filter\Exception;
8
use Zend\Filter\FilterInterface;
9
10
class SluggerFilter implements FilterInterface
11
{
12
    /** @var Slugify\SlugifyInterface */
13
    private $slugger;
14
15 15
    public function __construct(?Slugify\SlugifyInterface $slugger = null)
16
    {
17 15
        $this->slugger = $slugger ?: new Slugify\Slugify(['lowercase' => false]);
18
    }
19
20
    /**
21
     * Returns the result of filtering $value
22
     *
23
     * @param  mixed $value
24
     * @throws Exception\RuntimeException If filtering $value is impossible
25
     * @return mixed
26
     */
27 13
    public function filter($value)
28
    {
29 13
        return ! empty($value) ? $this->slugger->slugify($value) : null;
30
    }
31
}
32