GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TransactionalCommandBus::subscribe()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
4
namespace Broadway\Tools\Command;
5
6
use Broadway\CommandHandling\CommandBus;
7
use Broadway\CommandHandling\CommandHandler;
8
use Exception;
9
use Psr\Log\LoggerInterface;
10
use RemiSan\TransactionManager\TransactionManager;
11
use Throwable;
12
13
class TransactionalCommandBus
14
{
15
    /** @var CommandBus */
16
    private $decorated;
17
    /** @var TransactionManager */
18
    private $transactionManager;
19
    /** @var LoggerInterface */
20
    private $logger;
21
22
    public function __construct(CommandBus $bus, TransactionManager $transactionManager, LoggerInterface $logger)
23
    {
24
        $this->decorated = $bus;
25
        $this->transactionManager = $transactionManager;
26
        $this->logger = $logger;
27
    }
28
29
    /**
30
     * @param mixed $command
31
     *
32
     * @throws Throwable
33
     */
34
    public function dispatch($command)
35
    {
36
        $this->transactionManager->beginTransaction();
37
38
        try {
39
            $this->decorated->dispatch($command);
40
            $this->transactionManager->commit();
41
        } catch (Exception $exception) {
42
            $this->rollback($exception);
43
            throw $exception;
44
        }
45
    }
46
47
    /**
48
     * @param CommandHandler $handler
49
     */
50
    public function subscribe(CommandHandler $handler)
51
    {
52
        $this->decorated->subscribe($handler);
53
    }
54
55
    /**
56
     * @param $exception
57
     *
58
     * @throws Exception
59
     */
60
    private function rollback($exception)
61
    {
62
        try {
63
            $this->transactionManager->rollback();
64
        } catch (Exception $rollbackException) {
65
            $this->logger->critical($exception);
66
            throw $rollbackException;
67
        }
68
    }
69
}
70