VettedSecondFactorRepository   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

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