ResultSet::getAllowedCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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