ODMTransaction::delete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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