Skip to content

Commit a08b922

Browse files
committed
Fix return types for PHP 8.1
1 parent 9179357 commit a08b922

File tree

12 files changed

+58
-10
lines changed

12 files changed

+58
-10
lines changed

Button.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function __construct(FormConfigInterface $config)
5151
*
5252
* @return bool Always returns false
5353
*/
54+
#[\ReturnTypeWillChange]
5455
public function offsetExists($offset)
5556
{
5657
return false;
@@ -67,6 +68,7 @@ public function offsetExists($offset)
6768
*
6869
* @throws BadMethodCallException
6970
*/
71+
#[\ReturnTypeWillChange]
7072
public function offsetGet($offset)
7173
{
7274
throw new BadMethodCallException('Buttons cannot have children.');
@@ -84,6 +86,7 @@ public function offsetGet($offset)
8486
*
8587
* @throws BadMethodCallException
8688
*/
89+
#[\ReturnTypeWillChange]
8790
public function offsetSet($offset, $value)
8891
{
8992
throw new BadMethodCallException('Buttons cannot have children.');
@@ -100,6 +103,7 @@ public function offsetSet($offset, $value)
100103
*
101104
* @throws BadMethodCallException
102105
*/
106+
#[\ReturnTypeWillChange]
103107
public function offsetUnset($offset)
104108
{
105109
throw new BadMethodCallException('Buttons cannot have children.');
@@ -436,6 +440,7 @@ public function createView(FormView $parent = null)
436440
*
437441
* @return int Always returns 0
438442
*/
443+
#[\ReturnTypeWillChange]
439444
public function count()
440445
{
441446
return 0;
@@ -446,6 +451,7 @@ public function count()
446451
*
447452
* @return \EmptyIterator Always returns an empty iterator
448453
*/
454+
#[\ReturnTypeWillChange]
449455
public function getIterator()
450456
{
451457
return new \EmptyIterator();

ButtonBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ public function getOption($name, $default = null)
717717
*
718718
* @return int Always returns 0
719719
*/
720+
#[\ReturnTypeWillChange]
720721
public function count()
721722
{
722723
return 0;
@@ -727,6 +728,7 @@ public function count()
727728
*
728729
* @return \EmptyIterator Always returns an empty iterator
729730
*/
731+
#[\ReturnTypeWillChange]
730732
public function getIterator()
731733
{
732734
return new \EmptyIterator();

ChoiceList/View/ChoiceGroupView.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ public function __construct($label, array $choices = [])
3636
/**
3737
* {@inheritdoc}
3838
*
39-
* @return self[]|ChoiceView[]
39+
* @return \Traversable<ChoiceGroupView|ChoiceView>
4040
*/
41+
#[\ReturnTypeWillChange]
4142
public function getIterator()
4243
{
4344
return new \ArrayIterator($this->choices);

Extension/Validator/ViolationMapper/ViolationPath.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ public function mapsForm($index)
223223
*
224224
* @return ViolationPathIterator
225225
*/
226+
#[\ReturnTypeWillChange]
226227
public function getIterator()
227228
{
228229
return new ViolationPathIterator($this);

Form.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ public function get($name)
958958
*
959959
* @return bool
960960
*/
961+
#[\ReturnTypeWillChange]
961962
public function offsetExists($name)
962963
{
963964
return $this->has($name);
@@ -972,6 +973,7 @@ public function offsetExists($name)
972973
*
973974
* @throws OutOfBoundsException if the named child does not exist
974975
*/
976+
#[\ReturnTypeWillChange]
975977
public function offsetGet($name)
976978
{
977979
return $this->get($name);
@@ -990,6 +992,7 @@ public function offsetGet($name)
990992
*
991993
* @see self::add()
992994
*/
995+
#[\ReturnTypeWillChange]
993996
public function offsetSet($name, $child)
994997
{
995998
$this->add($child);
@@ -1004,6 +1007,7 @@ public function offsetSet($name, $child)
10041007
*
10051008
* @throws AlreadySubmittedException if the form has already been submitted
10061009
*/
1010+
#[\ReturnTypeWillChange]
10071011
public function offsetUnset($name)
10081012
{
10091013
$this->remove($name);
@@ -1014,6 +1018,7 @@ public function offsetUnset($name)
10141018
*
10151019
* @return \Traversable<FormInterface>
10161020
*/
1021+
#[\ReturnTypeWillChange]
10171022
public function getIterator()
10181023
{
10191024
return $this->children;
@@ -1024,6 +1029,7 @@ public function getIterator()
10241029
*
10251030
* @return int The number of embedded form children
10261031
*/
1032+
#[\ReturnTypeWillChange]
10271033
public function count()
10281034
{
10291035
return \count($this->children);

FormBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public function all()
161161
/**
162162
* @return int
163163
*/
164+
#[\ReturnTypeWillChange]
164165
public function count()
165166
{
166167
if ($this->locked) {
@@ -215,6 +216,7 @@ public function getForm()
215216
*
216217
* @return FormBuilderInterface[]|\Traversable
217218
*/
219+
#[\ReturnTypeWillChange]
218220
public function getIterator()
219221
{
220222
if ($this->locked) {

FormErrorIterator.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function getForm()
9393
*
9494
* @return FormError|self An error or an iterator containing nested errors
9595
*/
96+
#[\ReturnTypeWillChange]
9697
public function current()
9798
{
9899
return current($this->errors);
@@ -101,6 +102,7 @@ public function current()
101102
/**
102103
* Advances the iterator to the next position.
103104
*/
105+
#[\ReturnTypeWillChange]
104106
public function next()
105107
{
106108
next($this->errors);
@@ -111,6 +113,7 @@ public function next()
111113
*
112114
* @return int The 0-indexed position
113115
*/
116+
#[\ReturnTypeWillChange]
114117
public function key()
115118
{
116119
return key($this->errors);
@@ -121,6 +124,7 @@ public function key()
121124
*
122125
* @return bool Whether the iterator is valid
123126
*/
127+
#[\ReturnTypeWillChange]
124128
public function valid()
125129
{
126130
return null !== key($this->errors);
@@ -132,6 +136,7 @@ public function valid()
132136
* This method detects if errors have been added to the form since the
133137
* construction of the iterator.
134138
*/
139+
#[\ReturnTypeWillChange]
135140
public function rewind()
136141
{
137142
reset($this->errors);
@@ -144,6 +149,7 @@ public function rewind()
144149
*
145150
* @return bool Whether that position exists
146151
*/
152+
#[\ReturnTypeWillChange]
147153
public function offsetExists($position)
148154
{
149155
return isset($this->errors[$position]);
@@ -158,6 +164,7 @@ public function offsetExists($position)
158164
*
159165
* @throws OutOfBoundsException If the given position does not exist
160166
*/
167+
#[\ReturnTypeWillChange]
161168
public function offsetGet($position)
162169
{
163170
if (!isset($this->errors[$position])) {
@@ -174,6 +181,7 @@ public function offsetGet($position)
174181
*
175182
* @throws BadMethodCallException
176183
*/
184+
#[\ReturnTypeWillChange]
177185
public function offsetSet($position, $value)
178186
{
179187
throw new BadMethodCallException('The iterator doesn\'t support modification of elements.');
@@ -186,6 +194,7 @@ public function offsetSet($position, $value)
186194
*
187195
* @throws BadMethodCallException
188196
*/
197+
#[\ReturnTypeWillChange]
189198
public function offsetUnset($position)
190199
{
191200
throw new BadMethodCallException('The iterator doesn\'t support modification of elements.');
@@ -197,6 +206,7 @@ public function offsetUnset($position)
197206
*
198207
* @return bool Whether the current element is an instance of this class
199208
*/
209+
#[\ReturnTypeWillChange]
200210
public function hasChildren()
201211
{
202212
return current($this->errors) instanceof self;
@@ -207,6 +217,7 @@ public function hasChildren()
207217
*
208218
* @return self
209219
*/
220+
#[\ReturnTypeWillChange]
210221
public function getChildren()
211222
{
212223
return current($this->errors);
@@ -229,6 +240,7 @@ public function getChildren()
229240
*
230241
* @return int The number of iterated elements
231242
*/
243+
#[\ReturnTypeWillChange]
232244
public function count()
233245
{
234246
return \count($this->errors);
@@ -243,6 +255,7 @@ public function count()
243255
*
244256
* @throws OutOfBoundsException If the position is invalid
245257
*/
258+
#[\ReturnTypeWillChange]
246259
public function seek($position)
247260
{
248261
if (!isset($this->errors[$position])) {

FormView.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function setMethodRendered()
108108
*
109109
* @return self The child view
110110
*/
111+
#[\ReturnTypeWillChange]
111112
public function offsetGet($name)
112113
{
113114
return $this->children[$name];
@@ -120,6 +121,7 @@ public function offsetGet($name)
120121
*
121122
* @return bool Whether the child view exists
122123
*/
124+
#[\ReturnTypeWillChange]
123125
public function offsetExists($name)
124126
{
125127
return isset($this->children[$name]);
@@ -132,6 +134,7 @@ public function offsetExists($name)
132134
*
133135
* @throws BadMethodCallException always as setting a child by name is not allowed
134136
*/
137+
#[\ReturnTypeWillChange]
135138
public function offsetSet($name, $value)
136139
{
137140
throw new BadMethodCallException('Not supported.');
@@ -144,6 +147,7 @@ public function offsetSet($name, $value)
144147
*
145148
* @return void
146149
*/
150+
#[\ReturnTypeWillChange]
147151
public function offsetUnset($name)
148152
{
149153
unset($this->children[$name]);
@@ -154,6 +158,7 @@ public function offsetUnset($name)
154158
*
155159
* @return \ArrayIterator<string, FormView> The iterator
156160
*/
161+
#[\ReturnTypeWillChange]
157162
public function getIterator()
158163
{
159164
return new \ArrayIterator($this->children);
@@ -164,6 +169,7 @@ public function getIterator()
164169
*
165170
* @return int The number of children views
166171
*/
172+
#[\ReturnTypeWillChange]
167173
public function count()
168174
{
169175
return \count($this->children);

Tests/Fixtures/CustomArrayObject.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ public function offsetExists($offset): bool
2929
return \array_key_exists($offset, $this->array);
3030
}
3131

32+
/**
33+
* @param mixed $offset
34+
* @return mixed
35+
*/
36+
#[\ReturnTypeWillChange]
3237
public function offsetGet($offset)
3338
{
3439
return $this->array[$offset];
3540
}
3641

37-
public function offsetSet($offset, $value)
42+
public function offsetSet($offset, $value): void
3843
{
3944
if (null === $offset) {
4045
$this->array[] = $value;
@@ -43,7 +48,7 @@ public function offsetSet($offset, $value)
4348
}
4449
}
4550

46-
public function offsetUnset($offset)
51+
public function offsetUnset($offset): void
4752
{
4853
unset($this->array[$offset]);
4954
}
@@ -73,7 +78,7 @@ public function __unserialize(array $data): void
7378
$this->array = $data;
7479
}
7580

76-
public function unserialize($serialized)
81+
public function unserialize($serialized): void
7782
{
7883
$this->__unserialize((array) unserialize((string) $serialized));
7984
}

Util/InheritDataAwareIterator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class InheritDataAwareIterator extends \IteratorIterator implements \RecursiveIt
3030
*
3131
* @return static
3232
*/
33+
#[\ReturnTypeWillChange]
3334
public function getChildren()
3435
{
3536
return new static($this->current());
@@ -38,6 +39,7 @@ public function getChildren()
3839
/**
3940
* @return bool
4041
*/
42+
#[\ReturnTypeWillChange]
4143
public function hasChildren()
4244
{
4345
return (bool) $this->current()->getConfig()->getInheritData();

0 commit comments

Comments
 (0)