Completed
Pull Request — master (#1)
by Christopher
08:14 queued 02:30
created

ElasticsearchDsl::getElasticsearch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Triadev\Es\Dsl;
3
4
use Elasticsearch\Client;
5
use ONGR\ElasticsearchDSL\Search as OngrSearch;
6
use Triadev\Es\Contract\ElasticsearchContract;
7
use Triadev\Es\Dsl\Contract\ElasticsearchDslContract;
8
use Triadev\Es\Dsl\Dsl\Search;
9
use Triadev\Es\Dsl\Dsl\Suggestion;
10
11
class ElasticsearchDsl implements ElasticsearchDslContract
12
{
13
    /**
14
     * Get es client
15
     *
16
     * @return Client
17
     */
18
    public function getEsClient(): Client
19
    {
20
        return $this->getElasticsearch()->getClient();
21
    }
22
    
23
    private function getElasticsearch() : ElasticsearchContract
24
    {
25
        return app(ElasticsearchContract::class);
26
    }
27
    
28
    /**
29
     * Search
30
     *
31
     * @param OngrSearch|null $search
32
     * @return Search
33
     */
34 13
    public function search(?OngrSearch $search = null): Search
35
    {
36 13
        return app()->makeWith(Search::class, [
37 13
            'search' => $search
38
        ]);
39
    }
40
    
41
    /**
42
     * Suggestion
43
     *
44
     * @param OngrSearch|null $search
45
     * @return Suggestion
46
     */
47 3
    public function suggest(?OngrSearch $search = null): Suggestion
48
    {
49 3
        return app()->makeWith(Suggestion::class, [
50 3
            'search' => $search
51
        ]);
52
    }
53
}
54