Skip to content

Commit 2bbd045

Browse files
committed
DocumentPersister::$collection is always set, make it non-nullable
1 parent 3783f0e commit 2bbd045

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
*/
9090
final class DocumentPersister
9191
{
92-
private ?Collection $collection = null;
92+
private Collection $collection;
9393

9494
private ?Bucket $bucket = null;
9595

@@ -226,7 +226,6 @@ public function executeInserts(array $options = []): void
226226
}
227227

228228
try {
229-
assert($this->collection instanceof Collection);
230229
$this->collection->insertMany($inserts, $options);
231230
} catch (DriverException $e) {
232231
$this->queuedInserts = [];
@@ -334,7 +333,6 @@ private function executeUpsert(object $document, array $options): void
334333
}
335334

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

340338
return;
@@ -344,7 +342,6 @@ private function executeUpsert(object $document, array $options): void
344342
}
345343
}
346344

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

@@ -398,7 +395,6 @@ public function update(object $document, array $options = []): void
398395

399396
$options = $this->getWriteOptions($options);
400397

401-
assert($this->collection instanceof Collection);
402398
$result = $this->collection->updateOne($query, $update, $options);
403399

404400
if (($this->class->isVersioned || $this->class->isLockable) && $result->getModifiedCount() !== 1) {
@@ -439,7 +435,6 @@ public function delete(object $document, array $options = []): void
439435

440436
$options = $this->getWriteOptions($options);
441437

442-
assert($this->collection instanceof Collection);
443438
$result = $this->collection->deleteOne($query, $options);
444439

445440
if (($this->class->isVersioned || $this->class->isLockable) && ! $result->getDeletedCount()) {
@@ -452,7 +447,6 @@ public function delete(object $document, array $options = []): void
452447
*/
453448
public function refresh(object $document): void
454449
{
455-
assert($this->collection instanceof Collection);
456450
$query = $this->getQueryForDocument($document);
457451
$data = $this->collection->findOne($query);
458452
if ($data === null) {
@@ -498,7 +492,6 @@ public function load($criteria, ?object $document = null, array $hints = [], int
498492
$options['sort'] = $this->prepareSort($sort);
499493
}
500494

501-
assert($this->collection instanceof Collection);
502495
$result = $this->collection->findOne($criteria, $options);
503496
$result = $result !== null ? (array) $result : null;
504497

@@ -541,7 +534,6 @@ public function loadAll(array $criteria = [], ?array $sort = null, ?int $limit =
541534
$options['skip'] = $skip;
542535
}
543536

544-
assert($this->collection instanceof Collection);
545537
$baseCursor = $this->collection->find($criteria, $options);
546538

547539
assert($baseCursor instanceof CursorInterface && $baseCursor instanceof SplIterator);
@@ -603,7 +595,6 @@ private function wrapCursor(SplIterator&CursorInterface $baseCursor): Iterator
603595
public function exists(object $document): bool
604596
{
605597
$id = $this->class->getIdentifierObject($document);
606-
assert($this->collection instanceof Collection);
607598

608599
return (bool) $this->collection->findOne(['_id' => $id], ['_id']);
609600
}
@@ -616,7 +607,7 @@ public function lock(object $document, int $lockMode): void
616607
$id = $this->uow->getDocumentIdentifier($document);
617608
$criteria = ['_id' => $this->class->getDatabaseIdentifierValue($id)];
618609
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
619-
assert($this->collection instanceof Collection);
610+
620611
$this->collection->updateOne($criteria, ['$set' => [$lockMapping['name'] => $lockMode]]);
621612
$this->class->reflFields[$this->class->lockField]->setValue($document, $lockMode);
622613
}
@@ -629,7 +620,7 @@ public function unlock(object $document): void
629620
$id = $this->uow->getDocumentIdentifier($document);
630621
$criteria = ['_id' => $this->class->getDatabaseIdentifierValue($id)];
631622
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
632-
assert($this->collection instanceof Collection);
623+
633624
$this->collection->updateOne($criteria, ['$unset' => [$lockMapping['name'] => true]]);
634625
$this->class->reflFields[$this->class->lockField]->setValue($document, null);
635626
}

0 commit comments

Comments
 (0)