TransactionEventListener   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 35
ccs 16
cts 18
cp 0.8889
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A onException() 0 6 2
A postPersist() 0 3 1
A __construct() 0 3 1
A preUpdate() 0 5 1
A postRemove() 0 3 1
1
<?php
2
3
namespace Vox\Webservice\Event;
4
5
use Throwable;
6
use Vox\Webservice\Exception\RollbackException;
7
use Vox\Webservice\TransactionInterface;
8
9
class TransactionEventListener
10
{
11
    /**
12
     * @var TransactionInterface
13
     */
14
    private $transaction;
15
    
16 1
    public function __construct(TransactionInterface $transaction)
17
    {
18 1
        $this->transaction = $transaction;
19 1
    }
20
    
21 1
    public function postPersist(LifecycleEvent $event)
22
    {
23 1
        $this->transaction->addCreated($event->getObject());
24 1
    }
25
    
26 1
    public function preUpdate(LifecycleEvent $event)
27
    {
28 1
        $object   = $event->getObject();
29 1
        $original = $event->getObjectManager()->getUnitOfWork()->getOriginalObject($object);
0 ignored issues
show
Bug introduced by
The method getUnitOfWork() does not exist on Doctrine\Common\Persistence\ObjectManager. It seems like you code against a sub-type of Doctrine\Common\Persistence\ObjectManager such as Vox\Webservice\TransferManagerInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        $original = $event->getObjectManager()->/** @scrutinizer ignore-call */ getUnitOfWork()->getOriginalObject($object);
Loading history...
30 1
        $this->transaction->addUpdated($original);
31 1
    }
32
    
33 1
    public function postRemove(LifecycleEvent $event)
34
    {
35 1
        $this->transaction->addDeleted($event->getObject());
36 1
    }
37
    
38 1
    public function onException()
39
    {
40
        try {
41 1
            $this->transaction->rollback();
42
        } catch (Throwable $ex) {
43
            throw new RollbackException($ex);
44
        }
45 1
    }
46
}
47