Completed
Push — master ( 5467e4...183ea4 )
by Boy
05:06 queued 01:02
created

VettedSecondFactorRepository::removeByIdentityId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 9
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 9
loc 9
rs 9.6666
c 2
b 0
f 0
cc 1
eloc 7
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 Doctrine\ORM\EntityRepository;
22
use Doctrine\ORM\Query;
23
use Surfnet\Stepup\Identity\Value\IdentityId;
24
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\VettedSecondFactor;
25
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\VettedSecondFactorQuery;
26
27
class VettedSecondFactorRepository extends EntityRepository
28
{
29
    /**
30
     * @param string $id
31
     * @return VettedSecondFactor|null
32
     */
33
    public function find($id)
34
    {
35
        /** @var VettedSecondFactor|null $secondFactor */
36
        $secondFactor = parent::find($id);
37
38
        return $secondFactor;
39
    }
40
41
    /**
42
     * @param VettedSecondFactorQuery $query
43
     * @return Query
44
     */
45
    public function createSearchQuery(VettedSecondFactorQuery $query)
46
    {
47
        $queryBuilder = $this->createQueryBuilder('sf');
48
49
        if ($query->identityId) {
50
            $queryBuilder
51
                ->andWhere('sf.identityId = :identityId')
52
                ->setParameter('identityId', (string) $query->identityId);
53
        }
54
55
        return $queryBuilder->getQuery();
56
    }
57
58 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...
59
    {
60
        $this->getEntityManager()->createQueryBuilder()
61
            ->delete($this->_entityName, 'sf')
62
            ->where('sf.identityId = :identityId')
63
            ->setParameter('identityId', $identityId->getIdentityId())
64
            ->getQuery()
65
            ->execute();
66
    }
67
68
    /**
69
     * @param VettedSecondFactor $secondFactor
70
     */
71
    public function save(VettedSecondFactor $secondFactor)
72
    {
73
        $this->getEntityManager()->persist($secondFactor);
74
        $this->getEntityManager()->flush();
75
    }
76
77
    public function remove(VettedSecondFactor $secondFactor)
78
    {
79
        $this->getEntityManager()->remove($secondFactor);
80
        $this->getEntityManager()->flush();
81
    }
82
}
83