TransactionalCommandBusMiddleware::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace NilPortugues\MessageBus\CommandBus;
4
5
use NilPortugues\MessageBus\CommandBus\Contracts\Command;
6
use NilPortugues\MessageBus\CommandBus\Contracts\CommandBusMiddleware as CommandBusMiddlewareInterface;
7
use PDO;
8
9
class TransactionalCommandBusMiddleware implements CommandBusMiddlewareInterface
10
{
11
    /** @var PDO */
12
    protected $pdo;
13
14
    /**
15
     * TransactionalCommandBusMiddleware constructor.
16
     *
17
     * @param PDO $pdo
18
     */
19
    public function __construct(PDO $pdo)
20
    {
21
        $this->pdo = $pdo;
22
    }
23
24
    /**
25
     * @param Command       $command
26
     * @param callable|null $next
27
     */
28 View Code Duplication
    public function __invoke(Command $command, callable $next = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        try {
31
            $this->pdo->beginTransaction();
32
            $next($command);
33
            $this->pdo->commit();
34
        } catch (\PDOException $exception) {
35
            $this->pdo->rollBack();
36
            throw $exception;
37
        }
38
    }
39
}
40