Completed
Pull Request — develop (#82)
by
unknown
01:54
created

SpecifiedConsent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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\Profile\Value;
20
21
use Surfnet\SamlBundle\SAML2\Attribute\Attribute;
22
use Surfnet\SamlBundle\SAML2\Attribute\AttributeSet;
23
24
class SpecifiedConsent
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
25
{
26
    /**
27
     * @var Consent
28
     */
29
    private $consent;
30
31
    /**
32
     * @var AttributeSet
33
     */
34
    private $releasedAttributes;
35
36
    /**
37
     * @param Consent $consent
38
     * @param AttributeSet $releasedAttributes
39
     * @return SpecifiedConsent
40
     */
41
    public static function specifies(Consent $consent, AttributeSet $releasedAttributes)
42
    {
43
        return new self($consent, $releasedAttributes);
44
    }
45
46
    /**
47
     * @param Consent $consent
48
     * @param AttributeSet $releasedAttributes
49
     */
50
    private function __construct(Consent $consent, AttributeSet $releasedAttributes)
51
    {
52
        $this->consent            = $consent;
53
        $this->releasedAttributes = $releasedAttributes;
54
    }
55
56
    /**
57
     * @return Consent
58
     */
59
    public function getConsent()
60
    {
61
        return $this->consent;
62
    }
63
64
    /**
65
     * @return AttributeSet
66
     */
67
    public function getReleasedAttributes()
68
    {
69
        return $this->releasedAttributes;
70
    }
71
72
    public function hasMultipleSources()
73
    {
74
        $sources = [];
75
        foreach ($this->getReleasedAttributes() as $attribute) {
76
            $source = $attribute->getValue()[0]['source'];
77
            $sources[$source] = $source;
78
        }
79
80
        return count($sources) > 1;
81
    }
82
83
    /**
84
     * Groups the released attributes on the group they originate from. This can be used to show the attributes.
85
     *
86
     * @return Attribute[]
87
     */
88
    public function getReleasedAttributesGroupedBySource()
89
    {
90
        $grouped = [];
91
        foreach ($this->getReleasedAttributes() as $attribute) {
92
            // The source is the same for all possible attribute values, so use the first one.
93
            $source = $attribute->getValue()[0]['source'];
94
            $grouped[$source][] = $attribute;
95
        }
96
        return $grouped;
97
    }
98
}
99