Completed
Push — master ( 64908a...328605 )
by
unknown
03:10
created

VerifiedSecondFactorRepository::findByDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Repository;
20
21
use DateTime;
22
use Doctrine\ORM\EntityRepository;
23
use Doctrine\ORM\Query;
24
use Surfnet\Stepup\Identity\Value\IdentityId;
25
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\VerifiedSecondFactor;
26
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\VerifiedSecondFactorQuery;
27
28
class VerifiedSecondFactorRepository extends EntityRepository
29
{
30
    /**
31
     * @param string $id
32
     * @return VerifiedSecondFactor|null
33
     */
34
    public function find($id)
35
    {
36
        /** @var VerifiedSecondFactor|null $secondFactor */
37
        $secondFactor = parent::find($id);
38
39
        return $secondFactor;
40
    }
41
42
    /**
43
     * @param DateTime $requestedAt
44
     * @return VerifiedSecondFactor[]
45
     */
46
    public function findByDate(DateTime $requestedAt)
47
    {
48
        $fromDate = clone $requestedAt;
49
        $fromDate->setTime(0, 0, 0);
50
51
        $toDate = clone $requestedAt;
52
        $toDate->setTime(23, 59, 59);
53
54
        return $this->createQueryBuilder('sf')
55
            ->where('sf.registrationRequestedAt <= :toDate')
56
            ->andWhere('sf.registrationRequestedAt >= :fromDate')
57
            ->setParameter('toDate', $toDate)
58
            ->setParameter('fromDate', $fromDate)
59
            ->getQuery()
60
            ->getResult();
61
    }
62
63
    /**
64
     * @param VerifiedSecondFactorQuery $query
65
     * @return Query
66
     */
67
    public function createSearchQuery(VerifiedSecondFactorQuery $query)
68
    {
69
        $queryBuilder = $this->createQueryBuilder('sf');
70
71
        if ($query->identityId) {
72
            $queryBuilder
73
                ->andWhere('sf.identityId = :identityId')
74
                ->setParameter('identityId', (string) $query->identityId);
75
        }
76
77
        if ($query->secondFactorId) {
78
            $queryBuilder
79
                ->andWhere('sf.id = :secondFactorId')
80
                ->setParameter('secondFactorId', (string) $query->secondFactorId);
81
        }
82
83
        if (is_string($query->registrationCode)) {
84
            $queryBuilder
85
                ->andWhere('sf.registrationCode = :registrationCode')
86
                ->setParameter('registrationCode', $query->registrationCode);
87
        }
88
89
        return $queryBuilder->getQuery();
90
    }
91
92 View Code Duplication
    public function removeByIdentityId(IdentityId $identityId)
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...
93
    {
94
        $this->getEntityManager()->createQueryBuilder()
95
            ->delete($this->_entityName, 'sf')
96
            ->where('sf.identityId = :identityId')
97
            ->setParameter('identityId', $identityId->getIdentityId())
98
            ->getQuery()
99
            ->execute();
100
    }
101
102
    /**
103
     * @param VerifiedSecondFactor $secondFactor
104
     */
105
    public function save(VerifiedSecondFactor $secondFactor)
106
    {
107
        $this->getEntityManager()->persist($secondFactor);
108
        $this->getEntityManager()->flush();
109
    }
110
111
    public function remove(VerifiedSecondFactor $secondFactor)
112
    {
113
        $this->getEntityManager()->remove($secondFactor);
114
        $this->getEntityManager()->flush();
115
    }
116
}
117