Passed
Push — main ( 25ab27...21c65b )
by Proyecto
08:42
created

Transactional   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 23
ccs 7
cts 10
cp 0.7
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 14 2
A __construct() 0 3 1
1
<?php
2
3
namespace ProyectoTAU\TAU\Common;
4
5
use League\Tactician\Middleware;
6
7
class Transactional implements Middleware
8
{
9
    private object $entityManager;
10
11 68
    public function __construct(object $entityManager)
12
    {
13 68
        $this->entityManager = $entityManager;
14 68
    }
15
16 68
    public function execute(object $command, callable $next)
17
    {
18 68
        $this->entityManager->begin();
19
20
        try {
21
22 68
            $next($command);
23
24
        } catch (\Exception $e){
25
            $this->entityManager->rollback();
26
            throw $e;
27
        }
28
29 68
        $this->entityManager->commit();
30 68
    }
31
}
32