Completed
Pull Request — develop (#290)
by
unknown
05:53 queued 02:45
created

InstitutionListingRepository::getAuthorizationRolesForRa()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
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 Surfnet\Stepup\Identity\Value\Institution;
23
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\InstitutionListing;
24
25
class InstitutionListingRepository extends EntityRepository
26
{
27
    public function save(InstitutionListing $institution)
28
    {
29
        $this->getEntityManager()->persist($institution);
30
        $this->getEntityManager()->flush();
31
    }
32
33
    public function addIfNotExists(Institution $institution)
34
    {
35
        $existsQuery = $this->createQueryBuilder('i')
36
            ->where('i.institution = :institution')
37
            ->setParameter('institution', (string)$institution)
38
            ->getQuery()
39
            ->getOneOrNullResult();
40
41
        if ($existsQuery) {
42
            return;
43
        }
44
45
        $listing = InstitutionListing::createFrom($institution);
46
47
        $this->save($listing);
48
    }
49
}
50