/** * Iterates through user storage until certain $id is found. * * @param $id * * @return User * * @throws UserNotFoundException */ public function find(UserId $id) { $this->users->rewind(); while ($this->users->valid()) { $user = $this->users->current(); if ($user->getId()->equals($id)) { return $user; } $this->users->next(); } throw new UserNotFoundException(sprintf('User with id %d not found.', $id->id())); }