FakeResultWrapper   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A numRows() 0 3 1
A fetchRow() 0 13 3
A seek() 0 3 1
A free() 0 2 1
A fetchObject() 0 8 2
A rewind() 0 4 1
A next() 0 3 1
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