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 | protected int $pointer; |
| 17 | |
| 18 | /** @var IImportObject */ |
| 19 | protected $parent; |
| 20 | |
| 21 | /** @var callable */ |
| 22 | protected $factory; |
| 23 | |
| 24 | public function __construct( array $pageData, IImportObject $parent, callable $factory ) { |
| 25 | $this->pageData = $pageData; |
| 26 | $this->pointer = 0; |
| 27 | $this->parent = $parent; |
| 28 | $this->factory = $factory; |
| 29 | } |
| 30 | |
| 31 | protected function getRevisionCount() { |
| 32 | if ( isset( $this->pageData['revisions'] ) ) { |
| 33 | return count( $this->pageData['revisions'] ); |
| 34 | } else { |
| 35 | return 0; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | public function valid(): bool { |
| 40 | return $this->pointer < $this->getRevisionCount(); |
| 41 | } |
| 42 | |
| 43 | public function next(): void { |
| 44 | ++$this->pointer; |
| 45 | } |
| 46 | |
| 47 | public function key(): int { |
| 48 | return $this->pointer; |
| 49 | } |
| 50 | |
| 51 | public function rewind(): void { |
| 52 | $this->pointer = 0; |
| 53 | } |
| 54 | |
| 55 | public function current(): mixed { |
| 56 | return ( $this->factory )( $this->pageData['revisions'][$this->pointer], $this->parent ); |
| 57 | } |
| 58 | } |