Skip to content

Commit

Permalink
Merge pull request #2386 from franmomu/remove_key_template
Browse files Browse the repository at this point in the history
Remove key template for iterators
  • Loading branch information
malarzm authored Nov 15, 2021
2 parents aa129d8 + 869de0a commit 9a54beb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 35 deletions.
17 changes: 8 additions & 9 deletions lib/Doctrine/ODM/MongoDB/Iterator/CachingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@
*
* @internal
*
* @template TKey
* @template TValue
* @template-implements Iterator<TKey, TValue>
* @template-implements Iterator<TValue>
*/
final class CachingIterator implements Iterator
{
/** @var array<TKey, TValue> */
/** @var array<mixed, TValue> */
private $items = [];

/** @var Generator<TKey, TValue>|null */
/** @var Generator<mixed, TValue>|null */
private $iterator;

/** @var bool */
Expand All @@ -48,7 +47,7 @@ final class CachingIterator implements Iterator
* behavior of the SPL iterators and allows users to omit an explicit call
* to rewind() before using the other methods.
*
* @param Traversable<TKey, TValue> $iterator
* @param Traversable<mixed, TValue> $iterator
*/
public function __construct(Traversable $iterator)
{
Expand Down Expand Up @@ -78,7 +77,7 @@ public function current()
}

/**
* @return TKey|null
* @return mixed
*/
#[ReturnTypeWillChange]
public function key()
Expand Down Expand Up @@ -135,7 +134,7 @@ private function exhaustIterator(): void
}

/**
* @return Generator<TKey, TValue>
* @return Generator<mixed, TValue>
*/
private function getIterator(): Generator
{
Expand All @@ -161,9 +160,9 @@ private function storeCurrentItem(): void
}

/**
* @param Traversable<TKey, TValue> $traversable
* @param Traversable<mixed, TValue> $traversable
*
* @return Generator<TKey, TValue>
* @return Generator<mixed, TValue>
*/
private function wrapTraversable(Traversable $traversable): Generator
{
Expand Down
17 changes: 8 additions & 9 deletions lib/Doctrine/ODM/MongoDB/Iterator/HydratingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
*
* @psalm-import-type Hints from UnitOfWork
*
* @template TKey
* @template TValue
* @template TDocument of object
* @template-implements Iterator<TKey, TDocument>
* @template-implements Iterator<TValue>
*/
final class HydratingIterator implements Iterator
{
/** @var Generator<TKey, TValue>|null */
/** @var Generator<mixed, TValue>|null */
private $iterator;

/** @var UnitOfWork */
Expand All @@ -42,8 +41,8 @@ final class HydratingIterator implements Iterator
private $unitOfWorkHints;

/**
* @param Traversable<TKey, TValue> $traversable
* @param ClassMetadata<TDocument> $class
* @param Traversable<mixed, TValue> $traversable
* @param ClassMetadata<TDocument> $class
* @psalm-param Hints $unitOfWorkHints
*/
public function __construct(Traversable $traversable, UnitOfWork $unitOfWork, ClassMetadata $class, array $unitOfWorkHints = [])
Expand All @@ -69,7 +68,7 @@ public function current()
}

/**
* @return TKey|null
* @return mixed
*/
#[ReturnTypeWillChange]
public function key()
Expand Down Expand Up @@ -102,7 +101,7 @@ public function valid(): bool
}

/**
* @return Generator<TKey, TValue>
* @return Generator<mixed, TValue>
*/
private function getIterator(): Generator
{
Expand All @@ -124,9 +123,9 @@ private function hydrate(?array $document): ?object
}

/**
* @param Traversable<TKey, TValue> $traversable
* @param Traversable<mixed, TValue> $traversable
*
* @return Generator<TKey, TValue>
* @return Generator<mixed, TValue>
*/
private function wrapTraversable(Traversable $traversable): Generator
{
Expand Down
5 changes: 2 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Iterator/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
namespace Doctrine\ODM\MongoDB\Iterator;

/**
* @template TKey
* @template TValue
* @template-extends \Iterator<TKey, TValue>
* @template-extends \Iterator<mixed, TValue>
*/
interface Iterator extends \Iterator
{
/**
* @psalm-return array<TKey, TValue>
* @psalm-return array<mixed, TValue>
*/
public function toArray(): array;
}
9 changes: 4 additions & 5 deletions lib/Doctrine/ODM/MongoDB/Iterator/PrimingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@

/**
* @psalm-import-type Hints from UnitOfWork
* @template TKey
* @template TValue
* @template TDocument of object
* @template-implements Iterator<TKey, TValue>
* @template-implements Iterator<TValue>
*/
final class PrimingIterator implements Iterator
{
/** @var \Iterator<TKey, TValue> */
/** @var \Iterator<mixed, TValue> */
private $iterator;

/** @var ClassMetadata<TDocument> */
Expand All @@ -43,7 +42,7 @@ final class PrimingIterator implements Iterator
private $referencesPrimed = false;

/**
* @param \Iterator<TKey, TValue> $iterator
* @param \Iterator<mixed, TValue> $iterator
* @param ClassMetadata<TDocument> $class
* @param array<string, callable|null> $primers
* @psalm-param Hints $unitOfWorkHints
Expand Down Expand Up @@ -79,7 +78,7 @@ public function next(): void
}

/**
* @return TKey|null
* @return mixed
*/
#[ReturnTypeWillChange]
public function key()
Expand Down
15 changes: 7 additions & 8 deletions lib/Doctrine/ODM/MongoDB/Iterator/UnrewindableIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
*
* @internal
*
* @template TKey
* @template TValue
* @template-implements Iterator<TKey, TValue>
* @template-implements Iterator<TValue>
*/
final class UnrewindableIterator implements Iterator
{
/** @var Generator<TKey, TValue>|null */
/** @var Generator<mixed, TValue>|null */
private $iterator;

/** @var bool */
Expand All @@ -36,7 +35,7 @@ final class UnrewindableIterator implements Iterator
* Additionally, this mimics behavior of the SPL iterators and allows users
* to omit an explicit call to rewind() before using the other methods.
*
* @param Traversable<TKey, TValue> $iterator
* @param Traversable<mixed, TValue> $iterator
*/
public function __construct(Traversable $iterator)
{
Expand Down Expand Up @@ -70,7 +69,7 @@ public function current()
}

/**
* @return TKey|null
* @return mixed
*/
#[ReturnTypeWillChange]
public function key()
Expand Down Expand Up @@ -121,7 +120,7 @@ private function preventRewinding(string $method): void
}

/**
* @return Generator<TKey, TValue>
* @return Generator<mixed, TValue>
*/
private function getIterator(): Generator
{
Expand All @@ -133,9 +132,9 @@ private function getIterator(): Generator
}

/**
* @param Traversable<TKey, TValue> $traversable
* @param Traversable<mixed, TValue> $traversable
*
* @return Generator<TKey, TValue>
* @return Generator<mixed, TValue>
*/
private function wrapTraversable(Traversable $traversable): Generator
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function getClassName(): string
* Selects all elements from a selectable that match the expression and
* returns a new collection containing these elements.
*
* @return ArrayCollection<int, T>
* @return ArrayCollection<array-key, T>
*/
public function matching(Criteria $criteria): ArrayCollection
{
Expand Down

0 comments on commit 9a54beb

Please sign in to comment.