Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
| UserArrayFromResult | |
100.00% |
12 / 12 |
|
100.00% |
8 / 8 |
9 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setCurrent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| count | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| current | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| key | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| next | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| rewind | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| valid | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\User; |
| 8 | |
| 9 | use stdClass; |
| 10 | use Wikimedia\Rdbms\IResultWrapper; |
| 11 | |
| 12 | /** |
| 13 | * @internal Call and type against UserArray instead. |
| 14 | */ |
| 15 | class UserArrayFromResult extends UserArray { |
| 16 | |
| 17 | private IResultWrapper $res; |
| 18 | private int $key = 0; |
| 19 | private ?User $current = null; |
| 20 | |
| 21 | public function __construct( IResultWrapper $res ) { |
| 22 | $this->res = $res; |
| 23 | $this->rewind(); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @param stdClass|null|false $row |
| 28 | * @return void |
| 29 | */ |
| 30 | protected function setCurrent( $row ) { |
| 31 | $this->current = $row instanceof stdClass ? User::newFromRow( $row ) : null; |
| 32 | } |
| 33 | |
| 34 | public function count(): int { |
| 35 | return $this->res->numRows(); |
| 36 | } |
| 37 | |
| 38 | public function current(): User { |
| 39 | return $this->current; |
| 40 | } |
| 41 | |
| 42 | public function key(): int { |
| 43 | return $this->key; |
| 44 | } |
| 45 | |
| 46 | public function next(): void { |
| 47 | $this->setCurrent( $this->res->fetchObject() ); |
| 48 | $this->key++; |
| 49 | } |
| 50 | |
| 51 | public function rewind(): void { |
| 52 | $this->res->rewind(); |
| 53 | $this->key = 0; |
| 54 | $this->setCurrent( $this->res->current() ); |
| 55 | } |
| 56 | |
| 57 | public function valid(): bool { |
| 58 | return (bool)$this->current; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /** @deprecated class alias since 1.41 */ |
| 63 | class_alias( UserArrayFromResult::class, 'UserArrayFromResult' ); |