TransactionalEventBusMiddleware::__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\EventBus;
4
5
use NilPortugues\MessageBus\EventBus\Contracts\Event;
6
use NilPortugues\MessageBus\EventBus\Contracts\EventBusMiddleware as EventBusMiddlewareInterface;
7
use PDO;
8
9
/**
10
 * Class TransactionalEventBusMiddleware.
11
 */
12
class TransactionalEventBusMiddleware implements EventBusMiddlewareInterface
13
{
14
    /** @var PDO */
15
    protected $pdo;
16
17
    /**
18
     * TransactionalEventBusMiddleware constructor.
19
     *
20
     * @param PDO $pdo
21
     */
22
    public function __construct(PDO $pdo)
23
    {
24
        $this->pdo = $pdo;
25
    }
26
27
    /**
28
     * @param Event         $event
29
     * @param callable|null $next
30
     */
31 View Code Duplication
    public function __invoke(Event $event, 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...
32
    {
33
        try {
34
            $this->pdo->beginTransaction();
35
            $next($event);
36
            $this->pdo->commit();
37
        } catch (\PDOException $exception) {
38
            $this->pdo->rollBack();
39
            throw $exception;
40
        }
41
    }
42
}
43