Completed
Push — develop ( 042500...f65382 )
by A.
04:31 queued 27s
created

AttributeSetWithFallbacks::createFrom()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 2
1
<?php
2
3
/**
4
 * Copyright 2016 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\Attribute;
20
21
use SAML2_Assertion;
22
use Surfnet\SamlBundle\Exception\UnknownUrnException;
23
use Surfnet\SamlBundle\SAML2\Attribute\Attribute;
24
use Surfnet\SamlBundle\SAML2\Attribute\AttributeDefinition;
25
use Surfnet\SamlBundle\SAML2\Attribute\AttributeDictionary;
26
use Surfnet\SamlBundle\SAML2\Attribute\AttributeSet;
27
use Surfnet\SamlBundle\SAML2\Attribute\AttributeSetFactory;
28
use Surfnet\SamlBundle\SAML2\Attribute\AttributeSetInterface;
29
30
final class AttributeSetWithFallbacks extends AttributeSet implements AttributeSetFactory, AttributeSetInterface
31
{
32
    public static function createFrom(SAML2_Assertion $assertion, AttributeDictionary $attributeDictionary)
33
    {
34
        $attributeSet = new AttributeSetWithFallbacks();
35
36
        foreach ($assertion->getAttributes() as $urn => $attributeValue) {
37
            try {
38
                $attributeDefinition = $attributeDictionary->getAttributeDefinitionByUrn($urn);
39
            } catch (UnknownUrnException $exception) {
40
                $attributeDefinition = new AttributeDefinition($urn, $urn, $urn);
41
            }
42
43
            $attributeSet->initializeWith(new Attribute($attributeDefinition, $attributeValue));
44
        }
45
46
        return $attributeSet;
47
    }
48
49
    public static function create(array $attributes)
50
    {
51
        $attributeSet = new AttributeSetWithFallbacks();
52
53
        foreach ($attributes as $attribute) {
54
            $attributeSet->initializeWith($attribute);
55
        }
56
57
        return $attributeSet;
58
    }
59
60
    private function __construct()
0 ignored issues
show
Bug introduced by
Consider using a different method name as you override a private method of the parent class.

Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.

Loading history...
61
    {
62
    }
63
}
64