| Total Complexity | 8 |
| Total Lines | 74 |
| Duplicated Lines | 0 % |
| Coverage | 95.24% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | final class IterableNewResult implements Iterator |
||
| 19 | { |
||
| 20 | /** @var AbstractHydrator */ |
||
| 21 | private $hydrator; |
||
| 22 | |||
| 23 | /** @var bool */ |
||
| 24 | private $rewinded = false; |
||
| 25 | |||
| 26 | /** @var int */ |
||
| 27 | private $key = -1; |
||
| 28 | |||
| 29 | /** @var object|null */ |
||
| 30 | private $current; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param AbstractHydrator $hydrator |
||
| 34 | */ |
||
| 35 | 15 | public function __construct($hydrator) |
|
| 36 | { |
||
| 37 | 15 | $this->hydrator = $hydrator; |
|
| 38 | 15 | } |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @throws HydrationException |
||
| 42 | */ |
||
| 43 | 15 | public function rewind() |
|
| 44 | { |
||
| 45 | 15 | if ($this->rewinded === true) { |
|
| 46 | throw new HydrationException('Can only iterate a Result once.'); |
||
| 47 | } |
||
| 48 | |||
| 49 | 15 | $this->current = $this->next(); |
|
| 50 | 15 | $this->rewinded = true; |
|
| 51 | 15 | } |
|
| 52 | |||
| 53 | /** |
||
| 54 | * Gets the next set of results. |
||
| 55 | * |
||
| 56 | * @return mixed|false |
||
| 57 | */ |
||
| 58 | 15 | public function next() |
|
| 59 | { |
||
| 60 | 15 | $this->current = $this->hydrator->hydrateRow(); |
|
| 61 | 15 | if (is_array($this->current)) { |
|
| 62 | 14 | $this->current = array_values($this->current)[0]; |
|
| 63 | } |
||
| 64 | |||
| 65 | 15 | $this->key++; |
|
| 66 | |||
| 67 | 15 | return $this->current; |
|
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @return mixed |
||
| 72 | */ |
||
| 73 | 14 | public function current() |
|
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @return int |
||
| 80 | */ |
||
| 81 | 14 | public function key() |
|
| 82 | { |
||
| 83 | 14 | return $this->key; |
|
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @return bool |
||
| 88 | */ |
||
| 89 | 15 | public function valid() |
|
| 92 | } |
||
| 93 | } |
||
| 94 |