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

GroupManager::getRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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