Failed Conditions
Push — master ( 977552...4856db )
by Adrien
12:24
created

AbstractRepository::quoteArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Repository;
6
7
use Application\Model\AbstractModel;
8
use Application\Model\User;
9
use Application\ORM\Query\Filter\AclFilter;
10
use Doctrine\ORM\EntityRepository;
11
12
/**
13
 * Class AbstractRepository
14
 *
15
 * @method null|AbstractModel findOneById(integer $id)
16
 */
17
abstract class AbstractRepository extends EntityRepository
18
{
19
    /**
20
     * Returns the AclFilter to fetch ACL filtering SQL
21
     *
22 80
     * @return AclFilter
23
     */
24 80
    public function getAclFilter(): AclFilter
25
    {
26
        return $this->getEntityManager()->getFilters()->getFilter(AclFilter::class);
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->getEntityM...ilter\AclFilter::class) returns the type Doctrine\ORM\Query\Filter\SQLFilter which includes types incompatible with the type-hinted return Application\ORM\Query\Filter\AclFilter.
Loading history...
27
    }
28
29
    /**
30
     * Return native SQL query to get all ID
31
     *
32 20
     * @return string
33
     */
34 20
    protected function getAllIdsQuery(): string
35 20
    {
36 20
        $qb = $this->getEntityManager()->getConnection()->createQueryBuilder()
37
            ->select('id')
38 20
            ->from($this->getClassMetadata()->getTableName());
39
40
        return $qb->getSQL();
41
    }
42
43
    /**
44
     * Return native SQL query to get all ID of object owned by given user
45
     *
46
     * @param User $user
47
     *
48
     * @return string
49
     */
50
    protected function getAllIdsForOwnerQuery(User $user): string
51
    {
52
        $qb = $this->getEntityManager()->getConnection()->createQueryBuilder()
53
            ->select('id')
54
            ->from($this->getClassMetadata()->getTableName())
55
            ->andWhere('owner_id = ' . $user->getId());
56
57
        return $qb->getSQL();
58
    }
59
}
60