Skip to content

Commit

Permalink
Add PHP 8 compatible return types to Classes implementing PHP interna…
Browse files Browse the repository at this point in the history
…l 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
  • Loading branch information
cebe committed Apr 20, 2022
1 parent 2cd5d2d commit 495f3ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/json/JsonReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function getReference(): string
* which is a value of any type other than a resource.
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize() //: mixed
{
return (object)['$ref' => $this->getReference()];
}
Expand Down
17 changes: 6 additions & 11 deletions src/spec/Paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ public function getErrors(): array
* @return boolean true on success or false on failure.
* The return value will be casted to boolean if non-boolean was returned.
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return $this->hasPath($offset);
}
Expand All @@ -196,7 +195,7 @@ public function offsetExists($offset)
* @return PathItem Can return all value types.
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
public function offsetGet($offset) //: mixed
{
return $this->getPath($offset);
}
Expand All @@ -207,8 +206,7 @@ public function offsetGet($offset)
* @param mixed $offset The offset to assign the value to.
* @param mixed $value The value to set.
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
$this->addPath($offset, $value);
}
Expand All @@ -218,8 +216,7 @@ public function offsetSet($offset, $value)
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
* @param mixed $offset The offset to unset.
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
$this->removePath($offset);
}
Expand All @@ -230,8 +227,7 @@ public function offsetUnset($offset)
* @return int The custom count as an integer.
* The return value is cast to an integer.
*/
#[\ReturnTypeWillChange]
public function count()
public function count(): int
{
return count($this->_paths);
}
Expand All @@ -241,8 +237,7 @@ public function count()
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php
* @return Traversable An instance of an object implementing <b>Iterator</b> or <b>Traversable</b>
*/
#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): Traversable
{
return new ArrayIterator($this->_paths);
}
Expand Down
17 changes: 6 additions & 11 deletions src/spec/Responses.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ public function getErrors(): array
* @return boolean true on success or false on failure.
* The return value will be casted to boolean if non-boolean was returned.
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return $this->hasResponse($offset);
}
Expand All @@ -186,7 +185,7 @@ public function offsetExists($offset)
* @return mixed Can return all value types.
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
public function offsetGet($offset) //: mixed
{
return $this->getResponse($offset);
}
Expand All @@ -197,8 +196,7 @@ public function offsetGet($offset)
* @param mixed $offset The offset to assign the value to.
* @param mixed $value The value to set.
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
$this->addResponse($offset, $value);
}
Expand All @@ -208,8 +206,7 @@ public function offsetSet($offset, $value)
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
* @param mixed $offset The offset to unset.
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
$this->removeResponse($offset);
}
Expand All @@ -220,8 +217,7 @@ public function offsetUnset($offset)
* @return int The custom count as an integer.
* The return value is cast to an integer.
*/
#[\ReturnTypeWillChange]
public function count()
public function count(): int
{
return count($this->_responses);
}
Expand All @@ -231,8 +227,7 @@ public function count()
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php
* @return Traversable An instance of an object implementing <b>Iterator</b> or <b>Traversable</b>
*/
#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): Traversable
{
return new ArrayIterator($this->_responses);
}
Expand Down

0 comments on commit 495f3ef

Please sign in to comment.