Completed
Branch master (3a823b)
by Derek Stephen
04:04 queued 02:12
created

UserRepository::findByCriteria()   F

Complexity

Conditions 9
Paths 256

Size

Total Lines 39
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 9

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 39
ccs 29
cts 29
cp 1
rs 3
cc 9
eloc 24
nc 256
nop 1
crap 9
1
<?php
2
3
namespace Del\Repository;
4
5
use Del\Criteria\UserCriteria;
6
use Del\Entity\User;
7
use Doctrine\ORM\EntityRepository;
8
9
10
class UserRepository extends EntityRepository
11
{
12
    /**
13
     * @param User $user
14
     * @return User
15
     */
16 16 View Code Duplication
    public function save(User $user)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
    {
18 16
        if(!$user->getID()) {
19 16
            $this->_em->persist($user);
20 16
        }
21 16
        $this->_em->flush($user);
22 16
        $this->_em->flush($user->getPerson());
23 16
        return $user;
24
    }
25
    /**
26
     * @param User $user
27
     */
28 16 View Code Duplication
    public function delete(User $user, $deletePerson = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30 16
        if($deletePerson) {
31 16
            $this->_em->remove($user->getPerson());
32 16
        }
33 16
        $this->_em->remove($user);
34 16
        $this->_em->flush($user);
35 16
    }
36
37
    /**
38
     * @param UserCriteria $criteria
39
     * @return array
40
     */
41 11
    public function findByCriteria(UserCriteria $criteria)
42
    {
43 11
        $qb = $this->createQueryBuilder('u');
44
45 11
        if($criteria->hasId()) {
46 1
            $qb->where('u.id = :id');
47 1
            $qb->setParameter('id', $criteria->getId());
48 1
            $criteria->setLimit(1);
49 1
        }
50
51 11
        if($criteria->hasEmail()) {
52 10
            $qb->where('u.email = :email');
53 10
            $qb->setParameter('email', $criteria->getEmail());
54 10
            $criteria->setLimit(1);
55 10
        }
56
57 11
        if($criteria->hasState()) {
58 1
            $qb->andWhere('u.state = :state');
59 1
            $qb->setParameter('state', $criteria->getState());
60 1
        }
61
62 11
        if($criteria->hasRegistrationDate()) {
63 1
            $qb->andWhere('u.registrationDate = :regdate');
64 1
            $qb->setParameter('regdate', $criteria->getRegistrationDate());
65 1
        }
66
67 11
        if($criteria->hasLastLoginDate()) {
68 1
            $qb->andWhere('u.lastLoginDate = :lastlogin');
69 1
            $qb->setParameter('lastlogin', $criteria->getLastLoginDate());
70 1
        }
71
72 11
        $criteria->hasOrder() ? $qb->addOrderBy('u.'.$criteria->getOrder(),$criteria->getOrderDirection()) : null;
73 11
        $criteria->hasLimit() ? $qb->setMaxResults($criteria->getLimit()) : null;
74 11
        $criteria->hasOffset() ? $qb->setFirstResult($criteria->getOffset()) : null;
75
76 11
        $query = $qb->getQuery();
77
78 11
        return $query->getResult();
79
    }
80
}
81