Completed
Pull Request — develop (#17)
by Sam
04:04
created

WildcardQuery::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Nord\Lumen\Elasticsearch\Search\Query\TermLevel;
4
5
use Nord\Lumen\Elasticsearch\Exceptions\InvalidArgument;
6
7
/**
8
 * Class WildcardQuery
9
 * @package Nord\Lumen\Elasticsearch\Search\Query\TermLevel
10
 */
11
class WildcardQuery extends AbstractQuery
12
{
13
14
    use BoostableQuery;
15
16
    /**
17
     * @var string
18
     */
19
    private $value;
20
21
    /**
22
     * @inheritdoc
23
     *
24
     * @throws InvalidArgument
25
     */
26
    public function toArray()
27
    {
28
        if (!isset($this->field) || !isset($this->value)) {
29
            throw new InvalidArgument('"field" and "value" must be set for this type of query');
30
        }
31
32
        $definition = [
33
            'value' => $this->getValue(),
34
        ];
35
36
        if ($this->hasBoost()) {
37
            $definition['boost'] = $this->getBoost();
38
        }
39
40
        return [
41
            'wildcard' => [
42
                $this->getField() => $definition,
43
            ],
44
        ];
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getValue()
51
    {
52
        return $this->value;
53
    }
54
55
    /**
56
     * @param string $value
57
     *
58
     * @return $this
59
     */
60
    public function setValue($value)
61
    {
62
        $this->value = $value;
63
64
        return $this;
65
    }
66
}
67