diff --git a/backup/util/helper/backup_array_iterator.class.php b/backup/util/helper/backup_array_iterator.class.php index 1fce832ae77..ae0b8a4f521 100644 --- a/backup/util/helper/backup_array_iterator.class.php +++ b/backup/util/helper/backup_array_iterator.class.php @@ -40,23 +40,25 @@ class backup_array_iterator implements iterator { $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; } diff --git a/backup/util/helper/backup_null_iterator.class.php b/backup/util/helper/backup_null_iterator.class.php index 80eb5301a56..9d317e00d91 100644 --- a/backup/util/helper/backup_null_iterator.class.php +++ b/backup/util/helper/backup_null_iterator.class.php @@ -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; } diff --git a/calendar/classes/local/event/entities/repeat_event_collection.php b/calendar/classes/local/event/entities/repeat_event_collection.php index e25a3dc2b8c..0188eac3f95 100644 --- a/calendar/classes/local/event/entities/repeat_event_collection.php +++ b/calendar/classes/local/event/entities/repeat_event_collection.php @@ -99,7 +99,7 @@ class repeat_event_collection implements event_collection_interface { ); } - public function getIterator() { + public function getIterator(): \Traversable { $parentrecord = $this->get_parent_record(); foreach ($this->load_event_records() as $eventrecords) { foreach ($eventrecords as $eventrecord) { diff --git a/calendar/tests/action_event_test.php b/calendar/tests/action_event_test.php index c17a524375f..55881793dba 100644 --- a/calendar/tests/action_event_test.php +++ b/calendar/tests/action_event_test.php @@ -200,7 +200,7 @@ class core_calendar_action_event_test_event_collection implements event_collecti return 2; } - public function getIterator() { + public function getIterator(): \Traversable { foreach ($this->events as $event) { yield $event; } diff --git a/calendar/tests/event_mapper_test.php b/calendar/tests/event_mapper_test.php index 0428de004a4..2fe720b51df 100644 --- a/calendar/tests/event_mapper_test.php +++ b/calendar/tests/event_mapper_test.php @@ -464,7 +464,7 @@ class core_calendar_event_mapper_test_event_collection implements event_collecti return 2; } - public function getIterator() { + public function getIterator(): \Traversable { foreach ($this->events as $event) { yield $event; } diff --git a/calendar/tests/event_test.php b/calendar/tests/event_test.php index 26abea7e6e7..b6cedc6e70f 100644 --- a/calendar/tests/event_test.php +++ b/calendar/tests/event_test.php @@ -136,7 +136,7 @@ class core_calendar_event_test_event_collection implements event_collection_inte return 2; } - public function getIterator() { + public function getIterator(): \Traversable { foreach ($this->events as $event) { yield $event; } diff --git a/course/classes/category.php b/course/classes/category.php index 9a62a0d2f2e..5fa9ebc5686 100644 --- a/course/classes/category.php +++ b/course/classes/category.php @@ -196,7 +196,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr * * @return ArrayIterator */ - public function getIterator() { + public function getIterator(): Traversable { $ret = array(); foreach (self::$coursecatfields as $property => $unused) { if ($this->$property !== false) { diff --git a/course/classes/list_element.php b/course/classes/list_element.php index 5acafff2053..7f8f8137642 100644 --- a/course/classes/list_element.php +++ b/course/classes/list_element.php @@ -336,7 +336,7 @@ class core_course_list_element implements IteratorAggregate { * * @return ArrayIterator */ - public function getIterator() { + public function getIterator(): Traversable { $ret = array('id' => $this->record->id); foreach ($this->record as $property => $value) { $ret[$property] = $value; diff --git a/lib/accesslib.php b/lib/accesslib.php index bf7e1f7d6ab..2ec5e3ca091 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -5217,7 +5217,7 @@ abstract class context extends stdClass implements IteratorAggregate { * 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, diff --git a/lib/classes/chart_axis.php b/lib/classes/chart_axis.php index 1703472bad6..437accdf47a 100644 --- a/lib/classes/chart_axis.php +++ b/lib/classes/chart_axis.php @@ -129,6 +129,7 @@ class chart_axis implements JsonSerializable { * * @return array */ + #[\ReturnTypeWillChange] public function jsonSerialize() { return [ 'label' => $this->label, diff --git a/lib/classes/chart_bar.php b/lib/classes/chart_bar.php index aef8adf1c81..10431c758f5 100644 --- a/lib/classes/chart_bar.php +++ b/lib/classes/chart_bar.php @@ -43,6 +43,7 @@ class chart_bar extends chart_base { * * @return array */ + #[\ReturnTypeWillChange] public function jsonSerialize() { $data = parent::jsonSerialize(); $data['horizontal'] = $this->get_horizontal(); diff --git a/lib/classes/chart_base.php b/lib/classes/chart_base.php index 687a2748a75..3ff4d964d75 100644 --- a/lib/classes/chart_base.php +++ b/lib/classes/chart_base.php @@ -77,6 +77,7 @@ class chart_base implements JsonSerializable, renderable { * * @return array */ + #[\ReturnTypeWillChange] public function jsonSerialize() { global $CFG; return [ diff --git a/lib/classes/chart_line.php b/lib/classes/chart_line.php index 5a55e0e98e6..ba27d10c700 100644 --- a/lib/classes/chart_line.php +++ b/lib/classes/chart_line.php @@ -42,6 +42,7 @@ class chart_line extends chart_base { * * @return array */ + #[\ReturnTypeWillChange] public function jsonSerialize() { $data = parent::jsonSerialize(); $data['smooth'] = $this->get_smooth(); diff --git a/lib/classes/chart_pie.php b/lib/classes/chart_pie.php index 1ad6e560f94..1bc2e657e2c 100644 --- a/lib/classes/chart_pie.php +++ b/lib/classes/chart_pie.php @@ -42,6 +42,7 @@ class chart_pie extends chart_base { * * @return array */ + #[\ReturnTypeWillChange] public function jsonSerialize() { $data = parent::jsonSerialize(); $data['doughnut'] = $this->get_doughnut(); diff --git a/lib/classes/chart_series.php b/lib/classes/chart_series.php index a493748ec6e..85d063f29d8 100644 --- a/lib/classes/chart_series.php +++ b/lib/classes/chart_series.php @@ -183,6 +183,7 @@ class chart_series implements JsonSerializable { * * @return array */ + #[\ReturnTypeWillChange] public function jsonSerialize() { $data = [ 'label' => $this->label, diff --git a/lib/classes/dml/recordset_walk.php b/lib/classes/dml/recordset_walk.php index 3d560cf8fd2..db7867d3ac4 100644 --- a/lib/classes/dml/recordset_walk.php +++ b/lib/classes/dml/recordset_walk.php @@ -88,6 +88,7 @@ class recordset_walk implements \Iterator { * * @return mixed|bool The returned value type will depend on the callback. */ + #[\ReturnTypeWillChange] public function current() { if (!$this->recordset->valid()) { @@ -111,8 +112,8 @@ class recordset_walk implements \Iterator { * * @return void */ - public function next() { - return $this->recordset->next(); + public function next(): void { + $this->recordset->next(); } /** @@ -120,6 +121,7 @@ class recordset_walk implements \Iterator { * * @return int */ + #[\ReturnTypeWillChange] public function key() { return $this->recordset->key(); } @@ -133,7 +135,7 @@ class recordset_walk implements \Iterator { * * @return bool */ - public function valid() { + public function valid(): bool { if (!$valid = $this->recordset->valid()) { $this->close(); } @@ -145,7 +147,7 @@ class recordset_walk implements \Iterator { * * @return void */ - public function rewind() { + public function rewind(): void { // No rewind as it is not implemented in moodle_recordset. return; } diff --git a/lib/classes/event/base.php b/lib/classes/event/base.php index a0cf9f6b7bf..bf38916972a 100644 --- a/lib/classes/event/base.php +++ b/lib/classes/event/base.php @@ -984,7 +984,7 @@ abstract class base implements \IteratorAggregate { * * @return \ArrayIterator */ - public function getIterator() { + public function getIterator(): \Traversable { return new \ArrayIterator($this->data); } diff --git a/lib/dml/moodle_recordset.php b/lib/dml/moodle_recordset.php index 975b253d79e..cd63defb825 100644 --- a/lib/dml/moodle_recordset.php +++ b/lib/dml/moodle_recordset.php @@ -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; } diff --git a/lib/dml/mysqli_native_moodle_recordset.php b/lib/dml/mysqli_native_moodle_recordset.php index 522eac5cacd..29ec49c2390 100644 --- a/lib/dml/mysqli_native_moodle_recordset.php +++ b/lib/dml/mysqli_native_moodle_recordset.php @@ -62,10 +62,12 @@ class mysqli_native_moodle_recordset extends moodle_recordset { return $row; } + #[\ReturnTypeWillChange] public function current() { return (object)$this->current; } + #[\ReturnTypeWillChange] public function key() { // return first column value as key if (!$this->current) { @@ -75,11 +77,11 @@ class mysqli_native_moodle_recordset extends moodle_recordset { 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); } diff --git a/lib/dml/oci_native_moodle_recordset.php b/lib/dml/oci_native_moodle_recordset.php index 55ba1af64d8..e4b5fa7eff0 100644 --- a/lib/dml/oci_native_moodle_recordset.php +++ b/lib/dml/oci_native_moodle_recordset.php @@ -56,10 +56,12 @@ class oci_native_moodle_recordset extends moodle_recordset { return $row; } + #[\ReturnTypeWillChange] public function current() { return (object)$this->current; } + #[\ReturnTypeWillChange] public function key() { // return first column value as key if (!$this->current) { @@ -69,11 +71,11 @@ class oci_native_moodle_recordset extends moodle_recordset { 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); } diff --git a/lib/dml/pdo_moodle_recordset.php b/lib/dml/pdo_moodle_recordset.php index 673d91f30b1..26e6a9ffa54 100644 --- a/lib/dml/pdo_moodle_recordset.php +++ b/lib/dml/pdo_moodle_recordset.php @@ -55,10 +55,12 @@ class pdo_moodle_recordset extends moodle_recordset { return $row; } + #[\ReturnTypeWillChange] public function current() { return (object)$this->current; } + #[\ReturnTypeWillChange] public function key() { // return first column value as key if (!$this->current) { @@ -68,11 +70,11 @@ class pdo_moodle_recordset extends moodle_recordset { 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); } diff --git a/lib/dml/pgsql_native_moodle_recordset.php b/lib/dml/pgsql_native_moodle_recordset.php index 6679934424f..6558651dab5 100644 --- a/lib/dml/pgsql_native_moodle_recordset.php +++ b/lib/dml/pgsql_native_moodle_recordset.php @@ -133,10 +133,12 @@ class pgsql_native_moodle_recordset extends moodle_recordset { return $row; } + #[\ReturnTypeWillChange] public function current() { return (object)$this->current; } + #[\ReturnTypeWillChange] public function key() { // return first column value as key if (!$this->current) { @@ -146,11 +148,11 @@ class pgsql_native_moodle_recordset extends moodle_recordset { 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); } diff --git a/lib/dml/sqlsrv_native_moodle_recordset.php b/lib/dml/sqlsrv_native_moodle_recordset.php index 0bbd85d43d1..3f8621679d6 100644 --- a/lib/dml/sqlsrv_native_moodle_recordset.php +++ b/lib/dml/sqlsrv_native_moodle_recordset.php @@ -105,10 +105,12 @@ class sqlsrv_native_moodle_recordset extends moodle_recordset { return $row; } + #[\ReturnTypeWillChange] public function current() { return (object)$this->current; } + #[\ReturnTypeWillChange] public function key() { // return first column value as key if (!$this->current) { @@ -118,7 +120,7 @@ class sqlsrv_native_moodle_recordset extends moodle_recordset { return $key; } - public function next() { + public function next(): void { if ($this->buffer === null) { $this->current = $this->fetch_next(); } else { @@ -126,7 +128,7 @@ class sqlsrv_native_moodle_recordset extends moodle_recordset { } } - public function valid() { + public function valid(): bool { return !empty($this->current); } diff --git a/lib/dml/tests/fixtures/read_slave_moodle_database_special.php b/lib/dml/tests/fixtures/read_slave_moodle_database_special.php index be09eba0b43..3a8b0d775e2 100644 --- a/lib/dml/tests/fixtures/read_slave_moodle_database_special.php +++ b/lib/dml/tests/fixtures/read_slave_moodle_database_special.php @@ -106,28 +106,31 @@ class read_slave_moodle_recordset_special extends \moodle_recordset { } /** * Iterator interface - * @return stdClass + * @return \stdClass */ + #[\ReturnTypeWillChange] public function current() { - return new stdClass(); + return new \stdClass(); } /** * Iterator interface * @return void */ + #[\ReturnTypeWillChange] public function next() { } /** * Iterator interface * @return mixed */ + #[\ReturnTypeWillChange] public function key() { } /** * Iterator interface * @return bool */ - public function valid() { + public function valid(): bool { return false; } } diff --git a/lib/dml/tests/fixtures/read_slave_moodle_recordset_special.php b/lib/dml/tests/fixtures/read_slave_moodle_recordset_special.php index 452385f557d..8e4b6fdc077 100644 --- a/lib/dml/tests/fixtures/read_slave_moodle_recordset_special.php +++ b/lib/dml/tests/fixtures/read_slave_moodle_recordset_special.php @@ -44,6 +44,7 @@ class read_slave_moodle_recordset_special extends moodle_recordset { * Iterator interface * @return stdClass */ + #[\ReturnTypeWillChange] public function current() { return new stdClass(); } @@ -51,19 +52,20 @@ class read_slave_moodle_recordset_special extends moodle_recordset { * Iterator interface * @return void */ - public function next() { + public function next(): void { } /** * Iterator interface * @return mixed */ + #[\ReturnTypeWillChange] public function key() { } /** * Iterator interface * @return bool */ - public function valid() { + public function valid(): bool { return false; } } diff --git a/lib/filestorage/zip_archive.php b/lib/filestorage/zip_archive.php index 4c5953b342c..1aa4673f313 100644 --- a/lib/filestorage/zip_archive.php +++ b/lib/filestorage/zip_archive.php @@ -364,7 +364,7 @@ class zip_archive extends file_archive { * * @return int number of files */ - public function count() { + public function count(): int { if (!isset($this->za)) { return false; } @@ -509,6 +509,7 @@ class zip_archive extends file_archive { * * @return stdClass */ + #[\ReturnTypeWillChange] public function current() { if (!isset($this->za)) { return false; @@ -522,6 +523,7 @@ class zip_archive extends file_archive { * * @return int current file index */ + #[\ReturnTypeWillChange] public function key() { return $this->pos; } @@ -529,14 +531,14 @@ class zip_archive extends file_archive { /** * Moves forward to next file. */ - public function next() { + public function next(): void { $this->pos++; } /** * Rewinds back to the first file. */ - public function rewind() { + public function rewind(): void { $this->pos = 0; } @@ -545,7 +547,7 @@ class zip_archive extends file_archive { * * @return bool */ - public function valid() { + public function valid(): bool { if (!isset($this->za)) { return false; } diff --git a/lib/modinfolib.php b/lib/modinfolib.php index f0d5ce73a4b..cf9d0c3049b 100644 --- a/lib/modinfolib.php +++ b/lib/modinfolib.php @@ -1568,7 +1568,7 @@ class cm_info implements IteratorAggregate { * * @return ArrayIterator */ - public function getIterator() { + public function getIterator(): Traversable { // Make sure dynamic properties are retrieved prior to view properties. $this->obtain_dynamic_data(); $ret = array(); @@ -3207,7 +3207,7 @@ class section_info implements IteratorAggregate { * * @return ArrayIterator */ - public function getIterator() { + public function getIterator(): Traversable { $ret = array(); foreach (get_object_vars($this) as $key => $value) { if (substr($key, 0, 1) == '_') { diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 806328082fc..2209a3efaf6 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1243,7 +1243,7 @@ class navigation_node_collection implements IteratorAggregate, Countable { * * @return int */ - public function count() { + public function count(): int { return $this->count; } /** @@ -1254,7 +1254,7 @@ class navigation_node_collection implements IteratorAggregate, Countable { * * @return ArrayIterator */ - public function getIterator() { + public function getIterator(): Traversable { return new ArrayIterator($this->collection); } } diff --git a/lib/table/classes/local/filter/filter.php b/lib/table/classes/local/filter/filter.php index 2c9b94bcc5a..29a0ff0699f 100644 --- a/lib/table/classes/local/filter/filter.php +++ b/lib/table/classes/local/filter/filter.php @@ -104,6 +104,7 @@ class filter implements Countable, Iterator, JsonSerializable { /** * Return the current filter value. */ + #[\ReturnTypeWillChange] public function current() { if ($this->iteratorposition === null) { $this->rewind(); @@ -121,6 +122,7 @@ class filter implements Countable, Iterator, JsonSerializable { * * @return int */ + #[\ReturnTypeWillChange] public function key() { if ($this->iteratorposition === null) { $this->rewind(); @@ -258,6 +260,7 @@ class filter implements Countable, Iterator, JsonSerializable { * * @return mixed|object */ + #[\ReturnTypeWillChange] public function jsonSerialize() { return (object) [ 'name' => $this->get_name(), diff --git a/lib/table/classes/local/filter/filterset.php b/lib/table/classes/local/filter/filterset.php index be86f881a18..798d5454908 100644 --- a/lib/table/classes/local/filter/filterset.php +++ b/lib/table/classes/local/filter/filterset.php @@ -295,6 +295,7 @@ abstract class filterset implements JsonSerializable { * * @return mixed|object */ + #[\ReturnTypeWillChange] public function jsonSerialize() { return (object) [ 'jointype' => $this->get_join_type(), diff --git a/lib/tests/completionlib_test.php b/lib/tests/completionlib_test.php index ecd75696b2f..6d30cafaf71 100644 --- a/lib/tests/completionlib_test.php +++ b/lib/tests/completionlib_test.php @@ -1933,23 +1933,25 @@ class core_completionlib_fake_recordset implements Iterator { $this->index = 0; } + #[\ReturnTypeWillChange] public function current() { return $this->values[$this->index]; } + #[\ReturnTypeWillChange] public function key() { return $this->values[$this->index]; } - public function next() { + public function next(): void { $this->index++; } - public function rewind() { + public function rewind(): void { $this->index = 0; } - public function valid() { + public function valid(): bool { return count($this->values) > $this->index; } diff --git a/lib/xmlize.php b/lib/xmlize.php index 78cf82b2a87..c60fa3f9dfc 100644 --- a/lib/xmlize.php +++ b/lib/xmlize.php @@ -42,8 +42,6 @@ defined('MOODLE_INTERNAL') || die(); class xml_format_exception extends moodle_exception { /** @var string */ public $errorstring; - /** @var int */ - public $line; /** @var char */ public $char; /** diff --git a/mod/data/classes/search/sortedcontentqueue.php b/mod/data/classes/search/sortedcontentqueue.php index 12a555b47c5..2cbdc050662 100644 --- a/mod/data/classes/search/sortedcontentqueue.php +++ b/mod/data/classes/search/sortedcontentqueue.php @@ -56,9 +56,9 @@ class sortedcontentqueue extends \SPLPriorityQueue { * * @param int $key1 * @param int $key2 - * @return bool + * @return int */ - public function compare($key1 , $key2) { + public function compare($key1 , $key2): int { $record1 = $this->contents[$key1]; $record2 = $this->contents[$key2]; diff --git a/privacy/classes/local/request/contextlist_base.php b/privacy/classes/local/request/contextlist_base.php index 41dc87e1e0d..1c48a03c99b 100644 --- a/privacy/classes/local/request/contextlist_base.php +++ b/privacy/classes/local/request/contextlist_base.php @@ -121,6 +121,7 @@ abstract class contextlist_base implements * * @return \context */ + #[\ReturnTypeWillChange] public function current() { // It is possible that this context has been deleted and we now have subsequent calls being made with this // contextlist. Exceptions here will stop the further processing of this component and that is why we are @@ -137,7 +138,7 @@ abstract class contextlist_base implements $context = $this->current(); } else { // There are no more context ids left. - return; + return null; } } return $context; @@ -148,6 +149,7 @@ abstract class contextlist_base implements * * @return mixed */ + #[\ReturnTypeWillChange] public function key() { return $this->iteratorposition; } @@ -155,7 +157,7 @@ abstract class contextlist_base implements /** * Move to the next context in the list. */ - public function next() { + public function next(): void { ++$this->iteratorposition; } @@ -164,7 +166,7 @@ abstract class contextlist_base implements * * @return bool */ - public function valid() { + public function valid(): bool { return isset($this->contextids[$this->iteratorposition]); } @@ -174,14 +176,14 @@ abstract class contextlist_base implements * The list of contexts is uniqued during the rewind. * The rewind is called at the start of most iterations. */ - public function rewind() { + public function rewind(): void { $this->iteratorposition = 0; } /** * Return the number of contexts. */ - public function count() { + public function count(): int { return count($this->contextids); } } diff --git a/privacy/classes/local/request/contextlist_collection.php b/privacy/classes/local/request/contextlist_collection.php index 722b541404b..cefd36c2d76 100644 --- a/privacy/classes/local/request/contextlist_collection.php +++ b/privacy/classes/local/request/contextlist_collection.php @@ -117,6 +117,7 @@ class contextlist_collection implements \Iterator, \Countable { * * @return \context */ + #[\ReturnTypeWillChange] public function current() { $key = $this->get_key_from_position(); return $this->contextlists[$key]; @@ -127,6 +128,7 @@ class contextlist_collection implements \Iterator, \Countable { * * @return mixed */ + #[\ReturnTypeWillChange] public function key() { return $this->get_key_from_position(); } @@ -134,7 +136,7 @@ class contextlist_collection implements \Iterator, \Countable { /** * Move to the next context in the list. */ - public function next() { + public function next(): void { ++$this->iteratorposition; } @@ -143,7 +145,7 @@ class contextlist_collection implements \Iterator, \Countable { * * @return bool */ - public function valid() { + public function valid(): bool { return ($this->iteratorposition < count($this->contextlists)); } @@ -153,7 +155,7 @@ class contextlist_collection implements \Iterator, \Countable { * The list of contexts is uniqued during the rewind. * The rewind is called at the start of most iterations. */ - public function rewind() { + public function rewind(): void { $this->iteratorposition = 0; } @@ -174,7 +176,7 @@ class contextlist_collection implements \Iterator, \Countable { /** * Return the number of contexts. */ - public function count() { + public function count(): int { return count($this->contextlists); } } diff --git a/privacy/classes/local/request/userlist_base.php b/privacy/classes/local/request/userlist_base.php index 3a49a222276..0e2566e6b61 100644 --- a/privacy/classes/local/request/userlist_base.php +++ b/privacy/classes/local/request/userlist_base.php @@ -146,6 +146,7 @@ abstract class userlist_base implements * * @return \user */ + #[\ReturnTypeWillChange] public function current() { $user = \core_user::get_user($this->userids[$this->iteratorposition]); @@ -160,7 +161,7 @@ abstract class userlist_base implements $user = $this->current(); } else { // There are no more context ids left. - return; + return null; } } @@ -172,6 +173,7 @@ abstract class userlist_base implements * * @return mixed */ + #[\ReturnTypeWillChange] public function key() { return $this->iteratorposition; } @@ -179,7 +181,7 @@ abstract class userlist_base implements /** * Move to the next user in the list. */ - public function next() { + public function next(): void { ++$this->iteratorposition; } @@ -188,7 +190,7 @@ abstract class userlist_base implements * * @return bool */ - public function valid() { + public function valid(): bool { return isset($this->userids[$this->iteratorposition]) && $this->current(); } @@ -198,14 +200,14 @@ abstract class userlist_base implements * The list of users is uniqued during the rewind. * The rewind is called at the start of most iterations. */ - public function rewind() { + public function rewind(): void { $this->iteratorposition = 0; } /** * Return the number of users. */ - public function count() { + public function count(): int { return count($this->userids); } diff --git a/privacy/classes/local/request/userlist_collection.php b/privacy/classes/local/request/userlist_collection.php index 72eff15ea57..1438e94ea8a 100644 --- a/privacy/classes/local/request/userlist_collection.php +++ b/privacy/classes/local/request/userlist_collection.php @@ -114,6 +114,7 @@ class userlist_collection implements \Iterator, \Countable { * * @return \user */ + #[\ReturnTypeWillChange] public function current() { $key = $this->get_key_from_position(); return $this->userlists[$key]; @@ -124,6 +125,7 @@ class userlist_collection implements \Iterator, \Countable { * * @return mixed */ + #[\ReturnTypeWillChange] public function key() { return $this->get_key_from_position(); } @@ -131,7 +133,7 @@ class userlist_collection implements \Iterator, \Countable { /** * Move to the next user in the list. */ - public function next() { + public function next(): void { ++$this->iteratorposition; } @@ -140,7 +142,7 @@ class userlist_collection implements \Iterator, \Countable { * * @return bool */ - public function valid() { + public function valid(): bool { return ($this->iteratorposition < count($this->userlists)); } @@ -150,7 +152,7 @@ class userlist_collection implements \Iterator, \Countable { * The list of users is uniqued during the rewind. * The rewind is called at the start of most iterations. */ - public function rewind() { + public function rewind(): void { $this->iteratorposition = 0; } @@ -171,7 +173,7 @@ class userlist_collection implements \Iterator, \Countable { /** * Return the number of users. */ - public function count() { + public function count(): int { return count($this->userlists); } } diff --git a/question/engine/questionattempt.php b/question/engine/questionattempt.php index 097465c7a42..31ba3235c6b 100644 --- a/question/engine/questionattempt.php +++ b/question/engine/questionattempt.php @@ -1814,36 +1814,39 @@ class question_attempt_step_iterator implements Iterator, ArrayAccess { } /** @return question_attempt_step */ + #[\ReturnTypeWillChange] public function current() { return $this->offsetGet($this->i); } /** @return int */ + #[\ReturnTypeWillChange] public function key() { return $this->i; } - public function next() { + public function next(): void { ++$this->i; } - public function rewind() { + public function rewind(): void { $this->i = 0; } /** @return bool */ - public function valid() { + public function valid(): bool { return $this->offsetExists($this->i); } /** @return bool */ - public function offsetExists($i) { + public function offsetExists($i): bool { return $i >= 0 && $i < $this->qa->get_num_steps(); } /** @return question_attempt_step */ + #[\ReturnTypeWillChange] public function offsetGet($i) { return $this->qa->get_step($i); } - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { throw new coding_exception('You are only allowed read-only access to question_attempt::states through a question_attempt_step_iterator. Cannot set.'); } - public function offsetUnset($offset) { + public function offsetUnset($offset): void { throw new coding_exception('You are only allowed read-only access to question_attempt::states through a question_attempt_step_iterator. Cannot unset.'); } } @@ -1857,11 +1860,11 @@ class question_attempt_step_iterator implements Iterator, ArrayAccess { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class question_attempt_reverse_step_iterator extends question_attempt_step_iterator { - public function next() { + public function next(): void { --$this->i; } - public function rewind() { + public function rewind(): void { $this->i = $this->qa->get_num_steps() - 1; } } @@ -1933,21 +1936,23 @@ class question_attempt_steps_with_submitted_response_iterator extends question_a } /** @return question_attempt_step */ + #[\ReturnTypeWillChange] public function current() { return $this->offsetGet($this->submittedresponseno); } /** @return int */ + #[\ReturnTypeWillChange] public function key() { return $this->submittedresponseno; } - public function next() { + public function next(): void { ++$this->submittedresponseno; } - public function rewind() { + public function rewind(): void { $this->submittedresponseno = 1; } /** @return bool */ - public function valid() { + public function valid(): bool { return $this->submittedresponseno >= 1 && $this->submittedresponseno <= count($this->stepswithsubmittedresponses); } @@ -1955,7 +1960,7 @@ class question_attempt_steps_with_submitted_response_iterator extends question_a * @param int $submittedresponseno * @return bool */ - public function offsetExists($submittedresponseno) { + public function offsetExists($submittedresponseno): bool { return $submittedresponseno >= 1; } @@ -1963,6 +1968,7 @@ class question_attempt_steps_with_submitted_response_iterator extends question_a * @param int $submittedresponseno * @return question_attempt_step */ + #[\ReturnTypeWillChange] public function offsetGet($submittedresponseno) { if ($submittedresponseno > count($this->stepswithsubmittedresponses)) { return null; @@ -1974,7 +1980,7 @@ class question_attempt_steps_with_submitted_response_iterator extends question_a /** * @return int the count of steps with tries. */ - public function count() { + public function count(): int { return count($this->stepswithsubmittedresponses); } @@ -1993,11 +1999,11 @@ class question_attempt_steps_with_submitted_response_iterator extends question_a } } - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { throw new coding_exception('You are only allowed read-only access to question_attempt::states '. 'through a question_attempt_step_iterator. Cannot set.'); } - public function offsetUnset($offset) { + public function offsetUnset($offset): void { throw new coding_exception('You are only allowed read-only access to question_attempt::states '. 'through a question_attempt_step_iterator. Cannot unset.'); } diff --git a/question/engine/questionusage.php b/question/engine/questionusage.php index 116eca571de..aaf4c86dc21 100644 --- a/question/engine/questionusage.php +++ b/question/engine/questionusage.php @@ -1056,6 +1056,7 @@ class question_attempt_iterator implements Iterator, ArrayAccess { * * @return question_attempt */ + #[\ReturnTypeWillChange] public function current() { return $this->offsetGet(current($this->slots)); } @@ -1065,6 +1066,7 @@ class question_attempt_iterator implements Iterator, ArrayAccess { * * @return int */ + #[\ReturnTypeWillChange] public function key() { return current($this->slots); } @@ -1072,14 +1074,14 @@ class question_attempt_iterator implements Iterator, ArrayAccess { /** * Standard part of the Iterator interface. */ - public function next() { + public function next(): void { next($this->slots); } /** * Standard part of the Iterator interface. */ - public function rewind() { + public function rewind(): void { reset($this->slots); } @@ -1088,7 +1090,7 @@ class question_attempt_iterator implements Iterator, ArrayAccess { * * @return bool */ - public function valid() { + public function valid(): bool { return current($this->slots) !== false; } @@ -1098,7 +1100,7 @@ class question_attempt_iterator implements Iterator, ArrayAccess { * @param int $slot * @return bool */ - public function offsetExists($slot) { + public function offsetExists($slot): bool { return in_array($slot, $this->slots); } @@ -1108,6 +1110,7 @@ class question_attempt_iterator implements Iterator, ArrayAccess { * @param int $slot * @return question_attempt */ + #[\ReturnTypeWillChange] public function offsetGet($slot) { return $this->quba->get_question_attempt($slot); } @@ -1118,7 +1121,7 @@ class question_attempt_iterator implements Iterator, ArrayAccess { * @param int $slot * @param question_attempt $value */ - public function offsetSet($slot, $value) { + public function offsetSet($slot, $value): void { throw new coding_exception('You are only allowed read-only access to ' . 'question_attempt::states through a question_attempt_step_iterator. Cannot set.'); } @@ -1128,7 +1131,7 @@ class question_attempt_iterator implements Iterator, ArrayAccess { * * @param int $slot */ - public function offsetUnset($slot) { + public function offsetUnset($slot): void { throw new coding_exception('You are only allowed read-only access to ' . 'question_attempt::states through a question_attempt_step_iterator. Cannot unset.'); } diff --git a/question/engine/tests/helpers.php b/question/engine/tests/helpers.php index a1abe623985..33d9894c01a 100644 --- a/question/engine/tests/helpers.php +++ b/question/engine/tests/helpers.php @@ -1365,10 +1365,12 @@ class question_test_recordset extends moodle_recordset { $this->close(); } + #[\ReturnTypeWillChange] public function current() { return (object) current($this->records); } + #[\ReturnTypeWillChange] public function key() { if (is_null(key($this->records))) { return false; @@ -1377,11 +1379,11 @@ class question_test_recordset extends moodle_recordset { return reset($current); } - public function next() { + public function next(): void { next($this->records); } - public function valid() { + public function valid(): bool { return !is_null(key($this->records)); } diff --git a/search/classes/skip_future_documents_iterator.php b/search/classes/skip_future_documents_iterator.php index 6297fd80503..1a7d6a8faf1 100644 --- a/search/classes/skip_future_documents_iterator.php +++ b/search/classes/skip_future_documents_iterator.php @@ -67,6 +67,7 @@ class skip_future_documents_iterator implements \Iterator { } } + #[\ReturnTypeWillChange] public function current() { if (!$this->gotcurrent) { $this->currentdoc = $this->parent->current(); @@ -75,16 +76,17 @@ class skip_future_documents_iterator implements \Iterator { return $this->currentdoc; } - public function next() { + public function next(): void { $this->parent->next(); $this->gotcurrent = false; } + #[\ReturnTypeWillChange] public function key() { return $this->parent->key(); } - public function valid() { + public function valid(): bool { // Check that the parent is valid. if (!$this->parent->valid()) { return false; @@ -99,7 +101,7 @@ class skip_future_documents_iterator implements \Iterator { } } - public function rewind() { + public function rewind(): void { $this->parent->rewind(); $this->gotcurrent = false; } diff --git a/search/tests/skip_future_documents_iterator_test.php b/search/tests/skip_future_documents_iterator_test.php index 50ec9ebdf1d..a12ce76ac5b 100644 --- a/search/tests/skip_future_documents_iterator_test.php +++ b/search/tests/skip_future_documents_iterator_test.php @@ -202,6 +202,7 @@ class test_counting_iterator implements \Iterator { * * @return mixed Can return any type. */ + #[\ReturnTypeWillChange] public function current() { $this->count++; return false; @@ -219,7 +220,7 @@ class test_counting_iterator implements \Iterator { /** * Goes on to the next element. */ - public function next() { + public function next(): void { $this->pos++; } @@ -228,6 +229,7 @@ class test_counting_iterator implements \Iterator { * * @throws \coding_exception Always */ + #[\ReturnTypeWillChange] public function key() { throw new \coding_exception('Unsupported'); } @@ -237,14 +239,14 @@ class test_counting_iterator implements \Iterator { * * @return bool True if still valid */ - public function valid() { + public function valid(): bool { return $this->pos < 3; } /** * Rewinds the iterator. */ - public function rewind() { + public function rewind(): void { $this->pos = 0; } }