Completed
Push — master ( eab52f...000460 )
by Derek Stephen
02:02
created

User   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 25.81%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 2
cbo 5
dl 0
loc 57
ccs 8
cts 31
cp 0.2581
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
D findByCriteria() 0 31 8
A save() 0 6 1
A delete() 0 5 1
1
<?php
2
3
namespace Del\Repository;
4
5
use Del\Criteria\UserCriteria;
6
use Del\Entity\User as UserEntity;
7
use Doctrine\ORM\EntityRepository;
8
9
class User extends EntityRepository
10
{
11
    /**
12
     * @param UserEntity $user
13
     * @return UserEntity
14
     */
15 1
    public function save(UserEntity $user)
16
    {
17 1
        $this->_em->persist($user);
18 1
        $this->_em->flush();
19 1
        return $user;
20
    }
21
    /**
22
     * @param UserEntity $user
23
     */
24 1
    public function delete(UserEntity $user)
25
    {
26 1
        $this->_em->remove($user);
27 1
        $this->_em->flush();
28 1
    }
29
30
    /**
31
     * @param UserCriteria $criteria
32
     * @return array
33
     */
34
    public function findByCriteria(UserCriteria $criteria)
35
    {
36
        $qb = $this->createQueryBuilder('u');
37
38
        if($criteria->hasEmail()) {
39
            $qb->where('u.email = :email');
40
            $qb->setParameter('email', $criteria->getEmail());
41
        }
42
43
        if($criteria->hasState()) {
44
            $qb->andWhere('u.state = :state');
45
            $qb->setParameter('state', $criteria->getState());
46
        }
47
48
        if($criteria->hasRegistrationDate()) {
49
            $qb->andWhere('u.registrationDate = :regdate');
50
            $qb->setParameter('registrationDate', $criteria->getRegistrationDate());
51
        }
52
53
        if($criteria->hasLastLoginDate()) {
54
            $qb->andWhere('u.lastLoginDate = :lastlogin');
55
            $qb->setParameter('lastlogin', $criteria->getLastLoginDate());
56
        }
57
58
        $criteria->hasOrder() ? $qb->addOrderBy($criteria->getOrder()) : null;
59
        $criteria->hasLimit() ? $qb->setMaxResults($criteria->getLimit()) : null;
60
        $criteria->hasOffset() ? $qb->setFirstResult($criteria->getOffset()) : null;
61
62
        $query = $qb->getQuery();
63
        return $query->getResult();
64
    }
65
}
66