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

Remove key template for iterators #2386

Merged
merged 1 commit into from
Nov 15, 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
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