MultiResultSet   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 22.22%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 45
ccs 4
cts 18
cp 0.2222
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A merge() 0 11 3
A hasResultSet() 0 4 1
A getResultSet() 0 8 2
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