1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Doctrine\ORM\Internal\Hydration; |
||
6 | |||
7 | /** |
||
8 | * Represents a result structure that can be iterated over, hydrating row-by-row |
||
9 | * during the iteration. An IterableResult is obtained by AbstractHydrator#iterate(). |
||
10 | */ |
||
11 | class IterableResult implements \Iterator |
||
12 | { |
||
13 | /** |
||
14 | * @var AbstractHydrator |
||
15 | */ |
||
16 | private $hydrator; |
||
17 | |||
18 | /** |
||
19 | * @var bool |
||
20 | */ |
||
21 | private $rewinded = false; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | private $key = -1; |
||
27 | |||
28 | /** |
||
29 | * @var object|null |
||
30 | */ |
||
31 | private $current; |
||
32 | |||
33 | /** |
||
34 | * @param AbstractHydrator $hydrator |
||
35 | */ |
||
36 | 11 | public function __construct($hydrator) |
|
37 | { |
||
38 | 11 | $this->hydrator = $hydrator; |
|
39 | 11 | } |
|
40 | |||
41 | /** |
||
42 | * @throws HydrationException |
||
43 | */ |
||
44 | 5 | public function rewind() |
|
45 | { |
||
46 | 5 | if ($this->rewinded === true) { |
|
47 | throw new HydrationException('Can only iterate a Result once.'); |
||
48 | } |
||
49 | |||
50 | 5 | $this->current = $this->next(); |
|
51 | 5 | $this->rewinded = true; |
|
52 | 5 | } |
|
53 | |||
54 | /** |
||
55 | * Gets the next set of results. |
||
56 | * |
||
57 | * @return mixed[]|false |
||
58 | */ |
||
59 | 10 | public function next() |
|
60 | { |
||
61 | 10 | $this->current = $this->hydrator->hydrateRow(); |
|
62 | 10 | $this->key++; |
|
63 | |||
64 | 10 | return $this->current; |
|
0 ignored issues
–
show
|
|||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @return mixed |
||
69 | */ |
||
70 | 5 | public function current() |
|
71 | { |
||
72 | 5 | return $this->current; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * @return int |
||
77 | */ |
||
78 | public function key() |
||
79 | { |
||
80 | return $this->key; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return bool |
||
85 | */ |
||
86 | 5 | public function valid() |
|
87 | { |
||
88 | 5 | return $this->current!==false; |
|
89 | } |
||
90 | } |
||
91 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: