TransactionEventListener::onException()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.5

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 2
cts 4
cp 0.5
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2.5
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