Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| ReplyIterator | |
0.00% |
0 / 15 |
|
0.00% |
0 / 6 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| current | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| key | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| next | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| rewind | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| valid | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Flow\Import\LiquidThreadsApi; |
| 4 | |
| 5 | use Iterator; |
| 6 | |
| 7 | class ReplyIterator implements Iterator { |
| 8 | protected ImportPost $post; |
| 9 | protected array $threadReplies; |
| 10 | protected int $replyIndex; |
| 11 | protected ?ImportPost $current; |
| 12 | |
| 13 | public function __construct( ImportPost $post ) { |
| 14 | $this->post = $post; |
| 15 | $this->replyIndex = 0; |
| 16 | |
| 17 | $apiResponse = $post->getApiResponse(); |
| 18 | $this->threadReplies = array_values( $apiResponse['replies'] ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * @return ImportPost|null |
| 23 | */ |
| 24 | public function current(): ?ImportPost { |
| 25 | return $this->current; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @return int |
| 30 | */ |
| 31 | public function key(): int { |
| 32 | return $this->replyIndex; |
| 33 | } |
| 34 | |
| 35 | public function next(): void { |
| 36 | while ( ++$this->replyIndex < count( $this->threadReplies ) ) { |
| 37 | try { |
| 38 | $replyId = $this->threadReplies[$this->replyIndex]['id']; |
| 39 | $this->current = $this->post->getSource()->getPost( $replyId ); |
| 40 | |
| 41 | return; |
| 42 | } catch ( ApiNotFoundException ) { |
| 43 | // while loop fall-through handles our error case |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // Nothing found, set current to null |
| 48 | $this->current = null; |
| 49 | } |
| 50 | |
| 51 | public function rewind(): void { |
| 52 | $this->replyIndex = -1; |
| 53 | $this->next(); |
| 54 | } |
| 55 | |
| 56 | public function valid(): bool { |
| 57 | return $this->current !== null; |
| 58 | } |
| 59 | } |