Skip to content

Commit 495f3ef

Browse files
committed
Add PHP 8 compatible return types to Classes implementing PHP internal interfaces
- Add return types supported by PHP 7 - Add `#[\ReturnTypeWillChange]` annotation in cases where `mixed` return type is used, which is not available in PHP 7
1 parent 2cd5d2d commit 495f3ef

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

src/json/JsonReference.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function getReference(): string
127127
* which is a value of any type other than a resource.
128128
*/
129129
#[\ReturnTypeWillChange]
130-
public function jsonSerialize()
130+
public function jsonSerialize() //: mixed
131131
{
132132
return (object)['$ref' => $this->getReference()];
133133
}

src/spec/Paths.php

+6-11
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ public function getErrors(): array
183183
* @return boolean true on success or false on failure.
184184
* The return value will be casted to boolean if non-boolean was returned.
185185
*/
186-
#[\ReturnTypeWillChange]
187-
public function offsetExists($offset)
186+
public function offsetExists($offset): bool
188187
{
189188
return $this->hasPath($offset);
190189
}
@@ -196,7 +195,7 @@ public function offsetExists($offset)
196195
* @return PathItem Can return all value types.
197196
*/
198197
#[\ReturnTypeWillChange]
199-
public function offsetGet($offset)
198+
public function offsetGet($offset) //: mixed
200199
{
201200
return $this->getPath($offset);
202201
}
@@ -207,8 +206,7 @@ public function offsetGet($offset)
207206
* @param mixed $offset The offset to assign the value to.
208207
* @param mixed $value The value to set.
209208
*/
210-
#[\ReturnTypeWillChange]
211-
public function offsetSet($offset, $value)
209+
public function offsetSet($offset, $value): void
212210
{
213211
$this->addPath($offset, $value);
214212
}
@@ -218,8 +216,7 @@ public function offsetSet($offset, $value)
218216
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
219217
* @param mixed $offset The offset to unset.
220218
*/
221-
#[\ReturnTypeWillChange]
222-
public function offsetUnset($offset)
219+
public function offsetUnset($offset): void
223220
{
224221
$this->removePath($offset);
225222
}
@@ -230,8 +227,7 @@ public function offsetUnset($offset)
230227
* @return int The custom count as an integer.
231228
* The return value is cast to an integer.
232229
*/
233-
#[\ReturnTypeWillChange]
234-
public function count()
230+
public function count(): int
235231
{
236232
return count($this->_paths);
237233
}
@@ -241,8 +237,7 @@ public function count()
241237
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php
242238
* @return Traversable An instance of an object implementing <b>Iterator</b> or <b>Traversable</b>
243239
*/
244-
#[\ReturnTypeWillChange]
245-
public function getIterator()
240+
public function getIterator(): Traversable
246241
{
247242
return new ArrayIterator($this->_paths);
248243
}

src/spec/Responses.php

+6-11
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ public function getErrors(): array
173173
* @return boolean true on success or false on failure.
174174
* The return value will be casted to boolean if non-boolean was returned.
175175
*/
176-
#[\ReturnTypeWillChange]
177-
public function offsetExists($offset)
176+
public function offsetExists($offset): bool
178177
{
179178
return $this->hasResponse($offset);
180179
}
@@ -186,7 +185,7 @@ public function offsetExists($offset)
186185
* @return mixed Can return all value types.
187186
*/
188187
#[\ReturnTypeWillChange]
189-
public function offsetGet($offset)
188+
public function offsetGet($offset) //: mixed
190189
{
191190
return $this->getResponse($offset);
192191
}
@@ -197,8 +196,7 @@ public function offsetGet($offset)
197196
* @param mixed $offset The offset to assign the value to.
198197
* @param mixed $value The value to set.
199198
*/
200-
#[\ReturnTypeWillChange]
201-
public function offsetSet($offset, $value)
199+
public function offsetSet($offset, $value): void
202200
{
203201
$this->addResponse($offset, $value);
204202
}
@@ -208,8 +206,7 @@ public function offsetSet($offset, $value)
208206
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
209207
* @param mixed $offset The offset to unset.
210208
*/
211-
#[\ReturnTypeWillChange]
212-
public function offsetUnset($offset)
209+
public function offsetUnset($offset): void
213210
{
214211
$this->removeResponse($offset);
215212
}
@@ -220,8 +217,7 @@ public function offsetUnset($offset)
220217
* @return int The custom count as an integer.
221218
* The return value is cast to an integer.
222219
*/
223-
#[\ReturnTypeWillChange]
224-
public function count()
220+
public function count(): int
225221
{
226222
return count($this->_responses);
227223
}
@@ -231,8 +227,7 @@ public function count()
231227
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php
232228
* @return Traversable An instance of an object implementing <b>Iterator</b> or <b>Traversable</b>
233229
*/
234-
#[\ReturnTypeWillChange]
235-
public function getIterator()
230+
public function getIterator(): Traversable
236231
{
237232
return new ArrayIterator($this->_responses);
238233
}

0 commit comments

Comments
 (0)