ODMTransaction   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A commit() 0 4 1
A rollback() 0 6 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\ODM\MongoDB\DocumentManager;
6
use Isolate\Exception\UnsupportedOperationException;
7
use Isolate\PersistenceContext\Transaction;
8
9
final class ODMTransaction implements Transaction
10
{
11
    /**
12
     * @var DocumentManager
13
     */
14
    private $documentManager;
15
16
    /**
17
     * @param DocumentManager $documentManager
18
     */
19
    public function __construct(DocumentManager $documentManager)
20
    {
21
        $this->documentManager = $documentManager;
22
    }
23
24
    /**
25
     * @return void
26
     */
27
    public function commit()
28
    {
29
        $this->documentManager->flush();
30
    }
31
32
    /**
33
     * @throws UnsupportedOperationException
34
     */
35
    public function rollback()
36
    {
37
        throw new UnsupportedOperationException(
38
            "Doctrine ODM does not support rollbacks. If you really need them your should consider using ORM instead."
39
        );
40
    }
41
42
    /**
43
     * @param mixed $entity
44
     * @return boolean
45
     */
46
    public function contains($entity)
47
    {
48
        return $this->documentManager->contains($entity);
49
    }
50
51
    /**
52
     * @param mixed $entity
53
     */
54
    public function persist($entity)
55
    {
56
        $this->documentManager->persist($entity);
57
    }
58
59
    /**
60
     * @param mixed $entity
61
     */
62
    public function delete($entity)
63
    {
64
        $this->documentManager->remove($entity);
65
    }
66
}
67