Test Failed
Pull Request — develop (#380)
by Felipe
03:42
created

ArrayRecordSet::RecordCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * PHPPgAdmin 6.1.3
5
 */
6
7
namespace PHPPgAdmin;
8
9
use ADOFieldObject;
10
use Countable;
11
12
/**
13
 * @file
14
 * Really simple RecordSet to allow printTable of arrays.
15
 *
16
 * Id: ArrayRecordSet.php,v 1.3 2007/01/10 01:46:28 soranzo Exp $
17
 */
18
19
/**
20
 * Really simple RecordSet to allow printTable arrays.
21
 * Mimics the behavior of an ADORecordset.
22
 *
23
 * Id: ArrayRecordSet.php,v 1.3 2007/01/10 01:46:28 soranzo Exp $
24
 */
25
class ArrayRecordSet implements Countable , Interfaces\RecordSet
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between "Countable" and comma; 1 found
Loading history...
26
{
27
    public $EOF = false;
28
29
    public $fields;
30
31
    private $_array;
32
33
    /**
34
     * Constructor.
35
     *
36
     * @param array $data The input array
37
     */
38
    public function __construct($data)
39
    {
40
        $this->_array = $data;
41
        $this->fields = \reset($this->_array);
42
43
        if (false === $this->fields) {
44
            $this->EOF = true;
45
        }
46
    }
47
48
    /**
49
     * Returns the recordCount.
50
     */
51
    public function count(): int
52
    {
53
        return \count($this->_array);
54
    }
55
	function FetchField($off = 0): ADOFieldObject
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for FetchField.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
56
	{
57
		// offsets begin at 0
58
        
59
		$o= new ADOFieldObject();
60
		
61
        $o->name= array_keys($this->fields)[$off]??null;
62
        $value = $this->fields[$o->name??random_bytes(64)]??null;
63
        $o->type= get_debug_type($value);
64
		$o->max_length = 1024;
65
		return $o;
66
	}
67
68
    /**
69
     * Counts the records in the instance array.
70
     *
71
     * @return int number of records in the instance array
72
     */
73
    public function RecordCount():int
74
    {
75
        return $this->count();
76
    }
77
78
    /**
79
     * Advance the internal pointer of the instance array
80
     * if no more fields are left, marks the instance variable $EOF as true.
81
     */
82
    public function MoveNext(): void
83
    {
84
        $this->fields = \next($this->_array);
85
86
        if (false === $this->fields) {
87
            $this->EOF = true;
88
        }
89
    }
90
}
91