Result::count()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace CouchDB\DesignDocument;
4
5
/**
6
 * @author Markus Bachmann <[email protected]>
7
 */
8
class Result implements ResultInterface
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $data;
14
15
    /**
16
     * Constructor.
17
     *
18
     * @param array $data
19
     */
20 7
    public function __construct(array $data)
21
    {
22 7
        $this->data = $data;
23 7
    }
24
25
    /**
26
     * Return the total amount of rows.
27
     *
28
     * @return int
29
     */
30 1
    public function getTotalRows()
31
    {
32 1
        return $this->data['total_rows'];
33
    }
34
35
    /**
36
     * Gets the offset.
37
     *
38
     * @return int
39
     */
40 1
    public function getOffset()
41
    {
42 1
        return $this->data['offset'];
43
    }
44
45
    /**
46
     * Return all rows.
47
     *
48
     * @return array
49
     */
50 1
    public function getRows()
51
    {
52 1
        return $this->data['rows'];
53
    }
54
55
    /**
56
     * Return the first row.
57
     *
58
     * @return bool|array
59
     */
60 1 View Code Duplication
    public function getFirstRow()
61
    {
62 1
        $rows = $this->data['rows'];
63 1
        if (empty($rows)) {
64
            return false;
65
        }
66
67 1
        $row = array_slice($rows, 0, 1);
68
69 1
        return current($row);
70
    }
71
72
    /**
73
     * Return the last row.
74
     *
75
     * @return bool|array
76
     */
77 1 View Code Duplication
    public function getLastRow()
78
    {
79 1
        $rows = $this->data['rows'];
80 1
        if (empty($rows)) {
81
            return false;
82
        }
83
84 1
        $row = array_slice($rows, count($rows) - 1);
85
86 1
        return current($row);
87
    }
88
89
    /**
90
     * Return the array.
91
     *
92
     * @return array
93
     */
94
    public function toArray()
95
    {
96
        return $this->data;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 1
    public function getIterator()
103
    {
104 1
        return new \ArrayIterator($this->data['rows']);
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110 1
    public function count()
111
    {
112 1
        return count($this->data['rows']);
113
    }
114
}
115