From 97775bf3e2779e99666d20ab6249d4d24e201698 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Fri, 13 Jan 2023 16:29:03 +0100 Subject: [PATCH] [openapi v3.1] PHP 8.2 deprecations --- src/json/JsonReference.php | 1 + src/spec/OpenApi.php | 2 +- src/spec/Paths.php | 11 ++++++----- src/spec/Responses.php | 11 ++++++----- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/json/JsonReference.php b/src/json/JsonReference.php index fe27ced..cfac559 100644 --- a/src/json/JsonReference.php +++ b/src/json/JsonReference.php @@ -126,6 +126,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. */ + #[\ReturnTypeWillChange] public function jsonSerialize() { return (object)['$ref' => $this->getReference()]; diff --git a/src/spec/OpenApi.php b/src/spec/OpenApi.php index 7476ce8..4010093 100644 --- a/src/spec/OpenApi.php +++ b/src/spec/OpenApi.php @@ -107,7 +107,7 @@ public function performValidation() */ public function getMajorVersion() { - if (preg_match(static::PATTERN_VERSION, $this->openapi, $matches)) { + if (is_string($this->openapi) && preg_match(static::PATTERN_VERSION, $this->openapi, $matches)) { switch ($matches[1]) { case '3.0': return static::VERSION_3_0; diff --git a/src/spec/Paths.php b/src/spec/Paths.php index a2da8a1..6bb8625 100644 --- a/src/spec/Paths.php +++ b/src/spec/Paths.php @@ -183,7 +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. */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return $this->hasPath($offset); } @@ -194,6 +194,7 @@ public function offsetExists($offset) * @param mixed $offset The offset to retrieve. * @return PathItem Can return all value types. */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->getPath($offset); @@ -205,7 +206,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 +216,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 +227,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); } @@ -236,7 +237,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->_paths); } diff --git a/src/spec/Responses.php b/src/spec/Responses.php index a3623ae..82ecbb7 100644 --- a/src/spec/Responses.php +++ b/src/spec/Responses.php @@ -173,7 +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. */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return $this->hasResponse($offset); } @@ -184,6 +184,7 @@ public function offsetExists($offset) * @param mixed $offset The offset to retrieve. * @return mixed Can return all value types. */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->getResponse($offset); @@ -195,7 +196,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 +206,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 +217,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 +227,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); }