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

Make FormErrorIterator generic #45696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions 25 src/Symfony/Component/Form/FormErrorIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @implements \ArrayAccess<int, FormError|FormErrorIterator>
* @implements \RecursiveIterator<int, FormError|FormErrorIterator>
* @implements \SeekableIterator<int, FormError|FormErrorIterator>
* @template T of FormError|FormErrorIterator
*
* @implements \ArrayAccess<int, T>
* @implements \RecursiveIterator<int, T>
* @implements \SeekableIterator<int, T>
*/
class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \ArrayAccess, \Countable
{
Expand All @@ -41,10 +43,14 @@ class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \Array
public const INDENTATION = ' ';

private $form;

/**
* @var list<T>
*/
private $errors;

/**
* @param list<FormError|self> $errors
* @param list<T> $errors
*
* @throws InvalidArgumentException If the errors are invalid
*/
Expand Down Expand Up @@ -74,7 +80,7 @@ public function __toString()
$string .= 'ERROR: '.$error->getMessage()."\n";
} else {
/* @var self $error */
$string .= $error->form->getName().":\n";
$string .= $error->getForm()->getName().":\n";
$string .= self::indent((string) $error);
}
}
Expand All @@ -95,7 +101,7 @@ public function getForm()
/**
* Returns the current element of the iterator.
*
* @return FormError|self An error or an iterator containing nested errors
* @return T An error or an iterator containing nested errors
*/
#[\ReturnTypeWillChange]
public function current()
Expand Down Expand Up @@ -164,7 +170,7 @@ public function offsetExists($position)
*
* @param int $position The position
*
* @return FormError|FormErrorIterator
* @return T
*
* @throws OutOfBoundsException If the given position does not exist
*/
Expand Down Expand Up @@ -227,7 +233,10 @@ public function getChildren()
// throw new LogicException(sprintf('The current element is not iterable. Use "%s" to get the current element.', self::class.'::current()'));
}

return current($this->errors);
/** @var self $children */
$children = current($this->errors);

return $children;
}

/**
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.