Passed
Pull Request — master (#1)
by Christopher
05:53
created

ElasticsearchDsl   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 40
ccs 6
cts 10
cp 0.6
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A suggest() 0 4 1
A getElasticsearch() 0 3 1
A getEsClient() 0 3 1
A search() 0 4 1
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 7
    public function search(?OngrSearch $search = null): Search
35
    {
36 7
        return app()->makeWith(Search::class, [
37 7
            '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