From db7b07a62ae2740bf48cc7597ccbbfc56f6046d9 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 10 Dec 2021 12:05:34 +0100 Subject: [PATCH 1/3] Added missing return types to fix deprecation warnings in PHP 8.1 --- .github/workflows/php.yml | 2 +- src/json/JsonReference.php | 3 ++- src/spec/Paths.php | 15 ++++++--------- src/spec/Responses.php | 13 ++++++------- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index ccd13c23..aa1036fa 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -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'] diff --git a/src/json/JsonReference.php b/src/json/JsonReference.php index fe27ced1..e5b30892 100644 --- a/src/json/JsonReference.php +++ b/src/json/JsonReference.php @@ -8,6 +8,7 @@ namespace cebe\openapi\json; use JsonSerializable; +use stdClass; /** * Represents a JSON Reference (IETF draft-pbryan-zyp-json-ref-03) @@ -126,7 +127,7 @@ public function getReference(): string * @return mixed data which can be serialized by json_encode, * which is a value of any type other than a resource. */ - public function jsonSerialize() + public function jsonSerialize(): stdClass { return (object)['$ref' => $this->getReference()]; } diff --git a/src/spec/Paths.php b/src/spec/Paths.php index a2da8a10..634bfe85 100644 --- a/src/spec/Paths.php +++ b/src/spec/Paths.php @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -226,7 +224,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->_paths); } @@ -234,9 +232,8 @@ public function count() /** * Retrieve an external iterator * @link http://php.net/manual/en/iteratoraggregate.getiterator.php - * @return Traversable An instance of an object implementing Iterator or Traversable */ - public function getIterator() + public function getIterator(): Traversable { return new ArrayIterator($this->_paths); } diff --git a/src/spec/Responses.php b/src/spec/Responses.php index 52476031..77dedd9d 100644 --- a/src/spec/Responses.php +++ b/src/spec/Responses.php @@ -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); } @@ -184,7 +183,7 @@ public function offsetExists($offset) * @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); } @@ -195,7 +194,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); } @@ -205,7 +204,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); } @@ -216,7 +215,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); } @@ -226,7 +225,7 @@ public function count() * @link http://php.net/manual/en/iteratoraggregate.getiterator.php * @return Traversable An instance of an object implementing Iterator or Traversable */ - public function getIterator() + public function getIterator(): Traversable { return new ArrayIterator($this->_responses); } From c27cbaff5357becc467a90b3b5c23b26a6bd9319 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 21 Dec 2021 16:16:04 +0100 Subject: [PATCH 2/3] Removed phpdocs which do not match actual return types --- src/json/JsonReference.php | 2 -- src/spec/Responses.php | 1 - 2 files changed, 3 deletions(-) diff --git a/src/json/JsonReference.php b/src/json/JsonReference.php index e5b30892..0550cad4 100644 --- a/src/json/JsonReference.php +++ b/src/json/JsonReference.php @@ -124,8 +124,6 @@ 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 json_encode, - * which is a value of any type other than a resource. */ public function jsonSerialize(): stdClass { diff --git a/src/spec/Responses.php b/src/spec/Responses.php index 77dedd9d..e0367015 100644 --- a/src/spec/Responses.php +++ b/src/spec/Responses.php @@ -181,7 +181,6 @@ public function offsetExists($offset): bool * 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): ?SpecObjectInterface { From 813d46a7edacd249d4c608a937c0e2b90634fe09 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 9 Feb 2022 07:53:19 +0100 Subject: [PATCH 3/3] Added nullable type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Enrique Barbeito GarcĂ­a --- src/spec/Paths.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spec/Paths.php b/src/spec/Paths.php index 634bfe85..7a04ba48 100644 --- a/src/spec/Paths.php +++ b/src/spec/Paths.php @@ -192,7 +192,7 @@ public function offsetExists($offset): bool * @link http://php.net/manual/en/arrayaccess.offsetget.php * @param mixed $offset The offset to retrieve. */ - public function offsetGet($offset): PathItem + public function offsetGet($offset): ?PathItem { return $this->getPath($offset); }