RoleManager   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 73
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteRole() 0 4 1
A findRoleBy() 0 3 1
A __construct() 0 4 1
A getRepository() 0 3 1
A updateRole() 0 6 2
A findRoles() 0 3 1
A getClass() 0 3 1
A findRole() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the EloyekunlePermissionsBundle package.
5
 *
6
 * (c) Elijah Oyekunle <https://elijahoyekunle.com/>
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
namespace Eloyekunle\PermissionsBundle\Doctrine;
13
14
use Doctrine\Common\Persistence\ObjectManager;
15
use Doctrine\Common\Persistence\ObjectRepository;
16
use Eloyekunle\PermissionsBundle\Model\RoleInterface;
17
use Eloyekunle\PermissionsBundle\Model\RoleManager as BaseRoleManager;
18
19
class RoleManager extends BaseRoleManager
20
{
21
    /** @var ObjectManager */
22
    protected $objectManager;
23
24
    /** @var string */
25
    protected $class;
26
27 7
    public function __construct(ObjectManager $om, $class)
28
    {
29 7
        $this->objectManager = $om;
30 7
        $this->class = $class;
31 7
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 6
    public function getClass()
37
    {
38 6
        return $this->class;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 1
    public function findRoles()
45
    {
46 1
        return $this->getRepository()->findAll();
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 1
    public function findRoleBy(array $criteria)
53
    {
54 1
        return $this->getRepository()->findOneBy($criteria);
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 1
    public function findRole($id)
61
    {
62 1
        return $this->getRepository()->find($id);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 1
    public function updateRole(RoleInterface $role, $andFlush = true)
69
    {
70 1
        $this->objectManager->persist($role);
71
72 1
        if ($andFlush) {
73 1
            $this->objectManager->flush();
74
        }
75 1
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 1
    public function deleteRole(RoleInterface $role)
81
    {
82 1
        $this->objectManager->remove($role);
83 1
        $this->objectManager->flush();
84 1
    }
85
86
    /**
87
     * @return ObjectRepository
88
     */
89 3
    protected function getRepository()
90
    {
91 3
        return $this->objectManager->getRepository($this->getClass());
92
    }
93
}
94