SamlEntityRepository::removeAllOfType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 10
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\GatewayBundle\Entity;
20
21
use Doctrine\ORM\EntityRepository;
22
23
/**
24
 * @extends  EntityRepository<SamlEntity>
0 ignored issues
show
Coding Style introduced by
Tag value for @extends tag indented incorrectly; expected 1 spaces but found 2
Loading history...
25
 */
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...
26
class SamlEntityRepository extends EntityRepository
27
{
28
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $newSamlEntities should have a doc-comment as per coding-style.
Loading history...
29
     * Replace all configured service provider SamlEntities with the new SamlEntities.
30
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
31
    public function replaceAllSps(array $newSamlEntities): void
32
    {
33
        $this->replaceAllOfType(SamlEntity::TYPE_SP, $newSamlEntities);
34
    }
35
36
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $newSamlEntities should have a doc-comment as per coding-style.
Loading history...
37
     * Replace all configured identity provider SamlEntities with the new SamlEntities.
38
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
39
    public function replaceAllIdps(array $newSamlEntities): void
40
    {
41
        $this->replaceAllOfType(SamlEntity::TYPE_IDP, $newSamlEntities);
42
    }
43
44
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $type should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $newSamlEntities should have a doc-comment as per coding-style.
Loading history...
45
     * Replace all configured SamlEntities with the new SamlEntities.
46
     *
47
     * Will be updated later, see https://www.pivotaltracker.com/story/show/83532704
48
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
49
    private function replaceAllOfType(string $type, array $newSamlEntities): void
0 ignored issues
show
Coding Style introduced by
Private method name "SamlEntityRepository::replaceAllOfType" must be prefixed with an underscore
Loading history...
50
    {
51
        $entityManager = $this->getEntityManager();
52
53
        $this->removeAllOfType($type);
54
55
        foreach ($newSamlEntities as $samlEntity) {
56
            $entityManager->persist($samlEntity);
57
        }
58
59
        $entityManager->flush();
60
    }
61
62
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $type should have a doc-comment as per coding-style.
Loading history...
63
     * Remove all configured SamlEntities of a specific type
64
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
65
    private function removeAllOfType(string $type): void
0 ignored issues
show
Coding Style introduced by
Private method name "SamlEntityRepository::removeAllOfType" must be prefixed with an underscore
Loading history...
66
    {
67
        $this
68
            ->getEntityManager()
69
            ->createQuery(
70
                'DELETE FROM '.SamlEntity::class.' se WHERE se.type = :type',
71
            )
72
            ->execute(['type' => $type]);
73
74
        $this->getEntityManager()->clear();
75
    }
76
}
77