Skip to content

Commit a1ab62c

Browse files
committed
Remove unnecessary check
EventManager::dispatchEvent already checks if there are listeners for the event.
1 parent a1ab7ce commit a1ab62c

File tree

3 files changed

+9
-25
lines changed

3 files changed

+9
-25
lines changed

lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,7 @@ public function hydrate(object $document, array $data, array $hints = []): array
472472
$metadata->invokeLifecycleCallbacks(Events::preLoad, $document, $args);
473473
}
474474

475-
if ($this->evm->hasListeners(Events::preLoad)) {
476-
$this->evm->dispatchEvent(Events::preLoad, new PreLoadEventArgs($document, $this->dm, $data));
477-
}
475+
$this->evm->dispatchEvent(Events::preLoad, new PreLoadEventArgs($document, $this->dm, $data));
478476

479477
// alsoLoadMethods may transform the document before hydration
480478
if (! empty($metadata->alsoLoadMethods)) {
@@ -511,9 +509,7 @@ public function hydrate(object $document, array $data, array $hints = []): array
511509
$metadata->invokeLifecycleCallbacks(Events::postLoad, $document, [new LifecycleEventArgs($document, $this->dm)]);
512510
}
513511

514-
if ($this->evm->hasListeners(Events::postLoad)) {
515-
$this->evm->dispatchEvent(Events::postLoad, new LifecycleEventArgs($document, $this->dm));
516-
}
512+
$this->evm->dispatchEvent(Events::postLoad, new LifecycleEventArgs($document, $this->dm));
517513

518514
return $data;
519515
}

lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,10 @@ protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonS
202202

203203
$class->setParentClasses($nonSuperclassParents);
204204

205-
if (! $this->evm->hasListeners(Events::loadClassMetadata)) {
206-
return;
207-
}
208-
209-
$eventArgs = new LoadClassMetadataEventArgs($class, $this->dm);
210-
$this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
205+
$this->evm->dispatchEvent(
206+
Events::loadClassMetadata,
207+
new LoadClassMetadataEventArgs($class, $this->dm)
208+
);
211209

212210
// phpcs:ignore SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed
213211
if ($class->isChangeTrackingNotify()) {

lib/Doctrine/ODM/MongoDB/UnitOfWork.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,7 @@ public function setDocumentPersister(string $documentName, Persisters\DocumentPe
416416
public function commit(array $options = []): void
417417
{
418418
// Raise preFlush
419-
if ($this->evm->hasListeners(Events::preFlush)) {
420-
$this->evm->dispatchEvent(Events::preFlush, new Event\PreFlushEventArgs($this->dm));
421-
}
419+
$this->evm->dispatchEvent(Events::preFlush, new Event\PreFlushEventArgs($this->dm));
422420

423421
// Compute changes done since last commit.
424422
$this->computeChangeSets();
@@ -448,9 +446,7 @@ public function commit(array $options = []): void
448446
}
449447

450448
// Raise onFlush
451-
if ($this->evm->hasListeners(Events::onFlush)) {
452-
$this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->dm));
453-
}
449+
$this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->dm));
454450

455451
foreach ($this->getClassesForCommitAction($this->documentUpserts) as $classAndDocuments) {
456452
[$class, $documents] = $classAndDocuments;
@@ -473,9 +469,7 @@ public function commit(array $options = []): void
473469
}
474470

475471
// Raise postFlush
476-
if ($this->evm->hasListeners(Events::postFlush)) {
477-
$this->evm->dispatchEvent(Events::postFlush, new Event\PostFlushEventArgs($this->dm));
478-
}
472+
$this->evm->dispatchEvent(Events::postFlush, new Event\PostFlushEventArgs($this->dm));
479473

480474
// Clear up
481475
$this->documentInsertions =
@@ -2437,10 +2431,6 @@ public function clear(?string $documentName = null): void
24372431
}
24382432
}
24392433

2440-
if (! $this->evm->hasListeners(Events::onClear)) {
2441-
return;
2442-
}
2443-
24442434
$this->evm->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this->dm, $documentName));
24452435
}
24462436

0 commit comments

Comments
 (0)