Conditions | 3 |
Paths | 7 |
Total Lines | 26 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 3.1105 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | 2 | protected function handleForManager( |
|
17 | EntityManagerInterface $entityManager, |
||
18 | Envelope $envelope, |
||
19 | StackInterface $stack |
||
20 | ): Envelope { |
||
21 | 2 | $entityManager->getConnection()->beginTransaction(); |
|
22 | |||
23 | try { |
||
24 | 2 | $envelope = $stack->next()->handle($envelope, $stack); |
|
25 | 1 | $entityManager->flush(); |
|
26 | 1 | $entityManager->getConnection()->commit(); |
|
27 | |||
28 | 1 | return $envelope; |
|
29 | 1 | } catch (Throwable $exception) { |
|
30 | 1 | $entityManager->getConnection()->rollBack(); |
|
31 | |||
32 | 1 | if ($exception instanceof HandlerFailedException) { |
|
33 | // Remove all HandledStamp from the envelope so the retry will execute all handlers again. |
||
34 | // When a handler fails, the queries of allegedly successful previous handlers just got rolled back. |
||
35 | throw new HandlerFailedException( |
||
36 | $exception->getEnvelope()->withoutAll(HandledStamp::class), |
||
37 | $exception->getNestedExceptions() |
||
38 | ); |
||
39 | } |
||
40 | |||
41 | 1 | throw $exception; |
|
42 | } |
||
45 |