• 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

91.67
/src/MessageBusDoctrine/Middleware/PreventOuterTransactionMiddleware.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 PreventOuterTransactionMiddleware implements MiddlewareInterface
12
{
13

14
    private EntityManagerInterface $entityManager;
15

16
    private bool $isHandlingRootMessage = false;
17

18
    public function __construct(EntityManagerInterface $entityManager)
1✔
19
    {
20
        $this->entityManager = $entityManager;
1✔
21
    }
1✔
22

23
    public function handle(Envelope $envelope, StackInterface $stack): Envelope
1✔
24
    {
25
        if ($this->isHandlingRootMessage) {
1✔
26
            return $stack->next()->handle($envelope, $stack);
1✔
27
        }
28

29
        if ($this->entityManager->getConnection()->isTransactionActive()) {
1✔
30
            throw new \LogicException('Database transaction was already started.');
1✔
31
        }
32

33
        try {
34
            $this->isHandlingRootMessage = true;
1✔
35
            return $stack->next()->handle($envelope, $stack);
1✔
36
        } finally {
×
37
            $this->isHandlingRootMessage = false;
1✔
38
        }
39
    }
40

41
}
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