RoleManager::updateRole()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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