Total Complexity | 7 |
Total Lines | 83 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
12 | class UserGroupsIterator implements \Iterator |
||
13 | { |
||
14 | /** |
||
15 | * The users collection. |
||
16 | * |
||
17 | * @var Collection |
||
18 | */ |
||
19 | protected $users; |
||
20 | |||
21 | /** |
||
22 | * Number of users which can be sent per request |
||
23 | * |
||
24 | * @var int |
||
25 | */ |
||
26 | protected $perRequest; |
||
27 | |||
28 | /** |
||
29 | * The iterator position |
||
30 | * |
||
31 | * @var int |
||
32 | */ |
||
33 | protected $position; |
||
34 | |||
35 | /** |
||
36 | * UserGroupsIterator constructor. |
||
37 | * |
||
38 | * @param Collection $users |
||
39 | * @param int $perRequest |
||
40 | */ |
||
41 | public function __construct(Collection $users, int $perRequest) |
||
42 | { |
||
43 | $this->users = $users; |
||
44 | $this->perRequest = $perRequest; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @inheritdoc |
||
49 | */ |
||
50 | public function rewind() |
||
51 | { |
||
52 | $this->position = 1; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @inheritdoc |
||
57 | */ |
||
58 | public function next() |
||
59 | { |
||
60 | $this->position++; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @inheritdoc |
||
65 | */ |
||
66 | public function valid() |
||
67 | { |
||
68 | return $this->current()->isNotEmpty(); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @inheritdoc |
||
73 | */ |
||
74 | public function current() |
||
75 | { |
||
76 | return $this->users->forPage($this->position, $this->perRequest); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @inheritdoc |
||
81 | */ |
||
82 | public function key() |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Calculate a number of requests. |
||
89 | * |
||
90 | * @return int |
||
91 | */ |
||
92 | public function requestsCount(): int |
||
95 | } |
||
96 | } |