Completed
Pull Request — master (#4)
by ANTHONIUS
04:04
created

GroupManager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 61
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A updateGroup() 0 5 2
A getRepository() 0 3 1
A findGroupBy() 0 3 1
A __construct() 0 7 1
A deleteGroup() 0 4 1
A getClass() 0 8 2
A findGroups() 0 3 1
1
<?php
2
3
namespace Doyo\UserBundle\Bridge\ORM;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
use Doyo\UserBundle\Manager\GroupManager as BaseGroupManager;
7
use Doyo\UserBundle\Model\GroupInterface;
8
9
class GroupManager extends BaseGroupManager
10
{
11
    /**
12
     * @var ObjectManager
13
     */
14
    private $objectManager;
15
16
    /**
17
     * @var string
18
     */
19
    private $class;
20
21 7
    public function __construct(
22
        ObjectManager $objectManager,
23
        $class
24
    )
25
    {
26 7
        $this->objectManager = $objectManager;
27 7
        $this->class = $class;
28
    }
29
30 1
    public function deleteGroup(GroupInterface $group)
31
    {
32 1
        $this->objectManager->remove($group);
33 1
        $this->objectManager->flush();
34
    }
35
36 6
    public function findGroupBy(array $criteria)
37
    {
38 6
        return $this->getRepository()->findOneBy($criteria);
39
    }
40
41 1
    public function findGroups()
42
    {
43 1
        return $this->getRepository()->findAll();
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 8
    public function getClass()
50
    {
51 8
        if (false !== strpos($this->class, ':')) {
52 1
            $metadata = $this->objectManager->getClassMetadata($this->class);
53 1
            $this->class = $metadata->getName();
54
        }
55
56 8
        return $this->class;
57
    }
58
59 5
    public function updateGroup(GroupInterface $group, $andFlush = true)
60
    {
61 5
        $this->objectManager->persist($group);
62 5
        if($andFlush){
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after IF keyword; 0 found
Loading history...
63 5
            $this->objectManager->flush();
64
        }
65
    }
66
67 7
    public function getRepository()
68
    {
69 7
        return $this->objectManager->getRepository($this->getClass());
70
    }
71
}
72