Skip to content

Commit

Permalink
Merge branch 'MDL-76355-master' of https://github.com/marinaglancy/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Nov 29, 2022
2 parents 14d8b7c + b99a931 commit 62b6e49
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
2 changes: 2 additions & 0 deletions lib/google/readme_moodle.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand Down
27 changes: 17 additions & 10 deletions lib/google/src/Google/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,62 @@ 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])) {
reset($this->modelData[$this->collection_key]);
}
}

#[\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;
}
return count($this->modelData[$this->collection_key]);
}

public function offsetExists($offset)
public function offsetExists($offset): bool
{
if (!is_numeric($offset)) {
return parent::offsetExists($offset);
}
return isset($this->modelData[$this->collection_key][$offset]);
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
if (!is_numeric($offset)) {
Expand All @@ -73,18 +78,20 @@ public function offsetGet($offset)
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]);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/google/src/Google/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,20 @@ public function assertIsArray($obj, $method)
}
}

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) ?
$this->$offset :
$this->__get($offset);
}

public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
if (property_exists($this, $offset)) {
$this->$offset = $value;
Expand All @@ -268,7 +269,7 @@ public function offsetSet($offset, $value)
}
}

public function offsetUnset($offset)
public function offsetUnset($offset): void
{
unset($this->modelData[$offset]);
}
Expand Down

0 comments on commit 62b6e49

Please sign in to comment.