Completed
Push — master ( d21da7...883721 )
by Daan van
03:11
created

RaService::listRasWithoutRaas()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 3
eloc 11
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\StepupSelfService\SelfServiceBundle\Service;
20
21
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\RegistrationAuthorityCredentialsCollection;
22
use Surfnet\StepupMiddlewareClientBundle\Identity\Service\RaService as ApiRaService;
23
24
class RaService
25
{
26
    /**
27
     * @var ApiRaService
28
     */
29
    private $api;
30
31
    public function __construct(ApiRaService $raService)
32
    {
33
        $this->api = $raService;
34
    }
35
36
    /**
37
     * @param string $institution
38
     * @return RegistrationAuthorityCredentialsCollection
39
     */
40
    public function listRas($institution)
41
    {
42
        return $this->api->listRas($institution);
43
    }
44
45
    public function listRasWithoutRaas($institution)
46
    {
47
        $allRas = $this->api->listRas($institution);
48
49
        $rasWithoutRaas = [];
50
        foreach ($allRas->getElements() as $ra) {
51
            if (!$ra->isRaa) {
52
                $rasWithoutRaas[] = $ra;
53
            }
54
        }
55
56
        // All RAs and RAAs are fetched, so this can safely be returned (no pagination is used here)
57
        return new RegistrationAuthorityCredentialsCollection(
58
            $rasWithoutRaas,
59
            count($rasWithoutRaas),
60
            $allRas->getItemsPerPage(),
61
            $allRas->getCurrentPage()
62
        );
63
    }
64
}
65