MultiResultSet::merge()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 12
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
    /**
30
     * @param string $name
31
     *
32
     * @return bool
33
     */
34
    public function hasResultSet($name)
35
    {
36
        return isset($this->result[$name]);
37
    }
38
39
    /**
40
     * @param string $name
41
     *
42
     * @return SimpleResultSet
43
     */
44
    public function getResultSet($name)
45
    {
46
        if (!$this->hasResultSet($name)) {
47
            throw new \InvalidArgumentException(sprintf('Result set with name "%s" not exists.', $name));
48
        }
49
50
        return $this->result[$name];
51
    }
52
}
53