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

Repository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 46
rs 10
ccs 0
cts 21
cp 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllIdsForOwnerQuery() 0 9 1
A getAclFilter() 0 6 1
A getAllIdsQuery() 0 8 1
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