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.
Completed
Pull Request — master (#2)
by Pol-Valentin
03:50
created

TransactionalCommandBus::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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