Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.12% covered (success)
94.12%
16 / 17
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
UserArrayFromResult
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
8 / 8
9
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 setCurrent
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 count
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 current
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 key
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 next
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 rewind
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 valid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Class to walk into a list of User objects.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23namespace MediaWiki\User;
24
25use Countable;
26use stdClass;
27use Wikimedia\Rdbms\IResultWrapper;
28
29class UserArrayFromResult extends UserArray implements Countable {
30    /** @var IResultWrapper */
31    public $res;
32
33    /** @var int */
34    public $key;
35
36    /** @var User|false */
37    public $current;
38
39    /**
40     * @param IResultWrapper $res
41     */
42    public function __construct( $res ) {
43        $this->res = $res;
44        $this->key = 0;
45        $this->setCurrent( $this->res->current() );
46    }
47
48    /**
49     * @param stdClass|false $row
50     * @return void
51     */
52    protected function setCurrent( $row ) {
53        if ( $row === false ) {
54            $this->current = false;
55        } else {
56            $this->current = User::newFromRow( $row );
57        }
58    }
59
60    /**
61     * @return int
62     */
63    public function count(): int {
64        return $this->res->numRows();
65    }
66
67    public function current(): User {
68        return $this->current;
69    }
70
71    public function key(): int {
72        return $this->key;
73    }
74
75    public function next(): void {
76        $row = $this->res->fetchObject();
77        $this->setCurrent( $row );
78        $this->key++;
79    }
80
81    public function rewind(): void {
82        $this->res->rewind();
83        $this->key = 0;
84        $this->setCurrent( $this->res->current() );
85    }
86
87    /**
88     * @return bool
89     */
90    public function valid(): bool {
91        return $this->current !== false;
92    }
93}
94
95/** @deprecated class alias since 1.41 */
96class_alias( UserArrayFromResult::class, 'UserArrayFromResult' );