29
29
*
30
30
* @author Bernhard Schussek <bschussek@gmail.com>
31
31
*
32
- * @implements \ArrayAccess<int, FormError|FormErrorIterator>
33
- * @implements \RecursiveIterator<int, FormError|FormErrorIterator>
34
- * @implements \SeekableIterator<int, FormError|FormErrorIterator>
32
+ * @template T of FormError|FormErrorIterator
33
+ *
34
+ * @implements \ArrayAccess<int, T>
35
+ * @implements \RecursiveIterator<int, T>
36
+ * @implements \SeekableIterator<int, T>
35
37
*/
36
38
class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \ArrayAccess, \Countable
37
39
{
@@ -41,10 +43,14 @@ class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \Array
41
43
public const INDENTATION = ' ' ;
42
44
43
45
private $ form ;
46
+
47
+ /**
48
+ * @var list<T>
49
+ */
44
50
private $ errors ;
45
51
46
52
/**
47
- * @param list<FormError|self > $errors
53
+ * @param list<T > $errors
48
54
*
49
55
* @throws InvalidArgumentException If the errors are invalid
50
56
*/
@@ -74,7 +80,7 @@ public function __toString()
74
80
$ string .= 'ERROR: ' .$ error ->getMessage ()."\n" ;
75
81
} else {
76
82
/* @var self $error */
77
- $ string .= $ error ->form ->getName ().": \n" ;
83
+ $ string .= $ error ->getForm () ->getName ().": \n" ;
78
84
$ string .= self ::indent ((string ) $ error );
79
85
}
80
86
}
@@ -95,7 +101,7 @@ public function getForm()
95
101
/**
96
102
* Returns the current element of the iterator.
97
103
*
98
- * @return FormError|self An error or an iterator containing nested errors
104
+ * @return T An error or an iterator containing nested errors
99
105
*/
100
106
#[\ReturnTypeWillChange]
101
107
public function current ()
@@ -164,7 +170,7 @@ public function offsetExists($position)
164
170
*
165
171
* @param int $position The position
166
172
*
167
- * @return FormError|FormErrorIterator
173
+ * @return T
168
174
*
169
175
* @throws OutOfBoundsException If the given position does not exist
170
176
*/
@@ -227,7 +233,10 @@ public function getChildren()
227
233
// throw new LogicException(sprintf('The current element is not iterable. Use "%s" to get the current element.', self::class.'::current()'));
228
234
}
229
235
230
- return current ($ this ->errors );
236
+ /** @var self $children */
237
+ $ children = current ($ this ->errors );
238
+
239
+ return $ children ;
231
240
}
232
241
233
242
/**
0 commit comments