Code Duplication    Length = 60-68 lines in 2 locations

includes/TitleArrayFromResult.php 1 location

@@ 27-86 (lines=60) @@
24
 * @file
25
 */
26
27
class TitleArrayFromResult extends TitleArray implements Countable {
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

includes/user/UserArrayFromResult.php 1 location

@@ 23-90 (lines=68) @@
20
 * @file
21
 */
22
23
class UserArrayFromResult extends UserArray implements Countable {
24
	/** @var ResultWrapper */
25
	public $res;
26
27
	/** @var int */
28
	public $key;
29
30
	/** @var bool|stdClass */
31
	public $current;
32
33
	/**
34
	 * @param ResultWrapper $res
35
	 */
36
	function __construct( $res ) {
37
		$this->res = $res;
38
		$this->key = 0;
39
		$this->setCurrent( $this->res->current() );
40
	}
41
42
	/**
43
	 * @param bool|stdClass $row
44
	 * @return void
45
	 */
46
	protected function setCurrent( $row ) {
47
		if ( $row === false ) {
48
			$this->current = false;
49
		} else {
50
			$this->current = User::newFromRow( $row );
51
		}
52
	}
53
54
	/**
55
	 * @return int
56
	 */
57
	public function count() {
58
		return $this->res->numRows();
59
	}
60
61
	/**
62
	 * @return User
63
	 */
64
	function current() {
65
		return $this->current;
66
	}
67
68
	function key() {
69
		return $this->key;
70
	}
71
72
	function next() {
73
		$row = $this->res->next();
74
		$this->setCurrent( $row );
75
		$this->key++;
76
	}
77
78
	function rewind() {
79
		$this->res->rewind();
80
		$this->key = 0;
81
		$this->setCurrent( $this->res->current() );
82
	}
83
84
	/**
85
	 * @return bool
86
	 */
87
	function valid() {
88
		return $this->current !== false;
89
	}
90
}
91