Completed
Branch feature/multi_search_query (65c5f9)
by Alexey
01:57
created

MultiQuery::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace Bardex\Elastic;
3
4
5
class MultiQuery
6
{
7
    /**
8
     * @var \Elasticsearch\Client $client
9
     */
10
    protected $elastic;
11
12
    protected $queryList = [];
13
14
    /**
15
     * Логгер
16
     * @var \Psr\Log\LoggerInterface $logger
17
     */
18
    protected $logger;
19
20
21
    public function __construct(\Elasticsearch\Client $elastic)
22
    {
23
        $this->elastic = $elastic;
24
        $this->logger = new \Psr\Log\NullLogger;
25
    }
26
27
    /**
28
     * @param Query $query
29
     * @return $this
30
     */
31
    public function addQuery( Query $query ) {
32
        $this->queryList[] = $query;
33
        return $this;
34
    }
35
36
    public function fetchAll()
37
    {
38
        $query = $this->getQuery();
39
        $rows = $this->elastic->msearch($query);
0 ignored issues
show
Unused Code introduced by
$rows is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
40
    }
41
42
    public function getQuery()
43
    {
44
        $params = ['body' => []];
45
        foreach ($this->queryList as $query)
46
        {
47
            $query = $query->getQuery();
48
            $params['body'][] = [
49
                'index' => $query['index'],
50
                'type'  => $query['type'],
51
            ];
52
            if (!empty($query['body']['query']))
53
            {
54
                $params['body'][] = [
55
                    'query' => $query['body']['query'],
56
                ];
57
            }
58
        }
59
        return $params;
60
    }
61
}