Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 08ddac5

Browse filesBrowse files
VincentLangletfabpot
authored andcommitted
Make FormErrorIterator generic
1 parent b30675a commit 08ddac5
Copy full SHA for 08ddac5

File tree

1 file changed

+17
-8
lines changed
Filter options

1 file changed

+17
-8
lines changed

‎src/Symfony/Component/Form/FormErrorIterator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/FormErrorIterator.php
+17-8Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
*
3030
* @author Bernhard Schussek <bschussek@gmail.com>
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
*/
3638
class 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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.