Passed
Pull Request — develop (#340)
by Felipe
04:14
created

ArrayRecordSet   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 51
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 3 1
A recordCount() 0 3 1
A __construct() 0 7 2
A moveNext() 0 6 2
1
<?php
2
3
/**
4
 * PHPPgAdmin 6.0.0
5
 */
6
7
namespace PHPPgAdmin;
8
9
use Countable;
10
11
/**
12
 * @file
13
 * Really simple RecordSet to allow printTable of arrays.
14
 *
15
 * Id: ArrayRecordSet.php,v 1.3 2007/01/10 01:46:28 soranzo Exp $
16
 */
17
18
/**
19
 * Really simple RecordSet to allow printTable arrays.
20
 * Mimics the behavior of an ADORecordset.
21
 *
22
 * Id: ArrayRecordSet.php,v 1.3 2007/01/10 01:46:28 soranzo Exp $
23
 */
24
class ArrayRecordSet implements Countable
25
{
26
    public $EOF = false;
27
28
    public $fields;
29
30
    private $_array;
31
32
    /**
33
     * Constructor.
34
     *
35
     * @param array $data The input array
36
     */
37
    public function __construct($data)
38
    {
39
        $this->_array = $data;
40
        $this->fields = \reset($this->_array);
41
42
        if (false === $this->fields) {
43
            $this->EOF = true;
44
        }
45
    }
46
47
    /**
48
     * Returns the recordCount.
49
     */
50
    public function count(): int
51
    {
52
        return \count($this->_array);
53
    }
54
55
    /**
56
     * Counts the records in the instance array.
57
     *
58
     * @return int number of records in the instance array
59
     */
60
    public function recordCount()
61
    {
62
        return $this->count();
63
    }
64
65
    /**
66
     * Advance the internal pointer of the instance array
67
     * if no more fields are left, marks the instance variable $EOF as true.
68
     */
69
    public function moveNext(): void
70
    {
71
        $this->fields = \next($this->_array);
72
73
        if (false === $this->fields) {
74
            $this->EOF = true;
75
        }
76
    }
77
}
78