InstitutionListingRepository   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 28
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 4 1
A addIfNotExists() 0 15 2
A __construct() 0 3 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\Persistence\ManagerRegistry;
23
use Surfnet\Stepup\Identity\Value\Institution;
24
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\InstitutionListing;
25
26
/**
27
 * @deprecated This could probably be removed and is only used in migrations
28
 * @see app/DoctrineMigrations/Version20160719090052.php#L51
29
 * @extends ServiceEntityRepository<InstitutionListing>
30
 */
31
class InstitutionListingRepository extends ServiceEntityRepository
32
{
33
    public function __construct(ManagerRegistry $registry)
34
    {
35
        parent::__construct($registry, InstitutionListing::class);
36
    }
37
38
    public function save(InstitutionListing $institution): void
39
    {
40
        $this->getEntityManager()->persist($institution);
41
        $this->getEntityManager()->flush();
42
    }
43
44
    public function addIfNotExists(Institution $institution): void
45
    {
46
        $existsQuery = $this->createQueryBuilder('i')
47
            ->where('i.institution = :institution')
48
            ->setParameter('institution', (string)$institution)
49
            ->getQuery()
50
            ->getOneOrNullResult();
51
52
        if ($existsQuery) {
53
            return;
54
        }
55
56
        $listing = InstitutionListing::createFrom($institution);
57
58
        $this->save($listing);
59
    }
60
}
61