ResultSet   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 44.44%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 2
dl 0
loc 45
ccs 8
cts 18
cp 0.4444
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getSingleRow() 0 8 3
A getMeta() 0 4 1
A getAllowedCount() 0 4 1
A getTotalCount() 0 4 1
1
<?php
2
3
namespace Brouzie\Sphinxy\Query;
4
5
use Brouzie\Sphinxy\Exception\NonUniqueResultException;
6
7
class ResultSet extends SimpleResultSet
8
{
9
    protected $meta;
10
11 3
    public function __construct(array $result, array $rawMeta)
12
    {
13 3
        parent::__construct($result);
14
15 3
        $meta = array();
16 3
        foreach ($rawMeta as $row) {
17 3
            $meta[$row['Variable_name']] = $row['Value'];
18 2
        }
19
20 3
        $this->meta = $meta;
21 3
    }
22
23
    /**
24
     * @param array $default Workaround for http://sphinxsearch.com/bugs/view.php?id=2410
25
     *
26
     * @return array
27
     */
28
    public function getSingleRow($default = array())
29
    {
30
        if (count($this->result) > 1) {
31
            throw new NonUniqueResultException();
32
        }
33
34
        return isset($this->result[0]) ? $this->result[0] : $default;
35
    }
36
37
    public function getMeta()
38
    {
39
        return $this->meta;
40
    }
41
42
    public function getAllowedCount()
43
    {
44
        return (int) $this->meta['total'];
45
    }
46
47
    public function getTotalCount()
48
    {
49
        return (int) $this->meta['total_found'];
50
    }
51
}
52