VettedSecondFactorRepository::removeByIdentityId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
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
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
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 */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
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 \Surfnet\Stepup\Identity\Value\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