ElasticsearchServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 7
c 2
b 0
f 0
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A registerBindings() 0 7 1
1
<?php namespace Nord\Lumen\Elasticsearch;
2
3
use Elasticsearch\ClientBuilder;
4
use Illuminate\Support\ServiceProvider;
5
use Nord\Lumen\Elasticsearch\Contracts\ElasticsearchServiceContract;
6
7
class ElasticsearchServiceProvider extends ServiceProvider
8
{
9
    protected const CONFIG_KEY = 'elasticsearch';
10
11
12
    /**
13
     * @inheritdoc
14
     */
15
    public function register()
16
    {
17
        /** @noinspection PhpUndefinedMethodInspection */
18
        $this->app->/** @scrutinizer ignore-call */ configure(self::CONFIG_KEY);
19
20
        $this->registerBindings();
21
    }
22
23
24
    /**
25
     * Register bindings.
26
     */
27
    protected function registerBindings()
28
    {
29
        /** @noinspection PhpUndefinedMethodInspection */
30
        $config = $this->app['config']->get('elasticsearch', []);
31
32
        $this->app->/** @scrutinizer ignore-call */ singleton(ElasticsearchServiceContract::class, function () use ($config) {
33
            return new ElasticsearchService(ClientBuilder::fromConfig($config));
34
        });
35
    }
36
}
37