Passed
Branch master (8cb5b2)
by Christopher
04:33 queued 12s
created

ElasticsearchManager::suggest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
2
namespace Triadev\Leopard;
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
4
use Elasticsearch\Client;
5
use Elasticsearch\Common\Exceptions\Missing404Exception;
6
use Triadev\Es\Contract\ElasticsearchContract;
7
use Triadev\Leopard\Business\Dsl\Search;
8
use Triadev\Leopard\Business\Dsl\Suggestion;
9
use Triadev\Leopard\Business\Mapping\Builder;
10
use Triadev\Leopard\Contract\ElasticsearchManagerContract;
11
use Triadev\Leopard\Contract\Repository\ElasticsearchRepositoryContract;
12
13
class ElasticsearchManager implements ElasticsearchManagerContract
0 ignored issues
show
Coding Style Documentation introduced by
Missing class doc comment
Loading history...
14
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class ElasticsearchManager
Loading history...
15
    /** @var Client */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
16
    private $esClient;
1 ignored issue
show
Coding Style introduced by
Private member variable "esClient" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
Coding Style introduced by
Private member variable "esClient" must be prefixed with an underscore
Loading history...
17
    
18
    /**
19
     * ElasticsearchManager constructor.
20
     * @param ElasticsearchContract $elasticsearch
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
21
     */
22 43
    public function __construct(ElasticsearchContract $elasticsearch)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
23
    {
24 43
        $this->esClient = $elasticsearch->getClient();
25 43
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end __construct()
Loading history...
26
    
27
    /**
28
     * Get elasticsearch client
29
     *
30
     * @return Client
31
     */
32 12
    public function getEsClient(): Client
33
    {
34 12
        return $this->esClient;
35
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getEsClient()
Loading history...
36
    
37
    /**
38
     * Get es default index
39
     *
40
     * @return string
41
     */
42 4
    public function getEsDefaultIndex() : string
43
    {
44 4
        return config('leopard.index');
45
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getEsDefaultIndex()
Loading history...
46
    
47
    /**
48
     * Search
49
     *
50
     * @return Search
51
     */
52 8
    public function search(): Search
53
    {
54 8
        return app()->make(Search::class);
55
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end search()
Loading history...
56
    
57
    /**
58
     * Suggestion
59
     *
60
     * @return Suggestion
61
     */
62 3
    public function suggest() : Suggestion
63
    {
64 3
        return app()->make(Suggestion::class);
65
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end suggest()
Loading history...
66
    
67
    /**
68
     * Repository
69
     *
70
     * @return ElasticsearchRepositoryContract
71
     */
72 1
    public function repository() : ElasticsearchRepositoryContract
73
    {
74 1
        return app(ElasticsearchRepositoryContract::class);
75
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end repository()
Loading history...
76
    
77
    /**
78
     * Map
79
     *
80
     * @param \Closure $blueprint
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
81
     * @param string $index
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
82
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
83
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
84 8
    public function map(\Closure $blueprint, string $index, string $type)
85
    {
86 8
        (new Builder())->create($blueprint, $index, $type);
87 8
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end map()
Loading history...
88
    
89
    /**
90
     * Search statement
91
     *
92
     * @param array $params
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
93
     * @return array
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
94
     */
95 2
    public function searchStatement(array $params) : array
96
    {
97 2
        return $this->esClient->search($params);
98
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end searchStatement()
Loading history...
99
    
100
    /**
101
     * Put mapping statement
102
     *
103
     * @param array $params
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
104
     * @return array
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
105
     */
106 8
    public function putMappingStatement(array $params): array
107
    {
108 8
        return $this->esClient->indices()->putMapping($params);
109
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end putMappingStatement()
Loading history...
110
    
111
    /**
112
     * Index statement
113
     *
114
     * @param array $params
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
115
     * @return array
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
116
     */
117 7
    public function indexStatement(array $params) : array
118
    {
119 7
        return $this->esClient->index($params);
120
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end indexStatement()
Loading history...
121
    
122
    /**
123
     * Update statement
124
     *
125
     * @param array $params
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
126
     * @return array
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
127
     */
128 1
    public function updateStatement(array $params) : array
129
    {
130 1
        return $this->esClient->update($params);
131
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end updateStatement()
Loading history...
132
    
133
    /**
134
     * Exist statement
135
     *
136
     * @param array $params
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
137
     * @return bool
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
138
     */
139 1
    public function existStatement(array $params) : bool
140
    {
141 1
        return $this->esClient->exists($params);
142
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end existStatement()
Loading history...
143
    
144
    /**
145
     * Delete statement
146
     *
147
     * @param array $params
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
148
     * @return array
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
149
     */
150 1
    public function deleteStatement(array $params) : array
151
    {
152 1
        return $this->esClient->delete($params);
153
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end deleteStatement()
Loading history...
154
    
155
    /**
156
     * Get statement
157
     *
158
     * @param array $params
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
159
     * @return array|null
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
160
     */
161 6
    public function getStatement(array $params) : ?array
162
    {
163
        try {
164 6
            return $this->esClient->get($params);
165 6
        } catch (Missing404Exception $e) {
166 6
            return null;
167
        }
168
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getStatement()
Loading history...
169
    
170
    /**
171
     * Suggest statement
172
     *
173
     * @param array $params
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
174
     * @return array
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
175
     */
176
    public function suggestStatement(array $params): array
177
    {
178
        return $this->esClient->suggest($params);
179
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end suggestStatement()
Loading history...
180
    
181
    /**
182
     * Bulk statement
183
     *
184
     * @param array $params
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
185
     * @return array
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
186
     */
187 3
    public function bulkStatement(array $params): array
188
    {
189 3
        return $this->esClient->bulk($params);
190
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end bulkStatement()
Loading history...
191
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
192