From 68959399565fa04f9104fed38e3412f6d8620993 Mon Sep 17 00:00:00 2001 From: Csaba Maulis Date: Fri, 3 Sep 2021 16:20:30 +0800 Subject: [PATCH 1/4] Add `ReturnTypeWillChange` attribute Reason: To maintain PHP >=7.1.0 and make implementation PHP 8.1 compatible --- src/json/JsonReference.php | 1 + src/spec/Paths.php | 6 ++++++ src/spec/Responses.php | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/src/json/JsonReference.php b/src/json/JsonReference.php index fe27ced1..cfac559e 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/Paths.php b/src/spec/Paths.php index a2da8a10..f1ebdc2f 100644 --- a/src/spec/Paths.php +++ b/src/spec/Paths.php @@ -183,6 +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) { return $this->hasPath($offset); @@ -194,6 +195,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,6 +207,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) { $this->addPath($offset, $value); @@ -215,6 +218,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) { $this->removePath($offset); @@ -226,6 +230,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() { return count($this->_paths); @@ -236,6 +241,7 @@ public function count() * @link http://php.net/manual/en/iteratoraggregate.getiterator.php * @return Traversable An instance of an object implementing Iterator or Traversable */ + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_paths); diff --git a/src/spec/Responses.php b/src/spec/Responses.php index a3623ae4..e293fa15 100644 --- a/src/spec/Responses.php +++ b/src/spec/Responses.php @@ -173,6 +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) { return $this->hasResponse($offset); @@ -184,6 +185,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,6 +197,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) { $this->addResponse($offset, $value); @@ -205,6 +208,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) { $this->removeResponse($offset); @@ -216,6 +220,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() { return count($this->_responses); @@ -226,6 +231,7 @@ public function count() * @link http://php.net/manual/en/iteratoraggregate.getiterator.php * @return Traversable An instance of an object implementing Iterator or Traversable */ + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_responses); From 8e592f7dd7997dc2ad62dab1b37275a30efe43d3 Mon Sep 17 00:00:00 2001 From: Csaba Maulis Date: Thu, 10 Feb 2022 05:01:11 +0800 Subject: [PATCH 2/4] Add PHP 8.1 to GitHub test matrix --- .github/workflows/php.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index b60478ab..1cf8b0de 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -19,6 +19,7 @@ jobs: - "7.3" - "7.4" - "8.0" + - "8.1" dependencies: - "lowest" - "highest" @@ -48,6 +49,8 @@ jobs: # symfony/yaml v3.4 is not compatible with PHP 8.0 but has no upper-bound, so it installs on it - php: '8.0' symfony-yaml: '^3.4' + - php: '8.1' + symfony-yaml: '^3.4' runs-on: ${{ matrix.os }} From 2cd5d2da1e824c096c39ba6671ccbe00c3976dbe Mon Sep 17 00:00:00 2001 From: Woody Gilk Date: Fri, 8 Apr 2022 16:04:52 -0500 Subject: [PATCH 3/4] Use new PHPUnit with PHP 8.1 --- .github/workflows/php.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 1cf8b0de..607c866e 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -65,7 +65,11 @@ jobs: tools: composer:v2 - name: Require specific symfony/yaml version - run: "composer require symfony/yaml:'${{ matrix.symfony-yaml }}' --prefer-dist --no-interaction --ansi --no-install" + run: "composer require symfony/yaml:'${{ matrix.symfony-yaml }}' --no-interaction --ansi --no-install" + + - name: Require newer phpunit/phpunit version + run: "composer require phpunit/phpunit '^9.5' --dev --no-interaction --ansi --no-install" + if: matrix.php == '8.1' - name: "Install dependencies with Composer" uses: "ramsey/composer-install@v2" From 495f3efe6524be45c67be5b733c1d082839fc4d5 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 20 Apr 2022 15:41:12 +0200 Subject: [PATCH 4/4] 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 --- src/json/JsonReference.php | 2 +- src/spec/Paths.php | 17 ++++++----------- src/spec/Responses.php | 17 ++++++----------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/json/JsonReference.php b/src/json/JsonReference.php index cfac559e..5f248881 100644 --- a/src/json/JsonReference.php +++ b/src/json/JsonReference.php @@ -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()]; } diff --git a/src/spec/Paths.php b/src/spec/Paths.php index f1ebdc2f..e504a90a 100644 --- a/src/spec/Paths.php +++ b/src/spec/Paths.php @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -241,8 +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 */ - #[\ReturnTypeWillChange] - 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 e293fa15..a6db447d 100644 --- a/src/spec/Responses.php +++ b/src/spec/Responses.php @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -231,8 +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 */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { return new ArrayIterator($this->_responses); }