Completed
Push — master ( c1ef3a...dd8c88 )
by Beñat
03:54
created

PdoTransactionMiddleware::execute()   A

Complexity

Conditions 3
Paths 5

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 5
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Shared Kernel library.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\SharedKernel\Infrastructure\Application\Tactician;
13
14
use League\Tactician\Middleware;
15
use LIN3S\SharedKernel\Exception\Exception;
16
use LIN3S\SharedKernel\Infrastructure\Persistence\Sql\Pdo;
17
18
/**
19
 * @author Beñat Espiña <[email protected]>
20
 */
21
class PdoTransactionMiddleware implements Middleware
22
{
23
    private $pdo;
24
25
    public function __construct(Pdo $pdo)
26
    {
27
        $this->pdo = $pdo;
28
    }
29
30
    public function execute($command, callable $next)
31
    {
32
        $this->pdo->beginTransaction();
33
34
        try {
35
            $returnValue = $next($command);
36
37
            $this->pdo->commit();
38
        } catch (Exception $exception) {
39
            $this->pdo->rollBack();
40
41
            throw $exception;
42
        } catch (\Throwable $exception) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
43
            $this->pdo->rollBack();
44
45
            throw $exception;
46
        }
47
48
        return $returnValue;
49
    }
50
}
51