Skip to content

Added missing return types to fix deprecation warnings in PHP 8.1 #143

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest]
php: ['7.1', '7.2', '7.3', '7.4', '8.0']
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
# max 4.4.16, see https://github.com/symfony/symfony/issues/39521
# max 5.1.8, see https://github.com/symfony/symfony/issues/39521
yaml: ['5.2.9', '5.1.11', '4.4.24', '^3.4']
Expand Down
5 changes: 2 additions & 3 deletions src/json/JsonReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace cebe\openapi\json;

use JsonSerializable;
use stdClass;

/**
* Represents a JSON Reference (IETF draft-pbryan-zyp-json-ref-03)
Expand Down Expand Up @@ -123,10 +124,8 @@ public function getReference(): string
/**
* Specify data which should be serialized to JSON
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
*/
public function jsonSerialize()
public function jsonSerialize(): stdClass
{
return (object)['$ref' => $this->getReference()];
}
Expand Down
15 changes: 6 additions & 9 deletions src/spec/Paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,9 @@ public function getErrors(): array
* Whether a offset exists
* @link http://php.net/manual/en/arrayaccess.offsetexists.php
* @param mixed $offset An offset to check for.
* @return boolean true on success or false on failure.
* The return value will be casted to boolean if non-boolean was returned.
*/
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return $this->hasPath($offset);
}
Expand All @@ -192,9 +191,8 @@ public function offsetExists($offset)
* Offset to retrieve
* @link http://php.net/manual/en/arrayaccess.offsetget.php
* @param mixed $offset The offset to retrieve.
* @return PathItem Can return all value types.
*/
public function offsetGet($offset)
public function offsetGet($offset): ?PathItem
{
return $this->getPath($offset);
}
Expand All @@ -205,7 +203,7 @@ public function offsetGet($offset)
* @param mixed $offset The offset to assign the value to.
* @param mixed $value The value to set.
*/
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
$this->addPath($offset, $value);
}
Expand All @@ -215,7 +213,7 @@ public function offsetSet($offset, $value)
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
* @param mixed $offset The offset to unset.
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
$this->removePath($offset);
}
Expand All @@ -226,17 +224,16 @@ public function offsetUnset($offset)
* @return int The custom count as an integer.
* The return value is cast to an integer.
*/
public function count()
public function count(): int
{
return count($this->_paths);
}

/**
* Retrieve an external iterator
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php
* @return Traversable An instance of an object implementing <b>Iterator</b> or <b>Traversable</b>
*/
public function getIterator()
public function getIterator(): Traversable
{
return new ArrayIterator($this->_paths);
}
Expand Down
14 changes: 6 additions & 8 deletions src/spec/Responses.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,9 @@ public function getErrors(): array
* Whether a offset exists
* @link http://php.net/manual/en/arrayaccess.offsetexists.php
* @param mixed $offset An offset to check for.
* @return boolean true on success or false on failure.
* The return value will be casted to boolean if non-boolean was returned.
*/
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return $this->hasResponse($offset);
}
Expand All @@ -182,9 +181,8 @@ public function offsetExists($offset)
* Offset to retrieve
* @link http://php.net/manual/en/arrayaccess.offsetget.php
* @param mixed $offset The offset to retrieve.
* @return mixed Can return all value types.
*/
public function offsetGet($offset)
public function offsetGet($offset): ?SpecObjectInterface
{
return $this->getResponse($offset);
}
Expand All @@ -195,7 +193,7 @@ public function offsetGet($offset)
* @param mixed $offset The offset to assign the value to.
* @param mixed $value The value to set.
*/
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
$this->addResponse($offset, $value);
}
Expand All @@ -205,7 +203,7 @@ public function offsetSet($offset, $value)
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
* @param mixed $offset The offset to unset.
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
$this->removeResponse($offset);
}
Expand All @@ -216,7 +214,7 @@ public function offsetUnset($offset)
* @return int The custom count as an integer.
* The return value is cast to an integer.
*/
public function count()
public function count(): int
{
return count($this->_responses);
}
Expand All @@ -226,7 +224,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>
*/
public function getIterator()
public function getIterator(): Traversable
{
return new ArrayIterator($this->_responses);
}
Expand Down