Completed
Pull Request — master (#268)
by
unknown
03:49 queued 02:35
created

Xhgui_Storage_ResultSet::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
class Xhgui_Storage_ResultSet implements \Iterator {
4
5
    protected $data = [];
6
    protected $keys = [];
7
8
    protected $i = 0;
9
    protected $limit = 25;
10
    protected $totalRows = 0;
11
    public function __construct($data = null, $totalRows = 0) {
12
        $this->data         = $data;
13
        $this->keys         = array_keys($data);
14
        $this->totalRows    = $totalRows;
15
    }
16
17
    public function toArray(){
18
        return $this->data;
19
    }
20
21
    public function count(){
22
        return count($this->data);
23
    }
24
25
    public function sort(){
26
        return $this;
27
    }
28
29
    public function skip($count){
30
        $this->i += $count;
31
        return $this;
32
    }
33
34
    public function limit($limit){
35
        $this->limit = $limit;
36
        return $this;
37
    }
38
39
    public function get($i) {
40
        return $this->data[$i];
41
    }
42
    /**
43
     * Return the current element
44
     */
45
    public function current() {
46
        return $this->get($this->keys[$this->i]);
47
    }
48
49
    /**
50
     * Move forward to next element
51
     */
52
    public function next() {
53
        $this->i++;
54
    }
55
56
    /**
57
     * Return the key of the current element
58
     */
59
    public function key() {
60
        return $this->keys[$this->i];
61
    }
62
63
    /**
64
     * Checks if current position is valid
65
     * 
66
     * Returns true on success or false on failure.
67
     */
68
    public function valid() {
69
        return !empty($this->keys[$this->i]) AND !empty($this->data[$this->keys[$this->i]]) AND $this->i < $this->limit;
70
    }
71
72
    /**
73
     * Rewind the Iterator to the first element
74
     */
75
    public function rewind() {
76
        $this->i = 0;
77
    }
78
79
    /**
80
     * @return int
81
     */
82
    public function getTotalRows() {
83
        return $this->totalRows;
84
    }
85
86
    /**
87
     * @param int $totalRows
88
     */
89
    public function setTotalRows($totalRows) {
90
        $this->totalRows = $totalRows;
91
    }
92
}
93