Completed
Push — feature/fga-ra-management ( 9de126...037bdc )
by
unknown
21:54
created

RaListingService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 54
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findByIdentityId() 0 4 1
A findByIdentityIdAndInstitution() 0 4 1
A search() 0 8 1
A listRegistrationAuthoritiesFor() 0 10 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\Service;
20
21
use Surfnet\Stepup\Identity\Value\IdentityId;
22
use Surfnet\Stepup\Identity\Value\Institution;
23
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\RaListing;
24
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\RaListingQuery;
25
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\RaListingRepository;
26
use Surfnet\StepupMiddleware\ApiBundle\Identity\Value\RegistrationAuthorityCredentials;
27
28
class RaListingService extends AbstractSearchService
29
{
30
    /**
31
     * @var RaListingRepository
32
     */
33
    private $raListingRepository;
34
35
    public function __construct(RaListingRepository $raListingRepository)
36
    {
37
        $this->raListingRepository = $raListingRepository;
38
    }
39
40
    /**
41
     * @param IdentityId $identityId
42
     * @return null|\Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\RaListing
0 ignored issues
show
Documentation introduced by
Should the return type not be object|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
43
     */
44
    public function findByIdentityId(IdentityId $identityId)
45
    {
46
        return $this->raListingRepository->findByIdentityId($identityId);
47
    }
48
49
    public function findByIdentityIdAndInstitution(IdentityId $identityId, Institution $raInstitution)
50
    {
51
        return $this->raListingRepository->findByIdentityIdAndInstitution($identityId, $raInstitution);
52
    }
53
54
    /**
55
     * @param RaListingQuery $query
56
     * @return \Pagerfanta\Pagerfanta
57
     */
58
    public function search(RaListingQuery $query)
59
    {
60
        $doctrineQuery = $this->raListingRepository->createSearchQuery($query);
61
62
        $paginator = $this->createPaginatorFrom($doctrineQuery, $query);
63
64
        return $paginator;
65
    }
66
67
    /**
68
     * @param Institution $institution
69
     * @return RegistrationAuthorityCredentials[]
70
     */
71
    public function listRegistrationAuthoritiesFor(Institution $institution)
72
    {
73
        $raListings = $this->raListingRepository->listRasFor($institution);
74
75
        return $raListings
76
            ->map(function (RaListing $raListing) {
77
                return RegistrationAuthorityCredentials::fromRaListing($raListing);
78
            })
79
            ->toArray();
80
    }
81
}
82