Passed
Push — main ( 207cb8...b79353 )
by Fractal
12:49
created

RollbackTransactionOnConsoleSignalEventListener   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 3
c 1
b 0
f 0
dl 0
loc 11
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\TransactionalMessenger\EventListener;
6
7
use FRZB\Component\TransactionalMessenger\Attribute\Transactional;
8
use FRZB\Component\TransactionalMessenger\Exception\DispatchException;
9
use FRZB\Component\TransactionalMessenger\MessageBus\RollbackTransactionInterface as RollbackService;
10
use Symfony\Component\Console\ConsoleEvents;
11
use Symfony\Component\Console\Event\ConsoleSignalEvent;
12
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
13
14
#[AsEventListener(ConsoleEvents::SIGNAL, priority: Transactional::LISTENER_PRIORITY)]
15
class RollbackTransactionOnConsoleSignalEventListener
16
{
17
    public function __construct(
18
        private readonly RollbackService $service,
19
    ) {
20
    }
21
22
    public function __invoke(ConsoleSignalEvent $event): void
23
    {
24
        $this->service->rollback(DispatchException::fromSignal($event));
25
    }
26
}
27