diff --git a/src/Control/HTTPRequest.php b/src/Control/HTTPRequest.php index e37feadf556..7dfb4721f4e 100644 --- a/src/Control/HTTPRequest.php +++ b/src/Control/HTTPRequest.php @@ -430,36 +430,26 @@ public function isAjax() /** * Enables the existence of a key-value pair in the request to be checked using * array syntax, so isset($request['title']) will check for $_POST['title'] and $_GET['title'] - * - * @param string $offset - * @return bool */ - #[\ReturnTypeWillChange] - public function offsetExists($offset) + public function offsetExists(mixed $offset): bool { return isset($this->postVars[$offset]) || isset($this->getVars[$offset]); } /** * Access a request variable using array syntax. eg: $request['title'] instead of $request->postVar('title') - * - * @param string $offset - * @return mixed */ - #[\ReturnTypeWillChange] - public function offsetGet($offset) + public function offsetGet(mixed $offset): mixed { return $this->requestVar($offset); } - #[\ReturnTypeWillChange] - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { $this->getVars[$offset] = $value; } - #[\ReturnTypeWillChange] - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { unset($this->getVars[$offset]); unset($this->postVars[$offset]); diff --git a/src/Dev/BulkLoader_Result.php b/src/Dev/BulkLoader_Result.php index d14422786b6..333c89a2af8 100644 --- a/src/Dev/BulkLoader_Result.php +++ b/src/Dev/BulkLoader_Result.php @@ -59,11 +59,8 @@ class BulkLoader_Result implements \Countable /** * Returns the count of all objects which were * created or updated. - * - * @return int */ - #[\ReturnTypeWillChange] - public function Count() + public function Count(): int { return count($this->created ?? []) + count($this->updated ?? []); } diff --git a/src/ORM/ArrayList.php b/src/ORM/ArrayList.php index eae6272dc8c..3d3c98910dc 100644 --- a/src/ORM/ArrayList.php +++ b/src/ORM/ArrayList.php @@ -8,6 +8,7 @@ use SilverStripe\Dev\Debug; use SilverStripe\View\ArrayData; use SilverStripe\View\ViewableData; +use Traversable; /** * A list object that wraps around an array of objects or arrays. @@ -81,10 +82,8 @@ public function setDataClass($class) /** * Return the number of items in this list * - * @return int */ - #[\ReturnTypeWillChange] - public function count() + public function count(): int { return count($this->items ?? []); } @@ -102,11 +101,8 @@ public function exists() /** * Returns an Iterator for this ArrayList. * This function allows you to use ArrayList in foreach loops - * - * @return ArrayIterator */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { foreach ($this->items as $i => $item) { if (is_array($item)) { @@ -794,24 +790,16 @@ protected function shouldExclude($item, $args) /** * Returns whether an item with $key exists - * - * @param mixed $offset - * @return bool */ - #[\ReturnTypeWillChange] - public function offsetExists($offset) + public function offsetExists(mixed $offset): bool { return array_key_exists($offset, $this->items ?? []); } /** * Returns item stored in list with index $key - * - * @param mixed $offset - * @return DataObject */ - #[\ReturnTypeWillChange] - public function offsetGet($offset) + public function offsetGet(mixed $offset): mixed { if ($this->offsetExists($offset)) { return $this->items[$offset]; @@ -821,12 +809,8 @@ public function offsetGet($offset) /** * Set an item with the key in $key - * - * @param mixed $offset - * @param mixed $value */ - #[\ReturnTypeWillChange] - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { if ($offset === null) { $this->items[] = $value; @@ -837,11 +821,8 @@ public function offsetSet($offset, $value) /** * Unset an item with the key in $key - * - * @param mixed $offset */ - #[\ReturnTypeWillChange] - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { unset($this->items[$offset]); } diff --git a/src/ORM/Connect/MySQLQuery.php b/src/ORM/Connect/MySQLQuery.php index 4f8db6993f7..65213e66782 100644 --- a/src/ORM/Connect/MySQLQuery.php +++ b/src/ORM/Connect/MySQLQuery.php @@ -2,6 +2,8 @@ namespace SilverStripe\ORM\Connect; +use Traversable; + /** * A result-set from a MySQL database (using MySQLiConnector) * Note that this class is only used for the results of non-prepared statements @@ -45,8 +47,7 @@ public function __destruct() } } - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { $floatTypes = [MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, MYSQLI_TYPE_NEWDECIMAL]; if (is_object($this->handle)) { diff --git a/src/ORM/Connect/MySQLStatement.php b/src/ORM/Connect/MySQLStatement.php index 81edf8c50fe..3e95195e9c8 100644 --- a/src/ORM/Connect/MySQLStatement.php +++ b/src/ORM/Connect/MySQLStatement.php @@ -4,6 +4,7 @@ use mysqli_result; use mysqli_stmt; +use Traversable; /** * Provides a record-view for mysqli prepared statements @@ -101,8 +102,7 @@ protected function bind() call_user_func_array([$this->statement, 'bind_result'], $variables ?? []); } - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { while ($this->statement->fetch()) { // Dereferenced row diff --git a/src/ORM/Connect/Query.php b/src/ORM/Connect/Query.php index c4c4a4dbf55..b272206673a 100644 --- a/src/ORM/Connect/Query.php +++ b/src/ORM/Connect/Query.php @@ -4,6 +4,7 @@ use SilverStripe\Core\Convert; use Iterator; +use Traversable; /** * Abstract query-result class. A query result provides an iterator that returns a map for each record of a query @@ -147,8 +148,7 @@ public function table() /** * Return the next record in the query result. */ - #[\ReturnTypeWillChange] - abstract public function getIterator(); + abstract public function getIterator(): Traversable; /** * Return the total number of items in the query result. diff --git a/src/ORM/DataList.php b/src/ORM/DataList.php index 4b1f4afc093..8fe1911c1b2 100644 --- a/src/ORM/DataList.php +++ b/src/ORM/DataList.php @@ -6,12 +6,12 @@ use SilverStripe\Dev\Debug; use SilverStripe\ORM\Filters\SearchFilter; use SilverStripe\ORM\Queries\SQLConditionGroup; -use SilverStripe\View\TemplateIterator; use SilverStripe\View\ViewableData; -use ArrayIterator; use Exception; use InvalidArgumentException; use LogicException; +use BadMethodCallException; +use Traversable; /** * Implements a "lazy loading" DataObjectSet. @@ -915,11 +915,8 @@ public function getQueryParams() /** * Returns an Iterator for this DataList. * This function allows you to use DataLists in foreach loops - * - * @return Generator */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { foreach ($this->getFinalisedQuery() as $row) { yield $this->createDataObject($row); @@ -948,11 +945,8 @@ protected function getFinalisedQuery() /** * Return the number of items in this DataList - * - * @return int */ - #[\ReturnTypeWillChange] - public function count() + public function count(): int { if ($this->finalisedQuery) { return $this->finalisedQuery->numRecords(); @@ -1329,12 +1323,8 @@ public function reverse() /** * Returns whether an item with $key exists - * - * @param mixed $key - * @return bool */ - #[\ReturnTypeWillChange] - public function offsetExists($key) + public function offsetExists(mixed $key): bool { return ($this->limit(1, $key)->first() != null); } @@ -1343,37 +1333,29 @@ public function offsetExists($key) * Returns item stored in list with index $key * * The object returned is not cached, unlike {@link DataObject::get_one()} - * - * @param mixed $key - * @return DataObject */ - #[\ReturnTypeWillChange] - public function offsetGet($key) + public function offsetGet(mixed $key): ?DataObject { return $this->limit(1, $key)->first(); } /** * Set an item with the key in $key - * - * @param mixed $key - * @param mixed $value + * @throws BadMethodCallException */ - #[\ReturnTypeWillChange] - public function offsetSet($key, $value) + public function offsetSet(mixed $key, mixed $value): void { - throw new \BadMethodCallException("Can't alter items in a DataList using array-access"); + throw new BadMethodCallException("Can't alter items in a DataList using array-access"); } /** * Unset an item with the key in $key * - * @param mixed $key + * @throws BadMethodCallException */ - #[\ReturnTypeWillChange] - public function offsetUnset($key) + public function offsetUnset(mixed $key): void { - throw new \BadMethodCallException("Can't alter items in a DataList using array-access"); + throw new BadMethodCallException("Can't alter items in a DataList using array-access"); } /** diff --git a/src/ORM/ListDecorator.php b/src/ORM/ListDecorator.php index d3f006e64b5..7a3226dd4df 100644 --- a/src/ORM/ListDecorator.php +++ b/src/ORM/ListDecorator.php @@ -4,6 +4,7 @@ use SilverStripe\View\ViewableData; use LogicException; +use Traversable; /** * A base class for decorators that wrap around a list to provide additional @@ -50,28 +51,22 @@ public function setList($list) return $this; } - // PROXIED METHODS --------------------------------------------------------- - - #[\ReturnTypeWillChange] - public function offsetExists($key) + public function offsetExists(mixed $key): bool { return $this->list->offsetExists($key); } - #[\ReturnTypeWillChange] - public function offsetGet($key) + public function offsetGet(mixed $key): mixed { return $this->list->offsetGet($key); } - #[\ReturnTypeWillChange] - public function offsetSet($key, $value) + public function offsetSet(mixed $key, mixed $value): void { $this->list->offsetSet($key, $value); } - #[\ReturnTypeWillChange] - public function offsetUnset($key) + public function offsetUnset(mixed $key): void { $this->list->offsetUnset($key); } @@ -96,8 +91,7 @@ public function remove($itemObject) $this->list->remove($itemObject); } - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { return $this->list->getIterator(); } @@ -122,8 +116,7 @@ public function TotalItems() return $this->list->count(); } - #[\ReturnTypeWillChange] - public function Count() + public function Count(): int { return $this->list->count(); } diff --git a/src/ORM/Map.php b/src/ORM/Map.php index d062cd4c6c8..a1b81f609d8 100644 --- a/src/ORM/Map.php +++ b/src/ORM/Map.php @@ -3,8 +3,10 @@ namespace SilverStripe\ORM; use ArrayAccess; +use BadMethodCallException; use Countable; use IteratorAggregate; +use Traversable; /** * Creates a map from an SS_List by defining a key column and a value column. @@ -143,15 +145,7 @@ public function push($key, $value) return $this; } - // ArrayAccess - - /** - * @var string $key - * - * @return boolean - */ - #[\ReturnTypeWillChange] - public function offsetExists($key) + public function offsetExists(mixed $key): bool { if (isset($this->firstItems[$key])) { return true; @@ -166,13 +160,7 @@ public function offsetExists($key) return $record != null; } - /** - * @var string $key - * - * @return mixed - */ - #[\ReturnTypeWillChange] - public function offsetGet($key) + public function offsetGet(mixed $key): mixed { if (isset($this->firstItems[$key])) { return $this->firstItems[$key]; @@ -201,11 +189,9 @@ public function offsetGet($key) * {@link DataQuery} instance. In this case, use {@link Map::toArray()} * and manipulate the resulting array. * - * @var string $key - * @var mixed $value + * @throws BadMethodCallException */ - #[\ReturnTypeWillChange] - public function offsetSet($key, $value) + public function offsetSet(mixed $key, mixed $value): void { if (isset($this->firstItems[$key])) { $this->firstItems[$key] = $value; @@ -215,7 +201,7 @@ public function offsetSet($key, $value) $this->lastItems[$key] = $value; } - throw new \BadMethodCallException('Map is read-only. Please use $map->push($key, $value) to append values'); + throw new BadMethodCallException('Map is read-only. Please use $map->push($key, $value) to append values'); } /** @@ -226,39 +212,30 @@ public function offsetSet($key, $value) * {@link DataQuery} instance. In this case, use {@link Map::toArray()} * and manipulate the resulting array. * - * @var string $key - * @var mixed $value + * @throws BadMethodCallException */ - #[\ReturnTypeWillChange] - public function offsetUnset($key) + public function offsetUnset(mixed $key): void { if (isset($this->firstItems[$key])) { unset($this->firstItems[$key]); - return; } if (isset($this->lastItems[$key])) { unset($this->lastItems[$key]); - return; } - throw new \BadMethodCallException( - 'Map is read-only. Unset cannot be called on keys derived from the DataQuery' + throw new BadMethodCallException( + 'Map is read-only. Unset cannot be called on keys derived from the DataQuery.' ); } /** * Returns an Map_Iterator instance for iterating over the complete set * of items in the map. - * - * Satisfies the IteratorAggreagte interface. - * - * @return Map_Iterator */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { $keyField = $this->keyField; $valueField = $this->valueField; @@ -307,11 +284,8 @@ protected function extractValue($item, $key) /** * Returns the count of items in the list including the additional items set * through {@link Map::push()} and {@link Map::unshift}. - * - * @return int */ - #[\ReturnTypeWillChange] - public function count() + public function count(): int { return $this->list->count() + count($this->firstItems ?? []) + diff --git a/src/ORM/PaginatedList.php b/src/ORM/PaginatedList.php index 96a6fed9f56..d68c2f9c18a 100644 --- a/src/ORM/PaginatedList.php +++ b/src/ORM/PaginatedList.php @@ -9,6 +9,7 @@ use ArrayAccess; use Exception; use IteratorIterator; +use Traversable; /** * A decorator that wraps around a data list in order to provide pagination. @@ -208,11 +209,7 @@ public function setLimitItems($limit) return $this; } - /** - * @return IteratorIterator - */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { $pageLength = $this->getPageLength(); if ($this->limitItems && $pageLength) { diff --git a/src/ORM/UnsavedRelationList.php b/src/ORM/UnsavedRelationList.php index 51cde920fd9..d2f3c85b28a 100644 --- a/src/ORM/UnsavedRelationList.php +++ b/src/ORM/UnsavedRelationList.php @@ -5,6 +5,7 @@ use InvalidArgumentException; use ArrayIterator; use SilverStripe\ORM\FieldType\DBField; +use Traversable; /** * An {@link ArrayList} that represents an unsaved relation. @@ -120,11 +121,8 @@ public function dataClass() /** * Returns an Iterator for this relation. - * - * @return ArrayIterator */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { return new ArrayIterator($this->toArray()); } diff --git a/src/View/ViewableData.php b/src/View/ViewableData.php index 6ba6c853b96..a8340536fb6 100644 --- a/src/View/ViewableData.php +++ b/src/View/ViewableData.php @@ -20,6 +20,7 @@ use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\View\SSViewer; +use Traversable; use UnexpectedValueException; /** @@ -601,8 +602,7 @@ public function getXMLValues($fields) * * @return ArrayIterator */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): Traversable { return new ArrayIterator([$this]); } diff --git a/tests/php/ORM/ListDecoratorTest.php b/tests/php/ORM/ListDecoratorTest.php index 0410bba7653..213857aa119 100644 --- a/tests/php/ORM/ListDecoratorTest.php +++ b/tests/php/ORM/ListDecoratorTest.php @@ -166,8 +166,8 @@ public function testEach() public function testOffsetExists() { - $this->list->expects($this->once())->method('offsetExists')->with('foo')->willReturn('mock'); - $this->assertSame('mock', $this->decorator->offsetExists('foo')); + $this->list->expects($this->once())->method('offsetExists')->with('foo')->willReturn(true); + $this->assertSame(true, $this->decorator->offsetExists('foo')); } public function testGetList()