DumpReader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 46
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
nextEntityPage() 0 1 ?
rewind() 0 1 ?
A seekToTitle() 0 9 3
A getIterator() 0 3 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