Completed
Push — master ( d8a2fe...e3b3f5 )
by Konstantin
03:02
created

MultiResultSet::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Brouzie\Sphinxy\Query;
4
5
/**
6
 * @method SimpleResultSet[] getIterator()
7
 */
8
class MultiResultSet extends ResultSet
9
{
10
    public function __construct(array $result, array $rawMeta)
11
    {
12 3
        parent::__construct(array_map(function ($result) {
13 3
            return new SimpleResultSet($result);
14 3
        }, $result), $rawMeta);
15 3
    }
16
17
    public function merge(self $multiResultSet)
18
    {
19
        foreach ($multiResultSet as $name => $resultSet) {
20
            if (is_string($name)) {
21
                $this->result[$name] = $resultSet;
22
                //TODO: save meta
23
            } else {
24
                $this->result[] = $resultSet;
25
            }
26
        }
27
    }
28
29
    public function hasResultSet($name)
30
    {
31
        return isset($this->result[$name]);
32
    }
33
34
    public function getResultSet($name)
35
    {
36
        if (!$this->hasResultSet($name)) {
37
            throw new \InvalidArgumentException(sprintf('Result set with name "%s" not exists.', $name));
38
        }
39
40
        return $this->result[$name];
41
    }
42
}
43