TransactionalCommandBusMiddleware::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 4
nop 2
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