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

User::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 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 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