findOpzioniColonnetabella()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3.0261

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 2
nop 2
dl 0
loc 19
ccs 12
cts 14
cp 0.8571
crap 3.0261
rs 9.8333
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\Colonnetabelle;
7
use Cdf\BiCoreBundle\Entity\Operatori;
8
9
class ColonnetabelleRepository extends EntityRepository
10
{
11
    /**
12
     *
13
     * @param string $tabella
14
     * @param Operatori $user
15
     * @return array<Colonnetabelle>
16
     */
17 12
    public function findOpzioniColonnetabella(string $tabella, Operatori $user = null): array
18
    {
19 12
        $em = $this->getEntityManager();
20
        /* @var $qb \Doctrine\ORM\QueryBuilder */
21 12
        $qb = $em->createQueryBuilder();
22 12
        $qb->select(array('t'));
23 12
        $qb->from(Colonnetabelle::class, 't');
24 12
        $qb->where('t.nometabella = :tabella');
25 12
        $qb->andWhere('t.nomecampo is not null');
26 12
        $qb->orderBy('t.ordineindex', 'asc');
27 12
        $qb->setParameter('tabella', $tabella);
28 12
        if ($user && !$user->getRuoli()->isSuperadmin()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $user->getRuoli()->isSuperadmin() of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
29
            $qb->andWhere('t.operatori_id = :operatore');
30
            $qb->setParameter('operatore', $user->getId());
31
        }
32
        //$opzioni = $qb->getQuery()->useQueryCache(true)->useResultCache(true, null, 'Opzionitabella')->getResult();
33 12
        $opzioni = $qb->getQuery()->getResult();
34
35 12
        return $opzioni;
36
    }
37
}
38