AbstractManager   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 17
c 1
b 0
f 0
lcom 2
cbo 4
dl 0
loc 107
rs 10
ccs 46
cts 46
cp 1

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A find() 0 4 1
A findAll() 0 4 1
A findBy() 0 4 1
A findOneBy() 0 4 1
A getClassName() 0 4 1
A merge() 0 10 2
A persist() 0 8 2
A remove() 0 8 2
A getEntityManager() 0 4 1
A getRepository() 0 4 1
A create() 0 6 1
A createList() 0 10 1
A getListQuery() 0 4 1
1
<?php
2
3
namespace Pgs\RestfonyBundle\Manager;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\Query;
7
use Doctrine\ORM\QueryBuilder;
8
use Pgs\RestfonyBundle\Repository\RestRepository;
9
10
class AbstractManager implements ManagerInterface
11
{
12
    protected $objectManager;
13
14
    protected $class;
15
16
    /**
17
     * @var RestRepository
18
     */
19
    protected $repository;
20
21 10
    public function __construct(EntityManagerInterface $objectManager, $class)
22
    {
23 10
        $this->objectManager = $objectManager;
24 10
        $this->repository = $objectManager->getRepository($class);
25
26 10
        $metadata = $objectManager->getClassMetadata($class);
27 10
        $this->class = $metadata->getName();
28 10
    }
29
30 3
    public function find($id)
31
    {
32 3
        return $this->getRepository()->find($id);
33
    }
34
35 1
    public function findAll()
36
    {
37 1
        return $this->getRepository()->findAll();
38
    }
39
40 1
    public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
41
    {
42 1
        return $this->getRepository()->findBy($criteria, $orderBy, $limit, $offset);
43
    }
44
45 1
    public function findOneBy(array $criteria)
46
    {
47 1
        return $this->getRepository()->findOneBy($criteria);
48
    }
49
50 1
    public function getClassName()
51
    {
52 1
        return $this->getRepository()->getClassName();
53
    }
54
55 1
    public function merge($object, $flush = false)
56
    {
57 1
        $result = $this->getEntityManager()->merge($object);
58
59 1
        if ($flush) {
60 1
            $this->getEntityManager()->flush();
61
        }
62
63 1
        return $result;
64
    }
65
66 1
    public function persist($object, $flush = false)
67
    {
68 1
        $this->getEntityManager()->persist($object);
69
70 1
        if ($flush) {
71 1
            $this->getEntityManager()->flush();
72
        }
73 1
    }
74
75 1
    public function remove($object, $flush = false)
76
    {
77 1
        $this->getEntityManager()->remove($object);
78
79 1
        if ($flush) {
80 1
            $this->getEntityManager()->flush();
81
        }
82 1
    }
83
84 4
    public function getEntityManager()
85
    {
86 4
        return $this->objectManager;
87
    }
88
89 8
    public function getRepository()
90
    {
91 8
        return $this->repository;
92
    }
93
94 3
    public function create()
95
    {
96 3
        $className = $this->class;
97
98 3
        return new $className();
99
    }
100
101 1
    public function createList($alias, $idAlias, $hydrationMode = Query::HYDRATE_OBJECT)
102
    {
103 1
        $qb = $this->getEntityManager()->createQueryBuilder();
104
        /* @var $qb QueryBuilder */
105
        return $qb
106 1
            ->from($this->getRepository()->getClassName(), $alias, $idAlias)
107 1
            ->select($alias)
108 1
            ->getQuery()
109 1
            ->getResult($hydrationMode);
110
    }
111
112 1
    public function getListQuery(array $sortConfiguration, $sortQuery)
113
    {
114 1
        return $this->repository->getListQuery($sortConfiguration, $sortQuery);
115
    }
116
}
117