• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nepada / message-bus-doctrine / 4305196931

pending completion
4305196931

Pull #75

github

GitHub
Merge b75c2584f into 50df6e526
Pull Request #75: Update phpstan/phpstan requirement from 1.9.14 to 1.10.3

55 of 56 relevant lines covered (98.21%)

0.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/MessageBusDoctrine/Middleware/ClearEntityManagerMiddleware.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\MessageBusDoctrine\Middleware;
5

6
use Doctrine\ORM\EntityManagerInterface;
7
use Symfony\Component\Messenger\Envelope;
8
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
9
use Symfony\Component\Messenger\Middleware\StackInterface;
10

11
class ClearEntityManagerMiddleware implements MiddlewareInterface
12
{
13

14
    private EntityManagerInterface $entityManager;
15

16
    private bool $clearOnStart;
17

18
    private bool $clearOnError;
19

20
    private bool $clearOnSuccess;
21

22
    public function __construct(EntityManagerInterface $entityManager, bool $clearOnStart = true, bool $clearOnSuccess = true, bool $clearOnError = true)
1✔
23
    {
24
        $this->entityManager = $entityManager;
1✔
25
        $this->clearOnStart = $clearOnStart;
1✔
26
        $this->clearOnError = $clearOnError;
1✔
27
        $this->clearOnSuccess = $clearOnSuccess;
1✔
28
    }
1✔
29

30
    public function handle(Envelope $envelope, StackInterface $stack): Envelope
1✔
31
    {
32
        if ($this->entityManager->getConnection()->isTransactionActive()) {
1✔
33
            return $stack->next()->handle($envelope, $stack);
1✔
34
        }
35

36
        try {
37
            if ($this->clearOnStart) {
1✔
38
                $this->entityManager->clear();
1✔
39
            }
40
            $result = $stack->next()->handle($envelope, $stack);
1✔
41
            if ($this->clearOnSuccess) {
1✔
42
                $this->entityManager->clear();
1✔
43
            }
44
            return $result;
1✔
45

46
        } catch (\Throwable $exception) {
1✔
47
            if ($this->clearOnError) {
1✔
48
                $this->entityManager->clear();
1✔
49
            }
50
            throw $exception;
1✔
51
        }
52
    }
53

54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc