Skip to content

Commit

Permalink
API Removed #[\ReturnTypeWillChange] annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Rainville committed Jan 26, 2023
1 parent 8d6fa44 commit 944722f
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 146 deletions.
18 changes: 4 additions & 14 deletions src/Control/HTTPRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
5 changes: 1 addition & 4 deletions src/Dev/BulkLoader_Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? []);
}
Expand Down
33 changes: 7 additions & 26 deletions src/ORM/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 ?? []);
}
Expand All @@ -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)) {
Expand Down Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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]);
}
Expand Down
5 changes: 3 additions & 2 deletions src/ORM/Connect/MySQLQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/Connect/MySQLStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use mysqli_result;
use mysqli_stmt;
use Traversable;

/**
* Provides a record-view for mysqli prepared statements
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/Connect/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
42 changes: 12 additions & 30 deletions src/ORM/DataList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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");
}

/**
Expand Down
21 changes: 7 additions & 14 deletions src/ORM/ListDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -96,8 +91,7 @@ public function remove($itemObject)
$this->list->remove($itemObject);
}

#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): Traversable
{
return $this->list->getIterator();
}
Expand All @@ -122,8 +116,7 @@ public function TotalItems()
return $this->list->count();
}

#[\ReturnTypeWillChange]
public function Count()
public function Count(): int
{
return $this->list->count();
}
Expand Down
Loading

0 comments on commit 944722f

Please sign in to comment.