PermessiRepository::findPermessoModuloOperatore()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4.0047

Importance

Changes 0
Metric Value
cc 4
eloc 14
nc 4
nop 2
dl 0
loc 21
ccs 14
cts 15
cp 0.9333
crap 4.0047
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
namespace Cdf\BiCoreBundle\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use Cdf\BiCoreBundle\Entity\Operatori;
7
use Cdf\BiCoreBundle\Entity\Permessi;
8
9
class PermessiRepository extends EntityRepository
10
{
11
12 19
    public function findPermessoModuloOperatore(string $modulo, ?Operatori $operatore): ?Permessi
13
    {
14 19
        $em = $this->getEntityManager();
15 19
        if (!$operatore->getRuoli()) {
0 ignored issues
show
Bug introduced by
The method getRuoli() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
        if (!$operatore->/** @scrutinizer ignore-call */ getRuoli()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
16
            return null;
17
        }
18 19
        $permesso = $em->getRepository(Permessi::class)
19 19
                ->findOneBy(array('operatori_id' => $operatore->getId(), 'modulo' => $modulo));
20
21 19
        if (!$permesso) {
22 18
            $permesso = $em
23 18
                    ->getRepository(Permessi::class)
24 18
                    ->findOneBy(array('ruoli_id' => $operatore->getRuoli()->getId(), 'modulo' => $modulo, 'operatori_id' => null));
25 18
            if (!$permesso) {
26 18
                $permesso = $em
27 18
                        ->getRepository(Permessi::class)
28 18
                        ->findOneBy(array('ruoli_id' => null, 'modulo' => $modulo, 'operatori_id' => null));
29
            }
30
        }
31
32 19
        return $permesso;
33
    }
34
}
35