Completed
Pull Request — master (#12)
by Adam
03:38
created

Index::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
3
namespace BestServedCold\LaravelZendSearch\Laravel;
4
5
use BestServedCold\LaravelZendSearch\Lucene\Index as LuceneIndex;
6
use Illuminate\Config\Repository;
7
use Illuminate\Filesystem\Filesystem;
8
9
/**
10
 * Class Index
11
 * @package BestServedCold\LaravelZendSearch\Laravel
12
 */
13
class Index extends LuceneIndex
14
{
15
    /**
16
     * Index constructor.
17
     * @param Repository $config
18
     */
19 21
    public function __construct(Filter $filter, Repository $config, Filesystem $filesystem)
20
    {
21 21
        $this->setPath($config->get('search.index.path'));
22 21
        $this->addFilters($config->get('search.filters'), $filesystem);
23
24 21
        parent::__construct($filter);
25 21
    }
26
27
    /**
28
     * @param array $filters
29
     */
30 21
    private function addFilters(array $filters = [], Filesystem $filesystem)
31
    {
32 21
        foreach ($filters as $filter => $switch) {
33 21
            if ($switch !== false) {
34 21
                if ($filter === 'StopWords' && ! is_array($switch)) {
35 21
                    Filter::addStopWordFilter($switch === true ? 'en' : $switch, $filesystem);
36 21
                } else {
37 21
                    Filter::addFilter($filter, $switch === true ? [] : [$switch]);
38
                }
39 21
            }
40 21
        }
41 21
    }
42
}
43