AttributeSetWithFallbacks   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createFrom() 0 16 3
A create() 0 10 2
A __construct() 0 3 1
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(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