ManagesEntities::commitEntities()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Nord\Lumen\Core\Traits;
4
5
use Doctrine\Common\Persistence\ObjectRepository;
6
use Doctrine\ORM\EntityManagerInterface;
7
8
trait ManagesEntities
9
{
10
    /**
11
     * @param mixed $entity
12
     */
13
    private function saveEntity($entity)
14
    {
15
        $this->getEntityManager()->persist($entity);
16
    }
17
18
    /**
19
     * @param mixed $entity
20
     */
21
    private function saveEntityAndCommit($entity)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
22
    {
23
        $this->saveEntity($entity);
24
        $this->commitEntities();
25
    }
26
27
    /**
28
     * @param mixed $entity
29
     */
30
    private function updateEntity($entity)
31
    {
32
        $this->getEntityManager()->merge($entity);
33
    }
34
35
    /**
36
     * @param mixed $entity
37
     */
38
    private function updateEntityAndCommit($entity)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
39
    {
40
        $this->updateEntity($entity);
41
        $this->commitEntities();
42
    }
43
44
    /**
45
     * @param mixed $entity
46
     */
47
    private function deleteEntity($entity)
48
    {
49
        $this->getEntityManager()->remove($entity);
50
    }
51
52
    /**
53
     * @param mixed $entity
54
     */
55
    private function deleteEntityAndCommit($entity)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
56
    {
57
        $this->deleteEntity($entity);
58
        $this->commitEntities();
59
    }
60
61
    /**
62
     *
63
     */
64
    private function commitEntities()
65
    {
66
        $this->getEntityManager()->flush();
67
    }
68
69
    /**
70
     * @param mixed $entity
71
     */
72
    private function refreshEntity($entity)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
73
    {
74
        $this->getEntityManager()->refresh($entity);
75
    }
76
77
    /**
78
     * @param string $name
79
     */
80
    private function enableEntityFilter($name)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
81
    {
82
        $this->getEntityManager()->getFilters()->enable($name);
83
    }
84
85
    /**
86
     * @param string $name
87
     */
88
    private function disableEntityFilter($name)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
89
    {
90
        // For some weird reason the filter needs to be enabled first in order to be disabled.
91
        $this->getEntityManager()->getFilters()->enable($name);
92
        $this->getEntityManager()->getFilters()->disable($name);
93
    }
94
95
    /**
96
     * @param string $entityClassName
97
     *
98
     * @return ObjectRepository
99
     */
100
    private function getEntityRepository($entityClassName)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
101
    {
102
        return $this->getEntityManager()->getRepository($entityClassName);
103
    }
104
105
    /**
106
     * @return EntityManagerInterface
107
     */
108
    private function getEntityManager()
109
    {
110
        return app(EntityManagerInterface::class);
111
    }
112
}
113