WildcardQuery::toArray()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 17
rs 9.9666
cc 4
nc 3
nop 0
1
<?php
2
3
namespace Nord\Lumen\Elasticsearch\Search\Query\TermLevel;
4
5
use Nord\Lumen\Elasticsearch\Exceptions\InvalidArgument;
6
use Nord\Lumen\Elasticsearch\Search\Query\Traits\HasBoost;
7
use Nord\Lumen\Elasticsearch\Search\Query\Traits\HasValue;
8
9
/**
10
 * Class WildcardQuery
11
 * @package Nord\Lumen\Elasticsearch\Search\Query\TermLevel
12
 *
13
 * @see     https://www.elastic.co/guide/en/elasticsearch/reference/2.4/query-dsl-wildcard-query.html
14
 */
15
class WildcardQuery extends AbstractQuery
16
{
17
    use HasBoost;
18
    use HasValue;
19
20
    /**
21
     * @inheritdoc
22
     *
23
     * @throws InvalidArgument
24
     */
25
    public function toArray()
26
    {
27
        if ($this->field === null || $this->value === null) {
28
            throw new InvalidArgument('"field" and "value" must be set for this type of query');
29
        }
30
31
        $definition = [
32
            'value' => $this->getValue(),
33
        ];
34
35
        if ($this->hasBoost()) {
36
            $definition['boost'] = $this->getBoost();
37
        }
38
39
        return [
40
            'wildcard' => [
41
                $this->getField() => $definition,
42
            ],
43
        ];
44
    }
45
}
46