Completed
Push — master ( 4407aa...f0730d )
by ANTHONIUS
22s queued 14s
created

GroupManager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 60
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 6 1
A deleteGroup() 0 4 1
A getClass() 0 8 2
A findGroups() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the DoyoUserBundle project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\UserBundle\Bridge\ORM;
15
16
use Doctrine\Common\Persistence\ObjectManager;
17
use Doyo\UserBundle\Manager\GroupManager as BaseGroupManager;
18
use Doyo\UserBundle\Model\GroupInterface;
19
20
class GroupManager extends BaseGroupManager
21
{
22
    /**
23
     * @var ObjectManager
24
     */
25
    private $objectManager;
26
27
    /**
28
     * @var string
29
     */
30
    private $class;
31
32 7
    public function __construct(
33
        ObjectManager $objectManager,
34
        $class
35
    ) {
36 7
        $this->objectManager = $objectManager;
37 7
        $this->class         = $class;
38
    }
39
40 1
    public function deleteGroup(GroupInterface $group)
41
    {
42 1
        $this->objectManager->remove($group);
43 1
        $this->objectManager->flush();
44
    }
45
46 6
    public function findGroupBy(array $criteria)
47
    {
48 6
        return $this->getRepository()->findOneBy($criteria);
49
    }
50
51 1
    public function findGroups()
52
    {
53 1
        return $this->getRepository()->findAll();
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 8
    public function getClass()
60
    {
61 8
        if (false !== strpos($this->class, ':')) {
62 1
            $metadata    = $this->objectManager->getClassMetadata($this->class);
63 1
            $this->class = $metadata->getName();
64
        }
65
66 8
        return $this->class;
67
    }
68
69 5
    public function updateGroup(GroupInterface $group, $andFlush = true)
70
    {
71 5
        $this->objectManager->persist($group);
72 5
        if ($andFlush) {
73 5
            $this->objectManager->flush();
74
        }
75
    }
76
77 7
    public function getRepository()
78
    {
79 7
        return $this->objectManager->getRepository($this->getClass());
80
    }
81
}
82