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   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 57
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A dispatch() 0 12 2
A subscribe() 0 4 1
A rollback() 0 9 2
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
}