Skip to content

Commit 823f9f4

Browse files
committed
Add generic types to traversable implementations
1 parent f39a253 commit 823f9f4

File tree

12 files changed

+54
-21
lines changed

12 files changed

+54
-21
lines changed

Button.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* A form button.
1919
*
2020
* @author Bernhard Schussek <[email protected]>
21+
*
22+
* @implements \IteratorAggregate<string, FormInterface>
2123
*/
2224
class Button implements \IteratorAggregate, FormInterface
2325
{
@@ -64,7 +66,7 @@ public function offsetExists($offset)
6466
*
6567
* @param mixed $offset
6668
*
67-
* @return mixed
69+
* @return FormInterface
6870
*
6971
* @throws BadMethodCallException
7072
*/

ButtonBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* A builder for {@link Button} instances.
2020
*
2121
* @author Bernhard Schussek <[email protected]>
22+
*
23+
* @implements \IteratorAggregate<string, FormBuilderInterface>
2224
*/
2325
class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
2426
{

ChoiceList/View/ChoiceGroupView.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* Represents a group of choices in templates.
1616
*
1717
* @author Bernhard Schussek <[email protected]>
18+
*
19+
* @implements \IteratorAggregate<array-key, ChoiceGroupView|ChoiceView>
1820
*/
1921
class ChoiceGroupView implements \IteratorAggregate
2022
{
@@ -24,7 +26,7 @@ class ChoiceGroupView implements \IteratorAggregate
2426
/**
2527
* Creates a new choice group view.
2628
*
27-
* @param ChoiceGroupView[]|ChoiceView[] $choices the choice views in the group
29+
* @param array<array-key, ChoiceGroupView|ChoiceView> $choices the choice views in the group
2830
*/
2931
public function __construct(string $label, array $choices = [])
3032
{
@@ -35,7 +37,7 @@ public function __construct(string $label, array $choices = [])
3537
/**
3638
* {@inheritdoc}
3739
*
38-
* @return \Traversable<ChoiceGroupView|ChoiceView>
40+
* @return \Traversable<array-key, ChoiceGroupView|ChoiceView>
3941
*/
4042
#[\ReturnTypeWillChange]
4143
public function getIterator()

Extension/Validator/Constraints/FormValidator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*/
2525
class FormValidator extends ConstraintValidator
2626
{
27+
/**
28+
* @var \SplObjectStorage<FormInterface, array<int, string|string[]|GroupSequence>>
29+
*/
2730
private $resolvedGroups;
2831

2932
/**

Extension/Validator/ViolationMapper/ViolationPath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class ViolationPath implements \IteratorAggregate, PropertyPathInterface
2222
{
2323
/**
24-
* @var array
24+
* @var string[]
2525
*/
2626
private $elements = [];
2727

Form.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
*
6767
* @author Fabien Potencier <[email protected]>
6868
* @author Bernhard Schussek <[email protected]>
69+
*
70+
* @implements \IteratorAggregate<string, FormInterface>
6971
*/
7072
class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterface
7173
{
@@ -82,7 +84,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
8284
/**
8385
* A map of FormInterface instances.
8486
*
85-
* @var FormInterface[]|OrderedHashMap
87+
* @var OrderedHashMap<string, FormInterface>
8688
*/
8789
private $children;
8890

@@ -1021,7 +1023,7 @@ public function offsetUnset($name)
10211023
/**
10221024
* Returns the iterator for this group.
10231025
*
1024-
* @return \Traversable<FormInterface>
1026+
* @return \Traversable<string, FormInterface>
10251027
*/
10261028
#[\ReturnTypeWillChange]
10271029
public function getIterator()

FormBuilder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* A builder for creating {@link Form} instances.
2222
*
2323
* @author Bernhard Schussek <[email protected]>
24+
*
25+
* @implements \IteratorAggregate<string, FormBuilderInterface>
2426
*/
2527
class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormBuilderInterface
2628
{
@@ -214,7 +216,7 @@ public function getForm()
214216
/**
215217
* {@inheritdoc}
216218
*
217-
* @return FormBuilderInterface[]|\Traversable
219+
* @return \Traversable<string, FormBuilderInterface>
218220
*/
219221
#[\ReturnTypeWillChange]
220222
public function getIterator()

FormErrorIterator.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
* flatten the recursive structure into a flat list of errors.
2929
*
3030
* @author Bernhard Schussek <[email protected]>
31+
*
32+
* @implements \ArrayAccess<int, FormError|FormErrorIterator>
33+
* @implements \RecursiveIterator<int, FormError>
34+
* @implements \SeekableIterator<int, FormError>
3135
*/
3236
class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \ArrayAccess, \Countable
3337
{
@@ -40,8 +44,7 @@ class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \Array
4044
private $errors;
4145

4246
/**
43-
* @param FormError[]|self[] $errors An array of form errors and instances
44-
* of FormErrorIterator
47+
* @param array<int, FormError|self> $errors
4548
*
4649
* @throws InvalidArgumentException If the errors are invalid
4750
*/

FormInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
* A form group bundling multiple forms in a hierarchical structure.
1818
*
1919
* @author Bernhard Schussek <[email protected]>
20+
*
21+
* @extends \ArrayAccess<string, FormInterface>
22+
* @extends \Traversable<string, FormInterface>
2023
*/
2124
interface FormInterface extends \ArrayAccess, \Traversable, \Countable
2225
{

FormView.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
/**
1717
* @author Bernhard Schussek <[email protected]>
18+
*
19+
* @implements \ArrayAccess<string, FormView>
20+
* @implements \IteratorAggregate<string, FormView>
1821
*/
1922
class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
2023
{

0 commit comments

Comments
 (0)