Test Setup Failed
Push — master ( d6bd2d...bc363c )
by Alexey
03:03
created

AccountRepository::getAccountsCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 1
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\Repository\Telegram;
4
5
use Doctrine\ORM\EntityRepository;
6
use Skobkin\Bundle\PointToolsBundle\Entity\Telegram\Account;
7
8
class AccountRepository extends EntityRepository
9
{
10
    public function add(Account $entity)
11
    {
12
        $this->getEntityManager()->persist($entity);
13
    }
14
15
    /**
16
     * @todo remove if not used
17
     *
18
     * @param array $criteria
19
     * @param array|null $orderBy
20
     * @param int|null $limit
21
     * @param int|null $offset
22
     *
23
     * @return Account[]
24
     */
25
    public function findLinkedAccountsBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array
26
    {
27
        $qb = $this->createQueryBuilder('a');
28
29
        $i = 0;
30
        foreach ($criteria as $property => $value) {
31
            $qb
32
                ->andWhere('a.'.$property.' = :criteria_'.$i)
33
                ->setParameter('criteria_'.$i, $value)
34
            ;
35
        }
36
37
        if (null !== $orderBy) {
38
            foreach ($orderBy as $property => $order) {
39
                $qb->addOrderBy($property, $order);
40
            }
41
        }
42
43
        if (null !== $limit) {
44
            $qb->setMaxResults($limit);
45
        }
46
47
        if (null !== $offset) {
48
            $qb->setFirstResult($offset);
49
        }
50
51
        return $qb->getQuery()->getResult();
52
    }
53
54
    /**
55
     * Returns total number of accounts
56
     *
57
     * @return int
58
     */
59
    public function getAccountsCount(): int
60
    {
61
        return $this->createQueryBuilder('a')
62
            ->select('COUNT(a)')
63
            ->getQuery()->getSingleScalarResult()
64
        ;
65
    }
66
67
    /**
68
     * Returns number of accounts with linked Point.im profile
69
     *
70
     * @return int
71
     */
72
    public function getLinkedAccountsCount(): int
73
    {
74
        return $this->createQueryBuilder('a')
75
            ->select('COUNT(a)')
76
            ->where('a.user IS NOT NULL')
77
            ->getQuery()->getSingleScalarResult()
78
        ;
79
    }
80
}