FilterFactory::create()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
ccs 7
cts 7
cp 1
crap 3
1
<?php
2
/**
3
 * File: FilterFactory.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\Otomoto\App\Stats\Filter;
10
11
use MSlwk\Otomoto\App\Exception\NoSuchFilterException;
12
use MSlwk\Otomoto\App\Stats\Filter\Validator\YearFilterValidator;
13
14
/**
15
 * Class FilterFactory
16
 * @package MSlwk\Otomoto\App\Stats\Filter
17
 */
18
class FilterFactory
19
{
20
    /**
21
     * @param string $filterName
22
     * @param string $value
23
     * @return FilterInterface
24
     * @throws NoSuchFilterException
25
     */
26 3
    public function create(string $filterName, string $value): FilterInterface
27
    {
28 3
        switch ($filterName) {
29 3
            case 'from':
30 1
                return new FromYearFilter(new YearFilterValidator(), $value);
31 2
            case 'to':
32 1
                return new ToYearFilter(new YearFilterValidator(), $value);
33
            default:
34 1
                throw new NoSuchFilterException('Chosen filter implementation doesn\'t exist');
35
36
        }
37
    }
38
}
39