PermissionRepository::getPermissionIdByName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 15
rs 9.9666
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Potievdev\SlimRbac\Models\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
7
/**
8
 * PermissionRepository
9
 *
10
 * This class was generated by the Doctrine ORM. Add your own custom
11
 * repository methods below.
12
 */
13
class PermissionRepository extends EntityRepository
14
{
15
    /**
16
     * Finds permission by name. If it founded returns permission id
17
     */
18
    public function getPermissionIdByName(string $permissionName): ?int
19
    {
20
        $qb = $this->createQueryBuilder('permission');
21
22
        $result = $qb->select('permission.id')
23
            ->where($qb->expr()->eq('permission.name', $qb->expr()->literal($permissionName)))
24
            ->setMaxResults(1)
25
            ->getQuery()
26
            ->getArrayResult();
27
28
        if (count($result) > 0) {
29
            return $result[0]['id'];
30
        }
31
32
        return null;
33
    }
34
}
35