Completed
Pull Request — master (#57)
by
unknown
01:40
created

TNTSearchScoutServiceProvider::setAsYouType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace TeamTNT\Scout;
4
5
use Illuminate\Support\ServiceProvider;
6
use Laravel\Scout\EngineManager;
7
use TeamTNT\Scout\Console\ImportCommand;
8
use TeamTNT\TNTSearch\TNTSearch;
9
10
class TNTSearchScoutServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap any application services.
14
     *
15
     * @return void
16
     */
17
    public function boot()
18
    {
19
        $this->app[EngineManager::class]->extend('tntsearch', function () {
20
            $tnt = new TNTSearch();
21
            $driver = config('database.default');
22
            $config = config('scout.tntsearch') + config("database.connections.$driver");
23
24
25
            $tnt->loadConfig($config);
26
            $tnt->setDatabaseHandle(app('db')->connection()->getPdo());
27
            $this->setFuzziness($tnt);
28
            $this->setAsYouType($tnt);
29
30
            return new Engines\TNTSearchEngine($tnt);
31
        });
32
33
        if ($this->app->runningInConsole()) {
0 ignored issues
show
Bug introduced by
The method runningInConsole() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
            $this->commands([
35
                ImportCommand::class,
36
            ]);
37
        }
38
    }
39
40
    private function setFuzziness($tnt)
41
    {
42
        $fuzziness = config('scout.tntsearch.fuzziness');
43
        $prefix_length = config('scout.tntsearch.fuzzy.prefix_length');
44
        $max_expansions = config('scout.tntsearch.fuzzy.max_expansions');
45
        $distance = config('scout.tntsearch.fuzzy.distance');
46
47
48
        $tnt->fuzziness = isset($fuzziness) ? $fuzziness : $tnt->fuzziness;
49
        $tnt->fuzzy_prefix_length = isset($prefix_length) ? $prefix_length : $tnt->fuzzy_prefix_length;
50
        $tnt->fuzzy_max_expansions = isset($max_expansions) ? $max_expansions : $tnt->fuzzy_max_expansions;
51
        $tnt->fuzzy_distance = isset($distance) ? $distance : $tnt->fuzzy_distance;
52
    }
53
54
    private function setAsYouType($tnt)
55
    {
56
        $asYouType = config('scout.tntsearch.asYouType');
57
58
        $tnt->asYouType = isset($asYouType) ? $asYouType : $tnt->asYouType;
59
    }
60
}
61