Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return types for PHP 8.1 #8894

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Doctrine/ORM/Internal/Hydration/IterableResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace Doctrine\ORM\Internal\Hydration;

use Iterator;
use ReturnTypeWillChange;

/**
* Represents a result structure that can be iterated over, hydrating row-by-row
Expand Down Expand Up @@ -55,6 +56,7 @@ public function __construct($hydrator)
*
* @throws HydrationException
*/
#[ReturnTypeWillChange]
public function rewind()
{
if ($this->_rewinded === true) {
Expand All @@ -70,6 +72,7 @@ public function rewind()
*
* @return mixed[]|false
*/
#[ReturnTypeWillChange]
public function next()
{
$this->_current = $this->_hydrator->hydrateRow();
Expand All @@ -81,6 +84,7 @@ public function next()
/**
* @return mixed
*/
#[ReturnTypeWillChange]
public function current()
{
return $this->_current;
Expand All @@ -89,6 +93,7 @@ public function current()
/**
* @return int
*/
#[ReturnTypeWillChange]
public function key()
{
return $this->_key;
Expand All @@ -97,6 +102,7 @@ public function key()
/**
* @return bool
*/
#[ReturnTypeWillChange]
public function valid()
{
return $this->_current !== false;
Expand Down
10 changes: 10 additions & 0 deletions lib/Doctrine/ORM/Query/TreeWalkerChainIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use ArrayAccess;
use Doctrine\ORM\AbstractQuery;
use Iterator;
use ReturnTypeWillChange;

use function key;
use function next;
Expand Down Expand Up @@ -58,6 +59,7 @@ public function __construct(TreeWalkerChain $treeWalkerChain, $query, $parserRes
* @return string|false
* @psalm-return class-string<TreeWalker>|false
*/
#[ReturnTypeWillChange]
public function rewind()
{
return reset($this->walkers);
Expand All @@ -66,6 +68,7 @@ public function rewind()
/**
* @return TreeWalker|null
*/
#[ReturnTypeWillChange]
public function current()
{
return $this->offsetGet(key($this->walkers));
Expand All @@ -74,6 +77,7 @@ public function current()
/**
* @return int
*/
#[ReturnTypeWillChange]
public function key()
{
return key($this->walkers);
Expand All @@ -82,6 +86,7 @@ public function key()
/**
* @return TreeWalker|null
*/
#[ReturnTypeWillChange]
public function next()
{
next($this->walkers);
Expand All @@ -92,6 +97,7 @@ public function next()
/**
* {@inheritdoc}
*/
#[ReturnTypeWillChange]
public function valid()
{
return key($this->walkers) !== null;
Expand All @@ -100,6 +106,7 @@ public function valid()
/**
* {@inheritdoc}
*/
#[ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->walkers[$offset]);
Expand All @@ -111,6 +118,7 @@ public function offsetExists($offset)
*
* @return TreeWalker|null
*/
#[ReturnTypeWillChange]
public function offsetGet($offset)
{
if ($this->offsetExists($offset)) {
Expand All @@ -130,6 +138,7 @@ public function offsetGet($offset)
* @param string $value
* @psalm-param array-key|null $offset
*/
#[ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if ($offset === null) {
Expand All @@ -142,6 +151,7 @@ public function offsetSet($offset, $value)
/**
* {@inheritdoc}
*/
#[ReturnTypeWillChange]
public function offsetUnset($offset)
{
if ($this->offsetExists($offset)) {
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/Tools/Console/MetadataFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Countable;
use Doctrine\Persistence\Mapping\ClassMetadata;
use FilterIterator;
use ReturnTypeWillChange;
use RuntimeException;

use function assert;
Expand Down Expand Up @@ -70,6 +71,7 @@ public function __construct(ArrayIterator $metadata, $filter)
/**
* @return bool
*/
#[ReturnTypeWillChange]
public function accept()
{
if (count($this->filter) === 0) {
Expand Down Expand Up @@ -99,6 +101,7 @@ public function accept()
/**
* @return ArrayIterator<int, ClassMetadata>
*/
#[ReturnTypeWillChange]
public function getInnerIterator()
{
$innerIterator = parent::getInnerIterator();
Expand All @@ -111,6 +114,7 @@ public function getInnerIterator()
/**
* @return int
*/
#[ReturnTypeWillChange]
public function count()
{
return count($this->getInnerIterator());
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/ORM/Tools/Pagination/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\ORM\QueryBuilder;
use IteratorAggregate;
use ReturnTypeWillChange;

use function array_key_exists;
use function array_map;
Expand Down Expand Up @@ -117,6 +118,7 @@ public function setUseOutputWalkers($useOutputWalkers)
/**
* {@inheritdoc}
*/
#[ReturnTypeWillChange]
public function count()
{
if ($this->count === null) {
Expand All @@ -135,6 +137,7 @@ public function count()
*
* @psalm-return ArrayIterator<array-key, T>
*/
#[ReturnTypeWillChange]
public function getIterator()
{
$offset = $this->query->getFirstResult();
Expand Down
9 changes: 4 additions & 5 deletions tests/Doctrine/Tests/Mocks/HydratorMockStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace Doctrine\Tests\Mocks;

use ArrayIterator;
use Doctrine\DBAL\Driver\Statement;
use IteratorAggregate;
use PDO;
use Traversable;

use function array_shift;
use function current;
Expand Down Expand Up @@ -127,12 +129,9 @@ public function rowCount()
{
}

/**
* {@inheritdoc}
*/
public function getIterator()
public function getIterator(): Traversable
{
return $this->_resultSet;
return new ArrayIterator($this->_resultSet);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/Doctrine/Tests/Mocks/StatementArrayMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ArrayIterator;
use PDO;
use Traversable;

use function count;
use function current;
Expand All @@ -32,7 +33,7 @@ public function __construct(array $result)
/**
* @psalm-return ArrayIterator<int, mixed>
*/
public function getIterator(): ArrayIterator
public function getIterator(): Traversable
{
return new ArrayIterator($this->_result);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Doctrine/Tests/Mocks/StatementMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace Doctrine\Tests\Mocks;

use Doctrine\DBAL\Driver\Statement;
use EmptyIterator;
use IteratorAggregate;
use PDO;
use Traversable;

/**
* This class is a mock of the Statement interface.
Expand Down Expand Up @@ -97,10 +99,8 @@ public function fetchColumn($columnIndex = 0)
{
}

/**
* {@inheritdoc}
*/
public function getIterator()
public function getIterator(): Traversable
{
return new EmptyIterator();
}
}
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/Models/CMS/CmsGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public function getUsers(): Collection
}

/**
* @return ArrayCollection|Traversable
* @return Collection<int, CmsUser>
*/
public function getIterator()
public function getIterator(): Collection
{
return $this->getUsers();
}
Expand Down