PermissionRepository   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 10
c 0
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getPermissionIdByName() 0 15 2
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