Test Failed
Push — master ( 49ed34...5345eb )
by Elijah
03:06
created

RoleManager::getRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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
    public function __construct(ObjectManager $om, $class)
28
    {
29
        $this->objectManager = $om;
30
        $this->class = $class;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getClass()
37
    {
38
        if (false !== strpos($this->class, ':')) {
39
            $metadata = $this->objectManager->getClassMetadata($this->class);
40
            $this->class = $metadata->getName();
41
        }
42
43
        return $this->class;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function findRoles()
50
    {
51
        return $this->getRepository()->findAll();
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function findRoleBy(array $criteria)
58
    {
59
        return $this->getRepository()->findOneBy($criteria);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function findRole($id)
66
    {
67
        return $this->getRepository()->find($id);
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function updateRole(RoleInterface $role, $andFlush = true)
74
    {
75
        $this->objectManager->persist($role);
76
77
        if ($andFlush) {
78
            $this->objectManager->flush();
79
        }
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function deleteRole(RoleInterface $role)
86
    {
87
        $this->objectManager->remove($role);
88
        $this->objectManager->flush();
89
    }
90
91
    /**
92
     * @return ObjectRepository
93
     */
94
    protected function getRepository()
95
    {
96
        return $this->objectManager->getRepository($this->getClass());
97
    }
98
}
99