Completed
Push — master ( 4bad87...d6e1be )
by Derek Stephen
07:20
created

User   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 25%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 10
c 3
b 0
f 0
lcom 1
cbo 5
dl 0
loc 59
ccs 8
cts 32
cp 0.25
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 6 1
A delete() 0 5 1
D findByCriteria() 0 33 8
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 2
    public function save(UserEntity $user)
16
    {
17 2
        $this->_em->persist($user);
18 2
        $this->_em->flush();
19 2
        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
            $criteria->setLimit(1);
42
        }
43
44
        if($criteria->hasState()) {
45
            $qb->andWhere('u.state = :state');
46
            $qb->setParameter('state', $criteria->getState());
47
        }
48
49
        if($criteria->hasRegistrationDate()) {
50
            $qb->andWhere('u.registrationDate = :regdate');
51
            $qb->setParameter('registrationDate', $criteria->getRegistrationDate());
52
        }
53
54
        if($criteria->hasLastLoginDate()) {
55
            $qb->andWhere('u.lastLoginDate = :lastlogin');
56
            $qb->setParameter('lastlogin', $criteria->getLastLoginDate());
57
        }
58
59
        $criteria->hasOrder() ? $qb->addOrderBy($criteria->getOrder()) : null;
60
        $criteria->hasLimit() ? $qb->setMaxResults($criteria->getLimit()) : null;
61
        $criteria->hasOffset() ? $qb->setFirstResult($criteria->getOffset()) : null;
62
63
        $query = $qb->getQuery();
64
65
        return $query->getResult();
66
    }
67
}
68