Completed
Push — master ( 288915...e045d5 )
by Nenad
13s
created

TNTSearchScoutServiceProvider::setFuzziness()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php namespace TeamTNT\Scout;
2
3
use Engines\TNTSearchEngine;
4
use TeamTNT\TNTSearch\TNTSearch;
5
use Laravel\Scout\EngineManager;
6
use Illuminate\Support\ServiceProvider;
7
use TeamTNT\Scout\Console\ImportCommand;
8
9
class TNTSearchScoutServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap any application services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        $this->app[EngineManager::class]->extend('tntsearch', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
19
            $tnt = new TNTSearch();
20
            
21
            $driver = config('database.default');
22
            $config = config('scout.tntsearch') + config("database.connections.{$driver}");
23
24
            $tnt->loadConfig($config);
25
            $tnt->setDatabaseHandle(app('db')->connection()->getPdo());
26
            
27
            $this->setFuzziness($tnt);
28
            $this->setAsYouType($tnt);
29
30
            return new TNTSearchEngine($tnt);
31
        });
32
33
        if ($this->app->runningInConsole()) {
34
            $this->commands([
35
                ImportCommand::class,
36
            ]);
37
        }
38
    }
39
40
    protected function setFuzziness($tnt)
41
    {
42
        $tnt->fuzziness            = config('scout.tntsearch.fuzziness', $tnt->fuzziness);
43
        $tnt->fuzzy_distance       = config('scout.tntsearch.fuzzy.distance', $tnt->fuzzy_distance);
44
        $tnt->fuzzy_prefix_length  = config('scout.tntsearch.fuzzy.prefix_length', $tnt->fuzzy_prefix_length);
45
        $tnt->fuzzy_max_expansions = config('scout.tntsearch.fuzzy.max_expansions', $tnt->fuzzy_max_expansions);
46
    }
47
48
    protected function setAsYouType($tnt)
49
    {
50
        $tnt->asYouType = config('scout.tntsearch.asYouType', $tnt->asYouType);
51
    }
52
}
53