2929 *
3030 * @author Bernhard Schussek <[email protected] > 3131 *
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>
3537 */
3638class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \ArrayAccess, \Countable
3739{
@@ -41,10 +43,14 @@ class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \Array
4143 public const INDENTATION = ' ' ;
4244
4345 private $ form ;
46+
47+ /**
48+ * @var list<T>
49+ */
4450 private $ errors ;
4551
4652 /**
47- * @param list<FormError|self > $errors
53+ * @param list<T > $errors
4854 *
4955 * @throws InvalidArgumentException If the errors are invalid
5056 */
@@ -74,7 +80,7 @@ public function __toString()
7480 $ string .= 'ERROR: ' .$ error ->getMessage ()."\n" ;
7581 } else {
7682 /* @var self $error */
77- $ string .= $ error ->form ->getName ().": \n" ;
83+ $ string .= $ error ->getForm () ->getName ().": \n" ;
7884 $ string .= self ::indent ((string ) $ error );
7985 }
8086 }
@@ -95,7 +101,7 @@ public function getForm()
95101 /**
96102 * Returns the current element of the iterator.
97103 *
98- * @return FormError|self An error or an iterator containing nested errors
104+ * @return T An error or an iterator containing nested errors
99105 */
100106 #[\ReturnTypeWillChange]
101107 public function current ()
@@ -164,7 +170,7 @@ public function offsetExists($position)
164170 *
165171 * @param int $position The position
166172 *
167- * @return FormError|FormErrorIterator
173+ * @return T
168174 *
169175 * @throws OutOfBoundsException If the given position does not exist
170176 */
@@ -227,7 +233,10 @@ public function getChildren()
227233 // throw new LogicException(sprintf('The current element is not iterable. Use "%s" to get the current element.', self::class.'::current()'));
228234 }
229235
230- return current ($ this ->errors );
236+ /** @var self $children */
237+ $ children = current ($ this ->errors );
238+
239+ return $ children ;
231240 }
232241
233242 /**
0 commit comments