Merge pull request #10639 from creative-commoners/pulls/5/no-return-type-will-change

API Removed #[\ReturnTypeWillChange] annotations
This commit is contained in:
Guy Sartorelli 2023-01-27 09:49:38 +13:00 committed by GitHub
commit 4e92d25b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 59 additions and 146 deletions

View File

@ -430,36 +430,26 @@ class HTTPRequest implements ArrayAccess
/**
* 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]);

View File

@ -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 ?? []);
}

View File

@ -8,6 +8,7 @@ use LogicException;
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 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
/**
* 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 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
/**
* 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 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
/**
* 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 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
/**
* 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 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
/**
* 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]);
}

View File

@ -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 @@ class MySQLQuery extends Query
}
}
#[\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)) {

View File

@ -4,6 +4,7 @@ namespace SilverStripe\ORM\Connect;
use mysqli_result;
use mysqli_stmt;
use Traversable;
/**
* Provides a record-view for mysqli prepared statements
@ -101,8 +102,7 @@ class MySQLStatement extends Query
call_user_func_array([$this->statement, 'bind_result'], $variables ?? []);
}
#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): Traversable
{
while ($this->statement->fetch()) {
// Dereferenced row

View File

@ -4,6 +4,7 @@ namespace SilverStripe\ORM\Connect;
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 @@ abstract class Query implements \IteratorAggregate
/**
* 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.

View File

@ -6,12 +6,12 @@ use SilverStripe\Core\Injector\Injector;
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 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li
/**
* 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 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li
/**
* 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 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li
/**
* 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 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li
* 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");
}
/**

View File

@ -4,6 +4,7 @@ namespace SilverStripe\ORM;
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 @@ abstract class ListDecorator extends ViewableData implements SS_List, Sortable,
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 @@ abstract class ListDecorator extends ViewableData implements SS_List, Sortable,
$this->list->remove($itemObject);
}
#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): Traversable
{
return $this->list->getIterator();
}
@ -122,8 +116,7 @@ abstract class ListDecorator extends ViewableData implements SS_List, Sortable,
return $this->list->count();
}
#[\ReturnTypeWillChange]
public function Count()
public function Count(): int
{
return $this->list->count();
}

View File

@ -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 @@ class Map implements ArrayAccess, Countable, IteratorAggregate
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 @@ class Map implements ArrayAccess, Countable, IteratorAggregate
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 @@ class Map implements ArrayAccess, Countable, IteratorAggregate
* {@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 @@ class Map implements ArrayAccess, Countable, IteratorAggregate
$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 @@ class Map implements ArrayAccess, Countable, IteratorAggregate
* {@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 @@ class Map implements ArrayAccess, Countable, IteratorAggregate
/**
* 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 ?? []) +

View File

@ -9,6 +9,7 @@ use SilverStripe\View\ArrayData;
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 @@ class PaginatedList extends ListDecorator
return $this;
}
/**
* @return IteratorIterator
*/
#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): Traversable
{
$pageLength = $this->getPageLength();
if ($this->limitItems && $pageLength) {

View File

@ -5,6 +5,7 @@ namespace SilverStripe\ORM;
use InvalidArgumentException;
use ArrayIterator;
use SilverStripe\ORM\FieldType\DBField;
use Traversable;
/**
* An {@link ArrayList} that represents an unsaved relation.
@ -120,11 +121,8 @@ class UnsavedRelationList extends ArrayList implements Relation
/**
* Returns an Iterator for this relation.
*
* @return ArrayIterator
*/
#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): Traversable
{
return new ArrayIterator($this->toArray());
}

View File

@ -20,6 +20,7 @@ use SilverStripe\ORM\ArrayLib;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\View\SSViewer;
use Traversable;
use UnexpectedValueException;
/**
@ -601,8 +602,7 @@ class ViewableData implements IteratorAggregate
*
* @return ArrayIterator
*/
#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): Traversable
{
return new ArrayIterator([$this]);
}

View File

@ -166,8 +166,8 @@ class ListDecoratorTest extends SapphireTest
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()