DumpReader::seekToTitle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Queryr\DumpReader;
4
5
use Iterator;
6
use IteratorAggregate;
7
8
/**
9
 * @licence GNU GPL v2+
10
 * @author Jeroen De Dauw < [email protected] >
11
 */
12
abstract class DumpReader implements IteratorAggregate {
13
14
	/**
15
	 * Returns a string with the json of the next entity,
16
	 * or null if there are no further entities.
17
	 *
18
	 * @return Page|null
19
	 * @throws DumpReaderException
20
	 */
21
	public abstract function nextEntityPage();
22
23
	/**
24
	 * Rewinds the reader to the beginning of the dump.
25
	 */
26
	public abstract function rewind();
27
28
	/**
29
	 * Seeks to the Page with the provided title and returns it.
30
	 * If no page is found, null is returned.
31
	 *
32
	 * @param string $titleToSeekTo
33
	 *
34
	 * @return Page|null
35
	 */
36
	public function seekToTitle( $titleToSeekTo ) {
37
		while ( $page = $this->nextEntityPage() ) {
38
			if ( $page->getTitle() === $titleToSeekTo ) {
39
				return $page;
40
			}
41
		}
42
43
		return null;
44
	}
45
46
	/**
47
	 * Returns an Iterator for the REMAINING pages.
48
	 * Caution: the iterator affects the position of the dump reader itself.
49
	 *
50
	 * @see IteratorAggregate::getIterator
51
	 * @return Iterator
52
	 */
53
	public function getIterator() {
54
		return new DumpIterator( $this );
55
	}
56
57
}
58