From b99a931f7f12d7de5031d565ef265f29e8907734 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 21 Dec 2021 09:57:48 +0100 Subject: [PATCH] MDL-76355 lib: apply a patch to googleapi for php 8.1 compatibility --- lib/google/readme_moodle.txt | 2 ++ lib/google/src/Google/Collection.php | 27 +++++++++++++++++---------- lib/google/src/Google/Model.php | 7 ++++--- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/google/readme_moodle.txt b/lib/google/readme_moodle.txt index e8f736f52aa..62629405cec 100644 --- a/lib/google/readme_moodle.txt +++ b/lib/google/readme_moodle.txt @@ -43,6 +43,8 @@ Local changes (to reapply until upstream upgrades contain them): * MDL-73523 php80 compliance. openssl_xxx_free() methods deprecated. I've been unable to find any issue upstream and the current library versions are way different from the ones we are using here. + * MDL-76355 php81 compliance. Class methods require overriding methods to declare a + compatible return type. Information ----------- diff --git a/lib/google/src/Google/Collection.php b/lib/google/src/Google/Collection.php index b26e9e51d0e..25f5f92c242 100644 --- a/lib/google/src/Google/Collection.php +++ b/lib/google/src/Google/Collection.php @@ -13,7 +13,7 @@ class Google_Collection extends Google_Model implements Iterator, Countable { protected $collection_key = 'items'; - public function rewind() + public function rewind(): void { if (isset($this->modelData[$this->collection_key]) && is_array($this->modelData[$this->collection_key])) { @@ -21,34 +21,38 @@ class Google_Collection extends Google_Model implements Iterator, Countable } } + #[\ReturnTypeWillChange] public function current() { $this->coerceType($this->key()); if (is_array($this->modelData[$this->collection_key])) { return current($this->modelData[$this->collection_key]); } + return null; } + #[\ReturnTypeWillChange] public function key() { if (isset($this->modelData[$this->collection_key]) && is_array($this->modelData[$this->collection_key])) { return key($this->modelData[$this->collection_key]); } + return null; } - public function next() + public function next(): void { - return next($this->modelData[$this->collection_key]); + next($this->modelData[$this->collection_key]); } - public function valid() + public function valid(): bool { $key = $this->key(); return $key !== null && $key !== false; } - public function count() + public function count(): int { if (!isset($this->modelData[$this->collection_key])) { return 0; @@ -56,7 +60,7 @@ class Google_Collection extends Google_Model implements Iterator, Countable return count($this->modelData[$this->collection_key]); } - public function offsetExists($offset) + public function offsetExists($offset): bool { if (!is_numeric($offset)) { return parent::offsetExists($offset); @@ -64,6 +68,7 @@ class Google_Collection extends Google_Model implements Iterator, Countable return isset($this->modelData[$this->collection_key][$offset]); } + #[\ReturnTypeWillChange] public function offsetGet($offset) { if (!is_numeric($offset)) { @@ -73,18 +78,20 @@ class Google_Collection extends Google_Model implements Iterator, Countable return $this->modelData[$this->collection_key][$offset]; } - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { if (!is_numeric($offset)) { - return parent::offsetSet($offset, $value); + parent::offsetSet($offset, $value); + return; } $this->modelData[$this->collection_key][$offset] = $value; } - public function offsetUnset($offset) + public function offsetUnset($offset): void { if (!is_numeric($offset)) { - return parent::offsetUnset($offset); + parent::offsetUnset($offset); + return; } unset($this->modelData[$this->collection_key][$offset]); } diff --git a/lib/google/src/Google/Model.php b/lib/google/src/Google/Model.php index df8216a80ed..b5848be2de3 100644 --- a/lib/google/src/Google/Model.php +++ b/lib/google/src/Google/Model.php @@ -246,11 +246,12 @@ class Google_Model implements ArrayAccess } } - public function offsetExists($offset) + public function offsetExists($offset): bool { return isset($this->$offset) || isset($this->modelData[$offset]); } + #[\ReturnTypeWillChange] public function offsetGet($offset) { return isset($this->$offset) ? @@ -258,7 +259,7 @@ class Google_Model implements ArrayAccess $this->__get($offset); } - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { if (property_exists($this, $offset)) { $this->$offset = $value; @@ -268,7 +269,7 @@ class Google_Model implements ArrayAccess } } - public function offsetUnset($offset) + public function offsetUnset($offset): void { unset($this->modelData[$offset]); }