ORMTransaction   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 58
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A commit() 0 5 1
A rollback() 0 4 1
A contains() 0 4 1
A persist() 0 4 1
A delete() 0 4 1
1
<?php
2
3
namespace Isolate\PersistenceContext\Transaction\Doctrine;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Isolate\PersistenceContext\Transaction;
7
8
final class ORMTransaction implements Transaction
9
{
10
    /**
11
     * @var EntityManagerInterface
12
     */
13
    private $entityManager;
14
15
    /**
16
     * @param EntityManagerInterface $entityManager
17
     */
18
    public function __construct(EntityManagerInterface $entityManager)
19
    {
20
        $this->entityManager = $entityManager;
21
        $this->entityManager->beginTransaction();
22
    }
23
24
    /**
25
     * @return void
26
     */
27
    public function commit()
28
    {
29
        $this->entityManager->flush();
30
        $this->entityManager->getConnection()->commit();
31
    }
32
33
    /**
34
     * @return void
35
     */
36
    public function rollback()
37
    {
38
        $this->entityManager->rollback();
39
    }
40
41
    /**
42
     * @param mixed $entity
43
     * @return boolean
44
     */
45
    public function contains($entity)
46
    {
47
        return $this->entityManager->contains($entity);
48
    }
49
50
    /**
51
     * @param mixed $entity
52
     */
53
    public function persist($entity)
54
    {
55
        $this->entityManager->persist($entity);
56
    }
57
58
    /**
59
     * @param mixed $entity
60
     */
61
    public function delete($entity)
62
    {
63
        $this->entityManager->remove($entity);
64
    }
65
}
66