Failed Conditions
Push — master ( 5e6761...398dce )
by Adrien
04:14 queued 01:57
created

Repository::getAllIdsQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
cc 1
rs 10
ccs 0
cts 7
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Repository\Traits;
6
7
use Ecodev\Felix\Model\User;
8
use Ecodev\Felix\ORM\Query\Filter\AclFilter;
9
10
/**
11
 * Trait for common method of repository
12
 */
13
trait Repository
14
{
15
    /**
16
     * Returns the AclFilter to fetch ACL filtering SQL
17
     *
18
     * @return AclFilter
19
     */
20
    public function getAclFilter(): AclFilter
21
    {
22
        /** @var AclFilter $aclFilter */
23
        $aclFilter = $this->getEntityManager()->getFilters()->getFilter(AclFilter::class);
0 ignored issues
show
Bug introduced by
It seems like getEntityManager() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

23
        $aclFilter = $this->/** @scrutinizer ignore-call */ getEntityManager()->getFilters()->getFilter(AclFilter::class);
Loading history...
24
25
        return $aclFilter;
26
    }
27
28
    /**
29
     * Return native SQL query to get all ID
30
     *
31
     * @return string
32
     */
33
    protected function getAllIdsQuery(): string
34
    {
35
        $connection = $this->getEntityManager()->getConnection();
36
        $qb = $connection->createQueryBuilder()
37
            ->select('id')
38
            ->from($connection->quoteIdentifier($this->getClassMetadata()->getTableName()));
0 ignored issues
show
Bug introduced by
It seems like getClassMetadata() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

38
            ->from($connection->quoteIdentifier($this->/** @scrutinizer ignore-call */ getClassMetadata()->getTableName()));
Loading history...
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
        $connection = $this->getEntityManager()->getConnection();
53
        $qb = $connection->createQueryBuilder()
54
            ->select('id')
55
            ->from($connection->quoteIdentifier($this->getClassMetadata()->getTableName()))
56
            ->andWhere('owner_id = ' . $user->getId());
57
58
        return $qb->getSQL();
59
    }
60
}
61