for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Slides\Connector\Auth\Sync;
use Illuminate\Support\Collection;
/**
* Class UserGroupsIterator
*
* @package Slides\Connector\Auth\Sync
*/
class UserGroupsIterator implements \Iterator
{
* The users collection.
* @var Collection
protected $users;
* Number of users which can be sent per request
* @var int
protected $perRequest;
* The iterator position
protected $position;
* UserGroupsIterator constructor.
* @param Collection $users
* @param int $perRequest
public function __construct(Collection $users, int $perRequest)
$this->users = $users;
$this->perRequest = $perRequest;
}
* @inheritdoc
public function rewind()
$this->position = 1;
public function next()
$this->position++;
public function valid()
return $this->current()->isNotEmpty();
public function current()
return $this->users->forPage($this->position, $this->perRequest);
public function key()
return $this->position;
* Calculate a number of requests.
* @return int
public function requestsCount(): int
return max(1, ceil($this->users->count() / $this->perRequest));