Skip to content

Commit

Permalink
MDL-73424 general: Internal methods must have same type as parent
Browse files Browse the repository at this point in the history
Otherwise the error is thrown in PHP8.1
  • Loading branch information
marinaglancy committed Oct 10, 2022
1 parent cc4fec2 commit 41b93bd
Show file tree
Hide file tree
Showing 42 changed files with 154 additions and 98 deletions.
12 changes: 7 additions & 5 deletions backup/util/helper/backup_array_iterator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,25 @@ public function __construct(array $arr) {
$this->arr = $arr;
}

public function rewind() {
return reset($this->arr);
public function rewind(): void {
reset($this->arr);
}

#[\ReturnTypeWillChange]
public function current() {
return current($this->arr);
}

#[\ReturnTypeWillChange]
public function key() {
return key($this->arr);
}

public function next() {
return next($this->arr);
public function next(): void {
next($this->arr);
}

public function valid() {
public function valid(): bool {
return key($this->arr) !== null;
}

Expand Down
8 changes: 5 additions & 3 deletions backup/util/helper/backup_null_iterator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@
*/
class backup_null_iterator implements iterator {

public function rewind() {
public function rewind(): void {
}

#[\ReturnTypeWillChange]
public function current() {
}

#[\ReturnTypeWillChange]
public function key() {
}

public function next() {
public function next(): void {
}

public function valid() {
public function valid(): bool {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function get_num() {
);
}

public function getIterator() {
public function getIterator(): \Traversable {
$parentrecord = $this->get_parent_record();
foreach ($this->load_event_records() as $eventrecords) {
foreach ($eventrecords as $eventrecord) {
Expand Down
2 changes: 1 addition & 1 deletion calendar/tests/action_event_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function get_num() {
return 2;
}

public function getIterator() {
public function getIterator(): \Traversable {
foreach ($this->events as $event) {
yield $event;
}
Expand Down
2 changes: 1 addition & 1 deletion calendar/tests/event_mapper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public function get_num() {
return 2;
}

public function getIterator() {
public function getIterator(): \Traversable {
foreach ($this->events as $event) {
yield $event;
}
Expand Down
2 changes: 1 addition & 1 deletion calendar/tests/event_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function get_num() {
return 2;
}

public function getIterator() {
public function getIterator(): \Traversable {
foreach ($this->events as $event) {
yield $event;
}
Expand Down
2 changes: 1 addition & 1 deletion course/classes/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function get_plugins_callback_function(string $name) : array {
*
* @return ArrayIterator
*/
public function getIterator() {
public function getIterator(): Traversable {
$ret = array();
foreach (self::$coursecatfields as $property => $unused) {
if ($this->$property !== false) {
Expand Down
2 changes: 1 addition & 1 deletion course/classes/list_element.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public function __set($name, $value) {
*
* @return ArrayIterator
*/
public function getIterator() {
public function getIterator(): Traversable {
$ret = array('id' => $this->record->id);
foreach ($this->record as $property => $value) {
$ret[$property] = $value;
Expand Down
2 changes: 1 addition & 1 deletion lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5217,7 +5217,7 @@ public function __unset($name) {
* Now we can convert context object to array using convert_to_array(),
* and feed it properly to json_encode().
*/
public function getIterator() {
public function getIterator(): Traversable {
$ret = array(
'id' => $this->id,
'contextlevel' => $this->contextlevel,
Expand Down
1 change: 1 addition & 0 deletions lib/classes/chart_axis.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function get_stepsize() {
*
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() {
return [
'label' => $this->label,
Expand Down
1 change: 1 addition & 0 deletions lib/classes/chart_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class chart_bar extends chart_base {
*
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() {
$data = parent::jsonSerialize();
$data['horizontal'] = $this->get_horizontal();
Expand Down
1 change: 1 addition & 0 deletions lib/classes/chart_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function add_series(chart_series $serie) {
*
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() {
global $CFG;
return [
Expand Down
1 change: 1 addition & 0 deletions lib/classes/chart_line.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class chart_line extends chart_base {
*
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() {
$data = parent::jsonSerialize();
$data['smooth'] = $this->get_smooth();
Expand Down
1 change: 1 addition & 0 deletions lib/classes/chart_pie.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class chart_pie extends chart_base {
*
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() {
$data = parent::jsonSerialize();
$data['doughnut'] = $this->get_doughnut();
Expand Down
1 change: 1 addition & 0 deletions lib/classes/chart_series.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public function has_colored_values() {
*
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() {
$data = [
'label' => $this->label,
Expand Down
10 changes: 6 additions & 4 deletions lib/classes/dml/recordset_walk.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function __destruct() {
*
* @return mixed|bool The returned value type will depend on the callback.
*/
#[\ReturnTypeWillChange]
public function current() {

if (!$this->recordset->valid()) {
Expand All @@ -111,15 +112,16 @@ public function current() {
*
* @return void
*/
public function next() {
return $this->recordset->next();
public function next(): void {
$this->recordset->next();
}

/**
* Returns current record key.
*
* @return int
*/
#[\ReturnTypeWillChange]
public function key() {
return $this->recordset->key();
}
Expand All @@ -133,7 +135,7 @@ public function key() {
*
* @return bool
*/
public function valid() {
public function valid(): bool {
if (!$valid = $this->recordset->valid()) {
$this->close();
}
Expand All @@ -145,7 +147,7 @@ public function valid() {
*
* @return void
*/
public function rewind() {
public function rewind(): void {
// No rewind as it is not implemented in moodle_recordset.
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/event/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ public function __isset($name) {
*
* @return \ArrayIterator
*/
public function getIterator() {
public function getIterator(): \Traversable {
return new \ArrayIterator($this->data);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/dml/moodle_recordset.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ abstract class moodle_recordset implements Iterator {
* Rewinds are not supported!
* @return void
*/
public function rewind() {
public function rewind(): void {
// no seeking, sorry - let's ignore it ;-)
return;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/dml/mysqli_native_moodle_recordset.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ private function fetch_next() {
return $row;
}

#[\ReturnTypeWillChange]
public function current() {
return (object)$this->current;
}

#[\ReturnTypeWillChange]
public function key() {
// return first column value as key
if (!$this->current) {
Expand All @@ -75,11 +77,11 @@ public function key() {
return $key;
}

public function next() {
public function next(): void {
$this->current = $this->fetch_next();
}

public function valid() {
public function valid(): bool {
return !empty($this->current);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/dml/oci_native_moodle_recordset.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ private function fetch_next() {
return $row;
}

#[\ReturnTypeWillChange]
public function current() {
return (object)$this->current;
}

#[\ReturnTypeWillChange]
public function key() {
// return first column value as key
if (!$this->current) {
Expand All @@ -69,11 +71,11 @@ public function key() {
return $key;
}

public function next() {
public function next(): void {
$this->current = $this->fetch_next();
}

public function valid() {
public function valid(): bool {
return !empty($this->current);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/dml/pdo_moodle_recordset.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ private function fetch_next() {
return $row;
}

#[\ReturnTypeWillChange]
public function current() {
return (object)$this->current;
}

#[\ReturnTypeWillChange]
public function key() {
// return first column value as key
if (!$this->current) {
Expand All @@ -68,11 +70,11 @@ public function key() {
return $key;
}

public function next() {
public function next(): void {
$this->current = $this->fetch_next();
}

public function valid() {
public function valid(): bool {
return !empty($this->current);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/dml/pgsql_native_moodle_recordset.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ private function fetch_next() {
return $row;
}

#[\ReturnTypeWillChange]
public function current() {
return (object)$this->current;
}

#[\ReturnTypeWillChange]
public function key() {
// return first column value as key
if (!$this->current) {
Expand All @@ -146,11 +148,11 @@ public function key() {
return $key;
}

public function next() {
public function next(): void {
$this->current = $this->fetch_next();
}

public function valid() {
public function valid(): bool {
return !empty($this->current);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/dml/sqlsrv_native_moodle_recordset.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ private function fetch_next() {
return $row;
}

#[\ReturnTypeWillChange]
public function current() {
return (object)$this->current;
}

#[\ReturnTypeWillChange]
public function key() {
// return first column value as key
if (!$this->current) {
Expand All @@ -118,15 +120,15 @@ public function key() {
return $key;
}

public function next() {
public function next(): void {
if ($this->buffer === null) {
$this->current = $this->fetch_next();
} else {
$this->current = array_shift($this->buffer);
}
}

public function valid() {
public function valid(): bool {
return !empty($this->current);
}

Expand Down
Loading

0 comments on commit 41b93bd

Please sign in to comment.