Passed
Push — master ( 79a79c...9c574d )
by Thomas Mauro
02:27
created

handleForManager()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 4
nop 3
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\Laminas\Messenger\Bridge\Doctrine\Middleware;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Symfony\Component\Messenger\Envelope;
9
use Symfony\Component\Messenger\Middleware\StackInterface;
10
use Symfony\Component\Messenger\Stamp\ConsumedByWorkerStamp;
11
12
/**
13
 * @final
14
 */
15
class DoctrineClearEntityManagerMiddleware extends AbstractDoctrineMiddleware
16
{
17
    protected function handleForManager(
18
        EntityManagerInterface $entityManager,
19
        Envelope $envelope,
20
        StackInterface $stack
21
    ): Envelope {
22
        try {
23
            return $stack->next()->handle($envelope, $stack);
24
        } finally {
25
            if (null !== $envelope->last(ConsumedByWorkerStamp::class)) {
26
                $entityManager->clear();
27
            }
28
        }
29
    }
30
}
31