UnverifiedSecondFactorRepository   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 6 1
A remove() 0 4 1
A removeByIdentityId() 0 8 1
A createSearchQuery() 0 16 3
A __construct() 0 3 1
A save() 0 4 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 Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
22
use Doctrine\ORM\Query;
23
use Doctrine\Persistence\ManagerRegistry;
24
use Surfnet\Stepup\Identity\Value\IdentityId;
25
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\UnverifiedSecondFactor;
26
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\UnverifiedSecondFactorQuery;
27
28
/**
29
 * @extends ServiceEntityRepository<UnverifiedSecondFactor>
30
 */
31
class UnverifiedSecondFactorRepository extends ServiceEntityRepository
32
{
33
    public function __construct(ManagerRegistry $registry)
34
    {
35
        parent::__construct($registry, UnverifiedSecondFactor::class);
36
    }
37
38
    public function find(mixed $id, $lockMode = null, $lockVersion = null): ?UnverifiedSecondFactor
39
    {
40
        /** @var UnverifiedSecondFactor|null $secondFactor */
41
        $secondFactor = parent::find($id);
42
43
        return $secondFactor;
44
    }
45
46
    /**
47
     * @return Query
48
     */
49
    public function createSearchQuery(UnverifiedSecondFactorQuery $query): Query
50
    {
51
        $queryBuilder = $this->createQueryBuilder('sf');
52
53
        if ($query->identityId instanceof IdentityId) {
54
            $queryBuilder
55
                ->andWhere('sf.identityId = :identityId')
56
                ->setParameter('identityId', (string)$query->identityId);
57
        }
58
59
        if ($query->verificationNonce) {
60
            $queryBuilder->andWhere('sf.verificationNonce = :verificationNonce');
61
            $queryBuilder->setParameter('verificationNonce', $query->verificationNonce);
62
        }
63
64
        return $queryBuilder->getQuery();
65
    }
66
67
    public function removeByIdentityId(IdentityId $identityId): void
68
    {
69
        $this->getEntityManager()->createQueryBuilder()
70
            ->delete($this->getEntityName(), 'sf')
71
            ->where('sf.identityId = :identityId')
72
            ->setParameter('identityId', $identityId->getIdentityId())
73
            ->getQuery()
74
            ->execute();
75
    }
76
77
    public function save(UnverifiedSecondFactor $secondFactor): void
78
    {
79
        $this->getEntityManager()->persist($secondFactor);
80
        $this->getEntityManager()->flush();
81
    }
82
83
    public function remove(UnverifiedSecondFactor $secondFactor): void
84
    {
85
        $this->getEntityManager()->remove($secondFactor);
86
        $this->getEntityManager()->flush();
87
    }
88
}
89