Completed
Push — master ( d567a7...558b0d )
by Sébastien
04:09
created

Resultset::count()   A

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 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Soluble\DbWrapper\Result;
4
5
class Resultset  implements ResultInterface
0 ignored issues
show
Coding Style introduced by
Expected 1 space after class name; 2 found
Loading history...
Coding Style introduced by
Expected 1 space before implements keyword; 2 found
Loading history...
6
{
7
    /**
8
     *
9
     * @var integer 
10
     */
11
    protected $position = 0;
12
13
    /**
14
     *
15
     * @var integer
16
     */
17
    protected $count = 0;
18
19
    /**
20
     *
21
     * @var array
22
     */
23
    protected $storage=[];
24
25
    /**
26
     * 
27
     
28
     */
29 13
    public function __construct()
30
    {
31 13
        $this->storage = [];
32 13
        $this->position = 0;
33 13
        $this->count = count($this->storage);
34 13
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 1
    public function current()
40
    {
41 1
        return $this->storage[$this->position];
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     * @return int position
47
     */
48
    public function key()
49
    {
50
        return $this->position;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 1
    public function next()
57
    {
58 1
        ++$this->position;
59 1
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 1
    public function rewind()
65
    {
66 1
        $this->position=0;
67 1
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 1
    public function valid()
73
    {
74 1
        return isset($this->storage[$this->position]);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 5
    public function count()
81
    {
82 5
        return $this->count;
83
    }
84
85
    /**
86
     * 
87
     * {@inheritdoc}
88
     */
89 8
    public function append(array $row)
90
    {
91 8
        $this->storage[] = $row;
92 8
        ++$this->count;
93 8
    }
94
95
96
    /**
97
     * 
98
     * {@inheritdoc}
99
     */
100
    public function offsetExists($position)
101
    {
102
        return isset($this->storage[$position]);
103
    }
104
105
    /**
106
     * 
107
     * {@inheritdoc}
108
     */
109 8
    public function offsetGet($position)
110
    {
111 8
        return isset($this->storage[$position]) ? $this->storage[$position] : null;
112
    }
113
114
    /**
115
     * 
116
     * {@inheritdoc}
117
     */
118
    public function offsetSet($position, $row)
119
    {
120
        throw new \Exception('Resultsets are immutable');
121
    }
122
123
    /**
124
     * 
125
     * {@inheritdoc}
126
     */
127
    public function offsetUnset($position)
128
    {
129
        throw new \Exception("Resultsets are immutable");
130
    }
131
132
    /**
133
     * 
134
     * @return array
135
     */
136 1
    public function getArray()
137
    {
138 1
        return $this->storage;
139
    }
140
}
141