Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
52.94% |
9 / 17 |
|
62.50% |
5 / 8 |
CRAP | |
0.00% |
0 / 1 |
TitleArrayFromResult | |
56.25% |
9 / 16 |
|
62.50% |
5 / 8 |
15.78 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
setCurrent | |
100.00% |
3 / 3 |
|
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 | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
next | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
rewind | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
valid | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
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 | namespace MediaWiki\Title; |
28 | |
29 | use Countable; |
30 | use Iterator; |
31 | use Wikimedia\Rdbms\IResultWrapper; |
32 | |
33 | /** |
34 | * @newable |
35 | * @note marked as newable in 1.35 for lack of a better alternative, |
36 | * but should probably become part of the TitleFactory service. |
37 | */ |
38 | class TitleArrayFromResult implements Countable, Iterator { |
39 | /** @var IResultWrapper */ |
40 | public $res; |
41 | |
42 | /** @var int */ |
43 | public $key; |
44 | |
45 | /** @var Title|false */ |
46 | public $current; |
47 | |
48 | /** |
49 | * @stable to call |
50 | * |
51 | * @param IResultWrapper $res |
52 | */ |
53 | public function __construct( $res ) { |
54 | $this->res = $res; |
55 | $this->key = 0; |
56 | $this->setCurrent( $this->res->current() ); |
57 | } |
58 | |
59 | /** |
60 | * @param \stdClass|false $row |
61 | * @return void |
62 | */ |
63 | protected function setCurrent( $row ) { |
64 | if ( $row === false ) { |
65 | $this->current = false; |
66 | } else { |
67 | $this->current = Title::newFromRow( $row ); |
68 | } |
69 | } |
70 | |
71 | /** |
72 | * @return int |
73 | */ |
74 | public function count(): int { |
75 | return $this->res->numRows(); |
76 | } |
77 | |
78 | public function current(): Title { |
79 | return $this->current; |
80 | } |
81 | |
82 | public function key(): int { |
83 | return $this->key; |
84 | } |
85 | |
86 | public function next(): void { |
87 | $row = $this->res->fetchObject(); |
88 | $this->setCurrent( $row ); |
89 | $this->key++; |
90 | } |
91 | |
92 | public function rewind(): void { |
93 | $this->res->rewind(); |
94 | $this->key = 0; |
95 | $this->setCurrent( $this->res->current() ); |
96 | } |
97 | |
98 | /** |
99 | * @return bool |
100 | */ |
101 | public function valid(): bool { |
102 | return $this->current !== false; |
103 | } |
104 | } |
105 | |
106 | /** @deprecated class alias since 1.41 */ |
107 | class_alias( TitleArrayFromResult::class, 'TitleArrayFromResult' ); |