Skip to content

Commit

Permalink
Avoid PHP 8.1 deprecations with ReturnTypeWillChange
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Oct 15, 2021
1 parent 40fe3fc commit a582d89
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 25 deletions.
11 changes: 5 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Iterator/CachingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ODM\MongoDB\Iterator;

use Generator;
use ReturnTypeWillChange;
use RuntimeException;
use Traversable;

Expand Down Expand Up @@ -68,20 +69,18 @@ public function toArray(): array
}

/**
* @see http://php.net/iterator.current
*
* @return mixed
* @return TValue|false
*/
#[ReturnTypeWillChange]
public function current()
{
return current($this->items);
}

/**
* @see http://php.net/iterator.mixed
*
* @return mixed
* @return TKey|null
*/
#[ReturnTypeWillChange]
public function key()
{
return key($this->items);
Expand Down
13 changes: 7 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Iterator/HydratingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\ODM\MongoDB\UnitOfWork;
use Generator;
use Iterator;
use ReturnTypeWillChange;
use RuntimeException;
use Traversable;

Expand Down Expand Up @@ -59,20 +60,18 @@ public function __destruct()
}

/**
* @see http://php.net/iterator.current
*
* @return mixed
* @return TDocument|null
*/
#[ReturnTypeWillChange]
public function current()
{
return $this->hydrate($this->getIterator()->current());
}

/**
* @see http://php.net/iterator.mixed
*
* @return mixed
* @return TKey|null
*/
#[ReturnTypeWillChange]
public function key()
{
return $this->getIterator()->key();
Expand Down Expand Up @@ -116,6 +115,8 @@ private function getIterator(): Generator

/**
* @param array<string, mixed>|null $document
*
* @return TDocument|null
*/
private function hydrate(?array $document): ?object
{
Expand Down
9 changes: 9 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Iterator/PrimingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\Query\ReferencePrimer;
use Doctrine\ODM\MongoDB\UnitOfWork;
use ReturnTypeWillChange;

use function is_callable;
use function iterator_to_array;
Expand Down Expand Up @@ -61,6 +62,10 @@ public function toArray(): array
return iterator_to_array($this);
}

/**
* @return TValue|null
*/
#[ReturnTypeWillChange]
public function current()
{
$this->primeReferences();
Expand All @@ -73,6 +78,10 @@ public function next(): void
$this->iterator->next();
}

/**
* @return TKey|null
*/
#[ReturnTypeWillChange]
public function key()
{
return $this->iterator->key();
Expand Down
11 changes: 5 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Iterator/UnrewindableIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Generator;
use LogicException;
use ReturnTypeWillChange;
use RuntimeException;
use Traversable;

Expand Down Expand Up @@ -60,20 +61,18 @@ public function toArray(): array
}

/**
* @see http://php.net/iterator.current
*
* @return mixed
* @return TValue|null
*/
#[ReturnTypeWillChange]
public function current()
{
return $this->getIterator()->current();
}

/**
* @see http://php.net/iterator.mixed
*
* @return mixed
* @return TKey|null
*/
#[ReturnTypeWillChange]
public function key()
{
if ($this->iterator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Doctrine\ODM\MongoDB\MongoDBException;
use Doctrine\ODM\MongoDB\UnitOfWork;
use Doctrine\ODM\MongoDB\Utility\CollectionHelper;
use ReturnTypeWillChange;
use Traversable;

use function array_udiff;
use function array_udiff_assoc;
Expand Down Expand Up @@ -461,8 +463,9 @@ public function getValues()
}

/**
* {@inheritdoc}
* @return int
*/
#[ReturnTypeWillChange]
public function count()
{
// Workaround around not being able to directly count inverse collections anymore
Expand Down Expand Up @@ -496,8 +499,9 @@ public function isEmpty()
}

/**
* {@inheritdoc}
* @return Traversable
*/
#[ReturnTypeWillChange]
public function getIterator()
{
$this->initialize();
Expand Down Expand Up @@ -611,8 +615,11 @@ public function __sleep()
/* ArrayAccess implementation */

/**
* @see containsKey()
* @param mixed $offset
*
* @return bool
*/
#[ReturnTypeWillChange]
public function offsetExists($offset)
{
$this->initialize();
Expand All @@ -621,8 +628,11 @@ public function offsetExists($offset)
}

/**
* @see get()
* @param mixed $offset
*
* @return mixed
*/
#[ReturnTypeWillChange]
public function offsetGet($offset)
{
$this->initialize();
Expand All @@ -631,9 +641,12 @@ public function offsetGet($offset)
}

/**
* @see add()
* @see set()
* @param mixed $offset
* @param mixed $value
*
* @return void
*/
#[ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (! isset($offset)) {
Expand All @@ -646,8 +659,11 @@ public function offsetSet($offset, $value)
}

/**
* @see remove()
* @param mixed $offset
*
* @return void
*/
#[ReturnTypeWillChange]
public function offsetUnset($offset)
{
$this->doRemove($offset, true);
Expand Down
7 changes: 7 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@
<file name="tests/Doctrine/ODM/MongoDB/Tests/QueryTest.php"/>
</errorLevel>
</UndefinedConstant>

<UndefinedAttributeClass>
<errorLevel type="suppress">
<!-- Remove it when using PHP 8.1 for running Psalm -->
<referencedClass name="ReturnTypeWillChange" />
</errorLevel>
</UndefinedAttributeClass>
</issueHandlers>
</psalm>

0 comments on commit a582d89

Please sign in to comment.