Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
RevisionIterator | |
0.00% |
0 / 12 |
|
0.00% |
0 / 7 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getRevisionCount | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
valid | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
next | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
key | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
rewind | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
current | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\Import\LiquidThreadsApi; |
4 | |
5 | use Flow\Import\IImportObject; |
6 | use Iterator; |
7 | |
8 | /** |
9 | * Iterates over the revisions of a foreign page to produce |
10 | * revisions of a Flow object. |
11 | */ |
12 | class RevisionIterator implements Iterator { |
13 | /** @var array */ |
14 | protected $pageData; |
15 | |
16 | /** @var int */ |
17 | protected $pointer; |
18 | |
19 | /** @var IImportObject */ |
20 | protected $parent; |
21 | |
22 | /** @var callable */ |
23 | protected $factory; |
24 | |
25 | public function __construct( array $pageData, IImportObject $parent, callable $factory ) { |
26 | $this->pageData = $pageData; |
27 | $this->pointer = 0; |
28 | $this->parent = $parent; |
29 | $this->factory = $factory; |
30 | } |
31 | |
32 | protected function getRevisionCount() { |
33 | if ( isset( $this->pageData['revisions'] ) ) { |
34 | return count( $this->pageData['revisions'] ); |
35 | } else { |
36 | return 0; |
37 | } |
38 | } |
39 | |
40 | public function valid() { |
41 | return $this->pointer < $this->getRevisionCount(); |
42 | } |
43 | |
44 | public function next() { |
45 | ++$this->pointer; |
46 | } |
47 | |
48 | public function key() { |
49 | return $this->pointer; |
50 | } |
51 | |
52 | public function rewind() { |
53 | $this->pointer = 0; |
54 | } |
55 | |
56 | public function current() { |
57 | return ( $this->factory )( $this->pageData['revisions'][$this->pointer], $this->parent ); |
58 | } |
59 | } |