Completed
Push — master ( 5b8e9d...952218 )
by Nicolas
02:59
created

AbstractSuggest::setRegex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Elastica\Suggest;
4
5
use Elastica\Exception\InvalidException;
6
use Elastica\NameableInterface;
7
use Elastica\Param;
8
9
/**
10
 * Class AbstractSuggestion.
11
 */
12
abstract class AbstractSuggest extends Param implements NameableInterface
13
{
14
    /**
15
     * @var string the name of this suggestion
16
     */
17
    protected $_name;
18
19
    /**
20
     * @param string $name
21
     * @param string $field
22
     */
23
    public function __construct($name, $field)
24
    {
25
        $this->setName($name);
26
        $this->setField($field);
27
    }
28
29
    /**
30
     * Suggest text must be set either globally or per suggestion.
31
     *
32
     * @param string $text
33
     *
34
     * @return $this
35
     */
36
    public function setText($text)
37
    {
38
        return $this->_setRawParam('text', $text);
39
    }
40
41
    /**
42
     * Suggest prefix must be set either globally or per suggestion.
43
     *
44
     * @param string $text
0 ignored issues
show
Bug introduced by
There is no parameter named $text. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
45
     *
46
     * @return $this
47
     */
48
    public function setPrefix($prefix)
49
    {
50
        return $this->_setRawParam('prefix', $prefix);
51
    }
52
53
    /**
54
     * Suggest regex must be set either globally or per suggestion.
55
     *
56
     * @param string $text
0 ignored issues
show
Bug introduced by
There is no parameter named $text. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
57
     *
58
     * @return $this
59
     */
60
    public function setRegex($regex)
61
    {
62
        return $this->_setRawParam('regex', $regex);
63
    }
64
65
    /**
66
     * Expects one of the next params: max_determinized_states - defaults to 10000,
67
     * flags are ALL (default), ANYSTRING, COMPLEMENT, EMPTY, INTERSECTION, INTERVAL, or NONE.
68
     *
69
     * @param array $value
70
     *
71
     * @return $this
72
     */
73
    public function setRegexOptions(array $value)
74
    {
75
        return $this->setParam('regex', $value);
76
    }
77
78
    /**
79
     * @param string $field
80
     *
81
     * @return $this
82
     */
83
    public function setField($field)
84
    {
85
        return $this->setParam('field', $field);
86
    }
87
88
    /**
89
     * @param int $size
90
     *
91
     * @return $this
92
     */
93
    public function setSize($size)
94
    {
95
        return $this->setParam('size', $size);
96
    }
97
98
    /**
99
     * @param int $size maximum number of suggestions to be retrieved from each shard
100
     *
101
     * @return $this
102
     */
103
    public function setShardSize($size)
104
    {
105
        return $this->setParam('shard_size', $size);
106
    }
107
108
    /**
109
     * Sets the name of the suggest. It is automatically set by
110
     * the constructor.
111
     *
112
     * @param string $name The name of the suggest
113
     *
114
     * @throws \Elastica\Exception\InvalidException If name is empty
115
     *
116
     * @return $this
117
     */
118
    public function setName($name)
119
    {
120
        if (empty($name)) {
121
            throw new InvalidException('Suggest name has to be set');
122
        }
123
        $this->_name = $name;
124
125
        return $this;
126
    }
127
128
    /**
129
     * Retrieve the name of this suggestion.
130
     *
131
     * @return string
132
     */
133
    public function getName()
134
    {
135
        return $this->_name;
136
    }
137
}
138