UserRepository::parseCriteria()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * User entity repository class file
4
 *
5
 * @package    EBloodBank
6
 * @subpackage Models
7
 * @since      1.0
8
 */
9
namespace EBloodBank\Models;
10
11
/**
12
 * User entity repository class
13
 *
14
 * @since 1.0
15
 */
16
class UserRepository extends EntityRepository
17
{
18
    /**
19
     * Finds entities by a set of criteria.
20
     *
21
     * @param array      $criteria
22
     * @param array|null $orderBy
23
     * @param int|null   $limit
24
     * @param int|null   $offset
25
     *
26
     * @return array The objects.
27
     */
28
    public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
29
    {
30
        $criteria = $this->parseCriteria($criteria);
31
        return parent::findBy($criteria, $orderBy, $limit, $offset);
32
    }
33
34
    /**
35
     * Finds a single entity by a set of criteria.
36
     *
37
     * @param array $criteria
38
     * @param array|null $orderBy
39
     *
40
     * @return object|null The entity instance or NULL if the entity can not be found.
41
     */
42
    public function findOneBy(array $criteria, array $orderBy = null)
43
    {
44
        $criteria = $this->parseCriteria($criteria);
45
        return parent::findOneBy($criteria, $orderBy);
46
    }
47
48
    /**
49
     * @return array
50
     * @since 1.0
51
     */
52
    protected function parseCriteria(array $criteria)
53
    {
54
        if (isset($criteria['status']) && 'any' === $criteria['status']) {
55
            unset($criteria['status']);
56
        }
57
58
        return $criteria;
59
    }
60
}
61