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 | /** @var ImportPost */ |
9 | protected $post; |
10 | /** @var array Array of thread IDs */ |
11 | protected $threadReplies; |
12 | /** @var int */ |
13 | protected $replyIndex; |
14 | /** @var ImportPost|null */ |
15 | protected $current; |
16 | |
17 | public function __construct( ImportPost $post ) { |
18 | $this->post = $post; |
19 | $this->replyIndex = 0; |
20 | |
21 | $apiResponse = $post->getApiResponse(); |
22 | $this->threadReplies = array_values( $apiResponse['replies'] ); |
23 | } |
24 | |
25 | /** |
26 | * @return ImportPost|null |
27 | */ |
28 | public function current() { |
29 | return $this->current; |
30 | } |
31 | |
32 | /** |
33 | * @return int |
34 | */ |
35 | public function key() { |
36 | return $this->replyIndex; |
37 | } |
38 | |
39 | public function next() { |
40 | while ( ++$this->replyIndex < count( $this->threadReplies ) ) { |
41 | try { |
42 | $replyId = $this->threadReplies[$this->replyIndex]['id']; |
43 | $this->current = $this->post->getSource()->getPost( $replyId ); |
44 | |
45 | return; |
46 | } catch ( ApiNotFoundException $e ) { |
47 | // while loop fall-through handles our error case |
48 | } |
49 | } |
50 | |
51 | // Nothing found, set current to null |
52 | $this->current = null; |
53 | } |
54 | |
55 | public function rewind() { |
56 | $this->replyIndex = -1; |
57 | $this->next(); |
58 | } |
59 | |
60 | public function valid() { |
61 | return $this->current !== null; |
62 | } |
63 | } |