Completed
Pull Request — develop (#22)
by A.
06:45
created

SpecifiedConsentListService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4286
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
/**
4
 * Copyright 2015 SURFnet B.V.
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 OpenConext\ProfileBundle\Service;
20
21
use OpenConext\Profile\Value\Consent;
22
use OpenConext\Profile\Value\ConsentList;
23
use OpenConext\Profile\Value\SpecifiedConsent;
24
use OpenConext\Profile\Value\SpecifiedConsentList;
25
use OpenConext\ProfileBundle\Exception\RuntimeException;
26
use OpenConext\ProfileBundle\Security\Authentication\Entity\User;
27
use OpenConext\ProfileBundle\User\UserProvider;
28
use Surfnet\SamlBundle\SAML2\Attribute\Filter\AttributeFilter;
29
30
class SpecifiedConsentListService
31
{
32
    /**
33
     * @var ConsentService
34
     */
35
    private $consentService;
36
37
    /**
38
     * @var AttributeFilter
39
     */
40
    private $attributeFilter;
41
42
    /**
43
     * @param ConsentService $consentService
44
     * @param AttributeFilter $attributeFilter
45
     */
46
    public function __construct(
47
        ConsentService $consentService,
48
        AttributeFilter $attributeFilter
49
    ) {
50
        $this->consentService  = $consentService;
51
        $this->attributeFilter = $attributeFilter;
52
    }
53
54
    /**
55
     * @param User $user
56
     * @return SpecifiedConsentList
57
     */
58
    public function getListFor(User $user)
59
    {
60
        $consentList        = $this->consentService->findAllFor($user);
61
        $filteredAttributes = $user->getAttributes()->apply($this->attributeFilter);
62
63
        $specifiedConsents = $consentList->map(function (Consent $consent) use ($filteredAttributes) {
64
            return SpecifiedConsent::specifies($consent, $filteredAttributes);
65
        });
66
67
        return SpecifiedConsentList::createWith($specifiedConsents);
68
    }
69
}
70