handleForManager()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 10
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\Messenger\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\ReceivedStamp;
11
12
class DoctrineClearEntityManagerMiddleware extends AbstractDoctrineMiddleware
13
{
14 2
    protected function handleForManager(
15
        EntityManagerInterface $entityManager,
16
        Envelope $envelope,
17
        StackInterface $stack
18
    ): Envelope {
19
        try {
20 2
            return $stack->next()->handle($envelope, $stack);
21
        } finally {
22 2
            if (null !== $envelope->last(ReceivedStamp::class)) {
23 2
                $entityManager->clear();
24
            }
25
        }
26
    }
27
}
28