ElasticSearchServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 16
rs 9.9666
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arun
5
 * Date: 2019-07-07
6
 * Time: 13:00
7
 */
8
9
namespace ArunFung\ScoutElasticSearch;
10
11
use ArunFung\ScoutElasticSearch\Console\Commands\CreateElasticSearchIndex;
12
use Illuminate\Support\Facades\Config;
13
use Illuminate\Support\ServiceProvider;
14
use Laravel\Scout\EngineManager;
15
use Elasticsearch\ClientBuilder as ElasticSearchBuilder;
16
17
/**
18
 * Class ElasticSearchServiceProvider
19
 * @package ArunFung\ScoutElasticSearch
20
 */
21
class ElasticSearchServiceProvider extends ServiceProvider
22
{
23
    /**
24
     * Register services.
25
     *
26
     * @return void
27
     */
28
    public function register()
29
    {
30
        $this->mergeConfigFrom(
31
            __DIR__ . '/config/elasticsearch.php', 'elasticsearch'
32
        );
33
    }
34
35
    /**
36
     * Bootstrap services.
37
     *
38
     * @return void
39
     */
40
    public function boot()
41
    {
42
        $this->publishes([
43
            __DIR__ . '/config/elasticsearch.php' => config_path('elasticsearch.php'),
0 ignored issues
show
Bug introduced by
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
            __DIR__ . '/config/elasticsearch.php' => /** @scrutinizer ignore-call */ config_path('elasticsearch.php'),
Loading history...
44
        ]);
45
46
        resolve(EngineManager::class)->extend('elasticsearch', function () {
0 ignored issues
show
Bug introduced by
The function resolve was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        /** @scrutinizer ignore-call */ 
47
        resolve(EngineManager::class)->extend('elasticsearch', function () {
Loading history...
47
            return new ElasticSearchEngine(
48
                ElasticSearchBuilder::create()->setHosts(Config::get('elasticsearch.hosts'))->build(),
49
                Config::get('elasticsearch.index')
50
            );
51
        });
52
53
        if ($this->app->runningInConsole()) {
54
            $this->commands([
55
                CreateElasticSearchIndex::class,
56
            ]);
57
        }
58
    }
59
}
60