Factory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilter() 0 6 1
A supportedException() 0 8 2
A getSupportedFilters() 0 9 1
1
<?php
2
3
namespace BestServedCold\LaravelZendSearch\Lucene\Filter;
4
5
use Doctrine\Instantiator\Exception\InvalidArgumentException;
6
use ZendSearch\Lucene\Analysis\TokenFilter\LowerCase;
7
use ZendSearch\Lucene\Analysis\TokenFilter\LowerCaseUtf8;
8
use ZendSearch\Lucene\Analysis\TokenFilter\ShortWords;
9
use ZendSearch\Lucene\Analysis\TokenFilter\StopWords;
10
use ZendSearch\Lucene\Analysis\TokenFilter\TokenFilterInterface;
11
12
/**
13
 * Class ShortWord
14
 * @package BestServedCold\LaravelZendSearch\Lucene\Filter
15
 */
16
class Factory
17
{
18
    /**
19
     * @param  string $filter
20
     * @param  mixed  $option
21
     * @return TokenFilterInterface
22
     * @throws \InvalidArgumentException
23
     */
24 2
    public static function getFilter($filter, $option)
25
    {
26 2
        $supportedFilters = self::getSupportedFilters();
27 2
        self::supportedException($filter, $supportedFilters);
28 1
        return new $supportedFilters[$filter]($option);
29
    }
30
31
    /**
32
     * @param  string $filter
33
     * @param  array  $supportedFilters
34
     * @throws \InvalidArgumentException
35
     */
36 2
    private static function supportedException($filter, array $supportedFilters)
37
    {
38 2
        if (!array_key_exists($filter, $supportedFilters)) {
39 1
            throw new \InvalidArgumentException(
40 1
                'Filter ['.$filter.'] is not supported by ['.self::class.']'
41 1
            );
42
        }
43 1
    }
44
45
    /**
46
     * @return array
47
     */
48 2
    private static function getSupportedFilters()
49
    {
50
        return [
51 2
            'LowerCase'     => LowerCase::class,
52 2
            'LowerCaseUtf8' => LowerCaseUtf8::class,
53 2
            'ShortWords'    => ShortWords::class,
54
            'StopWords'     => StopWords::class
55 2
        ];
56
    }
57
}
58