TitleArrayFromResult::rewind()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 5
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class to walk into a list of Title objects.
4
 *
5
 * Note: this entire file is a byte-for-byte copy of UserArrayFromResult.php
6
 * with s/User/Title/.  If anyone can figure out how to do this nicely
7
 * with inheritance or something, please do so.
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License along
20
 * with this program; if not, write to the Free Software Foundation, Inc.,
21
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
 * http://www.gnu.org/copyleft/gpl.html
23
 *
24
 * @file
25
 */
26
27 View Code Duplication
class TitleArrayFromResult extends TitleArray implements Countable {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
	/** @var ResultWrapper */
29
	public $res;
30
31
	public $key;
32
33
	public $current;
34
35
	function __construct( $res ) {
36
		$this->res = $res;
37
		$this->key = 0;
38
		$this->setCurrent( $this->res->current() );
39
	}
40
41
	/**
42
	 * @param bool|ResultWrapper $row
43
	 * @return void
44
	 */
45
	protected function setCurrent( $row ) {
46
		if ( $row === false ) {
47
			$this->current = false;
48
		} else {
49
			$this->current = Title::newFromRow( $row );
50
		}
51
	}
52
53
	/**
54
	 * @return int
55
	 */
56
	public function count() {
57
		return $this->res->numRows();
58
	}
59
60
	function current() {
61
		return $this->current;
62
	}
63
64
	function key() {
65
		return $this->key;
66
	}
67
68
	function next() {
69
		$row = $this->res->next();
70
		$this->setCurrent( $row );
71
		$this->key++;
72
	}
73
74
	function rewind() {
75
		$this->res->rewind();
76
		$this->key = 0;
77
		$this->setCurrent( $this->res->current() );
78
	}
79
80
	/**
81
	 * @return bool
82
	 */
83
	function valid() {
84
		return $this->current !== false;
85
	}
86
}
87