These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Elastica\Query; |
||
3 | |||
4 | use Elastica\Exception\InvalidException; |
||
5 | |||
6 | /** |
||
7 | * SpanNear query. |
||
8 | * |
||
9 | * @author Marek Hernik <[email protected]> |
||
10 | * |
||
11 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-near-query.html |
||
12 | */ |
||
13 | class SpanNear extends AbstractSpanQuery |
||
14 | { |
||
15 | /** |
||
16 | * Constructs a SpanNear query object. |
||
17 | * |
||
18 | * @param AbstractSpanQuery[] $clauses OPTIONAL |
||
19 | * @param int $slop OPTIONAL maximum proximity |
||
20 | * @param bool $inOrder OPTIONAL true if order of searched clauses is important |
||
21 | */ |
||
22 | public function __construct($clauses = [], $slop = 1, $inOrder = false) |
||
23 | { |
||
24 | View Code Duplication | if (!empty($clauses)) { |
|
0 ignored issues
–
show
|
|||
25 | foreach ($clauses as $clause) { |
||
26 | if (!is_subclass_of($clause, AbstractSpanQuery::class)) { |
||
0 ignored issues
–
show
|
|||
27 | throw new InvalidException( |
||
28 | 'Invalid parameter. Has to be array or instance of Elastica\Query\SpanQuery' |
||
29 | ); |
||
30 | } |
||
31 | } |
||
32 | } |
||
33 | $this->setParams(['clauses' => $clauses]); |
||
34 | $this->setSlop($slop); |
||
35 | $this->setInOrder($inOrder); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param int $slop |
||
40 | */ |
||
41 | public function setSlop($slop) |
||
42 | { |
||
43 | $this->setParam('slop', $slop); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param bool $inOrder |
||
48 | */ |
||
49 | public function setInOrder($inOrder) |
||
50 | { |
||
51 | $this->setParam('in_order', $inOrder); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Add clause part to query. |
||
56 | * |
||
57 | * @param AbstractSpanQuery $clause |
||
58 | * |
||
59 | * @throws InvalidException If not valid query |
||
60 | * |
||
61 | * @return $this |
||
62 | */ |
||
63 | View Code Duplication | public function addClause($clause) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
64 | { |
||
65 | if (!is_subclass_of($clause, AbstractSpanQuery::class)) { |
||
0 ignored issues
–
show
|
|||
66 | throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\SpanQuery'); |
||
67 | } |
||
68 | |||
69 | return $this->addParam('clauses', $clause); |
||
70 | } |
||
71 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.