Failed Conditions
Push — master ( 2d1803...253cbc )
by Sylvain
09:12
created

AbstractRepository::getCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 2
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 Doctrine\ORM\EntityRepository;
9
10
/**
11
 * Class AbstractRepository
12
 *
13
 * @method null|AbstractModel findOneById(integer $id)
14
 */
15
abstract class AbstractRepository extends EntityRepository
16
{
17
    use \Ecodev\Felix\Repository\Traits\Repository;
18
19
    /**
20
     * Count the total number of objects
21
     */
22
    public function getCount(): int
23
    {
24
        $connection = $this->getEntityManager()->getConnection();
25
26
        $query = $connection->createQueryBuilder()
27
            ->select('COUNT(*)')
28
            ->from($connection->quoteIdentifier($this->getClassMetadata()->getTableName()));
29
30
        return (int) $query->execute()->fetchColumn();
31
    }
32
}
33