FakeResultWrapper::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Overloads the relevant methods of the real ResultsWrapper so it
4
 * doesn't go anywhere near an actual database.
5
 */
6
class FakeResultWrapper extends ResultWrapper {
7
	/** @var $result stdClass[] */
8
9
	/**
10
	 * @param stdClass[] $rows
11
	 */
12
	function __construct( array $rows ) {
13
		parent::__construct( null, $rows );
14
	}
15
16
	function numRows() {
17
		return count( $this->result );
18
	}
19
20
	function fetchRow() {
21
		if ( $this->pos < count( $this->result ) ) {
22
			$this->currentRow = $this->result[$this->pos];
23
		} else {
24
			$this->currentRow = false;
0 ignored issues
show
Documentation Bug introduced by
It seems like false of type false is incompatible with the declared type object<stdClass>|null of property $currentRow.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
25
		}
26
		$this->pos++;
27
		if ( is_object( $this->currentRow ) ) {
28
			return get_object_vars( $this->currentRow );
29
		} else {
30
			return $this->currentRow;
31
		}
32
	}
33
34
	function seek( $row ) {
35
		$this->pos = $row;
36
	}
37
38
	function free() {
39
	}
40
41
	function fetchObject() {
42
		$this->fetchRow();
43
		if ( $this->currentRow ) {
44
			return (object)$this->currentRow;
45
		} else {
46
			return false;
47
		}
48
	}
49
50
	function rewind() {
51
		$this->pos = 0;
52
		$this->currentRow = null;
53
	}
54
55
	function next() {
56
		return $this->fetchObject();
57
	}
58
}
59