EntityRepository::countBy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Abstract entity repository class file
4
 *
5
 * @package    EBloodBank
6
 * @subpackage Models
7
 * @since      1.0
8
 */
9
namespace EBloodBank\Models;
10
11
/**
12
 * Abstract entity repository class
13
 *
14
 * @since 1.0
15
 */
16
abstract class EntityRepository extends \Doctrine\ORM\EntityRepository
17
{
18
    /**
19
     * Count all entities.
20
     *
21
     * @return int
22
     * @since 1.0
23
     */
24
    public function countAll()
25
    {
26
        return $this->countBy([]);
27
    }
28
29
    /**
30
     * Count entities (optionally filtered by a criteria).
31
     *
32
     * @return int
33
     * @since 1.0
34
     */
35
    public function countBy($criteria = [])
36
    {
37
        $em = $this->getEntityManager();
38
        $entityName = $this->getEntityName();
39
        $criteria = $this->parseCriteria($criteria);
40
        $persister = $em->getUnitOfWork()->getEntityPersister($entityName);
41
42
        return $persister->count($criteria);
43
    }
44
45
    /**
46
     * @return array
47
     * @since 1.0
48
     */
49
    protected function parseCriteria(array $criteria)
50
    {
51
        return $criteria;
52
    }
53
}
54