Skip to content

Commit b0909ca

Browse files
authored
Remove unnecessary assert calls (#2775)
* CursorInterface always extends Traversable, no need to assert on SPL Iterator * Remove duplicate assert
1 parent 02c9ce7 commit b0909ca

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

lib/Doctrine/ODM/MongoDB/Aggregation/Aggregation.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
use Doctrine\ODM\MongoDB\Iterator\Iterator;
1212
use Doctrine\ODM\MongoDB\Iterator\UnrewindableIterator;
1313
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
14-
use Iterator as SPLIterator;
1514
use MongoDB\Collection;
1615
use MongoDB\Driver\CursorInterface;
1716

1817
use function array_merge;
19-
use function assert;
2018

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

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

6358
return $this->prepareIterator($cursor);
6459
}
6560

66-
private function prepareIterator(CursorInterface&SPLIterator $cursor): Iterator
61+
private function prepareIterator(CursorInterface $cursor): Iterator
6762
{
6863
if ($this->classMetadata) {
6964
$cursor = new HydratingIterator($cursor, $this->dm->getUnitOfWork(), $this->classMetadata);

lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use Doctrine\ODM\MongoDB\Utility\CollectionHelper;
3030
use Doctrine\Persistence\Mapping\MappingException;
3131
use InvalidArgumentException;
32-
use Iterator as SplIterator;
3332
use MongoDB\BSON\ObjectId;
3433
use MongoDB\Collection;
3534
use MongoDB\Driver\CursorInterface;
@@ -333,8 +332,8 @@ private function executeUpsert(object $document, array $options): void
333332
$data = ['$set' => ['_id' => $criteria['_id']]];
334333
}
335334

335+
assert($this->collection instanceof Collection);
336336
try {
337-
assert($this->collection instanceof Collection);
338337
$this->collection->updateOne($criteria, $data, $options);
339338

340339
return;
@@ -344,7 +343,6 @@ private function executeUpsert(object $document, array $options): void
344343
}
345344
}
346345

347-
assert($this->collection instanceof Collection);
348346
$this->collection->updateOne($criteria, ['$set' => new stdClass()], $options);
349347
}
350348

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

547-
assert($baseCursor instanceof CursorInterface && $baseCursor instanceof SplIterator);
548-
549545
return $this->wrapCursor($baseCursor);
550546
}
551547

@@ -592,7 +588,7 @@ private function getShardKeyQuery(object $document): array
592588
/**
593589
* Wraps the supplied base cursor in the corresponding ODM class.
594590
*/
595-
private function wrapCursor(SplIterator&CursorInterface $baseCursor): Iterator
591+
private function wrapCursor(CursorInterface $baseCursor): Iterator
596592
{
597593
return new CachingIterator(new HydratingIterator($baseCursor, $this->dm->getUnitOfWork(), $this->class));
598594
}

0 commit comments

Comments
 (0)