Skip to content
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
7 changes: 1 addition & 6 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
use Doctrine\ODM\MongoDB\Iterator\Iterator;
use Doctrine\ODM\MongoDB\Iterator\UnrewindableIterator;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Iterator as SPLIterator;
use MongoDB\Collection;
use MongoDB\Driver\CursorInterface;

use function array_merge;
use function assert;

/** @phpstan-import-type PipelineExpression from Builder */
final class Aggregation implements IterableResult
Expand Down Expand Up @@ -56,14 +54,11 @@ public function getIterator(): Iterator
$options = array_merge($this->options, ['cursor' => true]);

$cursor = $this->collection->aggregate($this->pipeline, $options);
// This assertion can be dropped when requiring mongodb/mongodb 1.17.0
assert($cursor instanceof CursorInterface);
assert($cursor instanceof SPLIterator);

return $this->prepareIterator($cursor);
}

private function prepareIterator(CursorInterface&SPLIterator $cursor): Iterator
private function prepareIterator(CursorInterface $cursor): Iterator
{
if ($this->classMetadata) {
$cursor = new HydratingIterator($cursor, $this->dm->getUnitOfWork(), $this->classMetadata);
Expand Down
8 changes: 2 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Doctrine\ODM\MongoDB\Utility\CollectionHelper;
use Doctrine\Persistence\Mapping\MappingException;
use InvalidArgumentException;
use Iterator as SplIterator;
use MongoDB\BSON\ObjectId;
use MongoDB\Collection;
use MongoDB\Driver\CursorInterface;
Expand Down Expand Up @@ -333,8 +332,8 @@ private function executeUpsert(object $document, array $options): void
$data = ['$set' => ['_id' => $criteria['_id']]];
}

assert($this->collection instanceof Collection);
try {
assert($this->collection instanceof Collection);
$this->collection->updateOne($criteria, $data, $options);

return;
Expand All @@ -344,7 +343,6 @@ private function executeUpsert(object $document, array $options): void
}
}

assert($this->collection instanceof Collection);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate assert.

$this->collection->updateOne($criteria, ['$set' => new stdClass()], $options);
}

Expand Down Expand Up @@ -544,8 +542,6 @@ public function loadAll(array $criteria = [], ?array $sort = null, ?int $limit =
assert($this->collection instanceof Collection);
$baseCursor = $this->collection->find($criteria, $options);

assert($baseCursor instanceof CursorInterface && $baseCursor instanceof SplIterator);

return $this->wrapCursor($baseCursor);
}

Expand Down Expand Up @@ -592,7 +588,7 @@ private function getShardKeyQuery(object $document): array
/**
* Wraps the supplied base cursor in the corresponding ODM class.
*/
private function wrapCursor(SplIterator&CursorInterface $baseCursor): Iterator
private function wrapCursor(CursorInterface $baseCursor): Iterator
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the iterators (CachingIterator, HydratingIterator and UnrewindableIterator) take a Transversable. They don't need that we assert the SPL Iterable type.

{
return new CachingIterator(new HydratingIterator($baseCursor, $this->dm->getUnitOfWork(), $this->class));
}
Expand Down