Completed
Push — master ( 51c246...0d8778 )
by Derek Stephen
02:23
created

User   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 21.62%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 11
c 4
b 0
f 0
lcom 1
cbo 5
dl 0
loc 65
ccs 8
cts 37
cp 0.2162
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 6 1
A delete() 0 5 1
F findByCriteria() 0 39 9
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->hasId()) {
39
            $qb->where('u.id = :id');
40
            $qb->setParameter('id', $criteria->getId());
41
            $criteria->setLimit(1);
42
        }
43
44
        if($criteria->hasEmail()) {
45
            $qb->where('u.email = :email');
46
            $qb->setParameter('email', $criteria->getEmail());
47
            $criteria->setLimit(1);
48
        }
49
50
        if($criteria->hasState()) {
51
            $qb->andWhere('u.state = :state');
52
            $qb->setParameter('state', $criteria->getState());
53
        }
54
55
        if($criteria->hasRegistrationDate()) {
56
            $qb->andWhere('u.registrationDate = :regdate');
57
            $qb->setParameter('registrationDate', $criteria->getRegistrationDate());
58
        }
59
60
        if($criteria->hasLastLoginDate()) {
61
            $qb->andWhere('u.lastLoginDate = :lastlogin');
62
            $qb->setParameter('lastlogin', $criteria->getLastLoginDate());
63
        }
64
65
        $criteria->hasOrder() ? $qb->addOrderBy('u.'.$criteria->getOrder(),$criteria->getOrderDirection()) : null;
0 ignored issues
show
Bug introduced by
The method getOrderDirection() does not exist on Del\Criteria\UserCriteria. Did you maybe mean getOrder()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
66
        $criteria->hasLimit() ? $qb->setMaxResults($criteria->getLimit()) : null;
67
        $criteria->hasOffset() ? $qb->setFirstResult($criteria->getOffset()) : null;
68
69
        $query = $qb->getQuery();
70
71
        return $query->getResult();
72
    }
73
}
74