TransactionalInterceptor   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 2
c 4
b 1
f 1
lcom 1
cbo 4
dl 0
loc 22
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A invoke() 0 14 2
1
<?php
2
/**
3
 * This file is part of the Ray.DoctrineOrmModule package
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Ray\DoctrineOrmModule;
8
9
use Ray\Aop\MethodInterceptor;
10
use Ray\Aop\MethodInvocation;
11
use Ray\DoctrineOrmModule\Exception\RollbackException;
12
13
class TransactionalInterceptor implements MethodInterceptor
14
{
15
    use EntityManagerInject;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 4
    public function invoke(MethodInvocation $invocation)
21
    {
22 4
        $result = null;
23
24
        try {
25 4
            $this->entityManager->transactional(function () use ($invocation, &$result) {
26 4
                $result = $invocation->proceed();
27 4
            });
28 4
        } catch (\Exception $e) {
29 2
            throw new RollbackException('Transaction rolled back.', 0, $e);
30
        }
31
32 2
        return $result;
33
    }
34
}
35