Completed
Pull Request — develop (#35)
by A.
03:03
created

AuthenticatedUser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 6
c 2
b 0
f 2
lcom 0
cbo 2
dl 0
loc 77
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createFrom() 0 4 1
A __construct() 0 8 1
A getNameId() 0 4 1
A getAttributes() 0 4 1
A getAuthenticatingAuthorities() 0 4 1
A __toString() 0 4 1
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\Entity;
20
21
use OpenConext\Profile\Assert;
22
use Surfnet\SamlBundle\SAML2\Attribute\AttributeSet;
23
use Surfnet\SamlBundle\SAML2\Response\AssertionAdapter;
24
25
final class AuthenticatedUser
26
{
27
    /**
28
     * @var string
29
     */
30
    private $nameId;
31
32
    /**
33
     * @var AttributeSet
34
     */
35
    private $attributes;
36
37
    /**
38
     * @var array
39
     */
40
    private $authenticatingAuthorities;
41
42
    /**
43
     * @param AssertionAdapter $assertionAdapter
44
     * @param array $authenticatingAuthorities
45
     * @return AuthenticatedUser
46
     */
47
    public static function createFrom(AssertionAdapter $assertionAdapter, array $authenticatingAuthorities)
48
    {
49
        return new self($assertionAdapter->getNameId(), $assertionAdapter->getAttributeSet(), $authenticatingAuthorities);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
50
    }
51
52
    /**
53
     * @param string $nameId
54
     * @param AttributeSet $attributes
55
     * @param array $authenticatingAuthorities
56
     */
57
    private function __construct($nameId, AttributeSet $attributes, array $authenticatingAuthorities)
58
    {
59
        Assert::string($nameId);
60
61
        $this->nameId                    = $nameId;
62
        $this->attributes                = $attributes;
63
        $this->authenticatingAuthorities = $authenticatingAuthorities;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getNameId()
70
    {
71
        return $this->nameId;
72
    }
73
74
    /**
75
     * @return AttributeSet
76
     */
77
    public function getAttributes()
78
    {
79
        return $this->attributes;
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function getAuthenticatingAuthorities()
86
    {
87
        return $this->authenticatingAuthorities;
88
    }
89
90
    /**
91
     * Using toString in order to comply with AbstractToken's setUser method,
92
     * which uses the string representation to detect changes in the user object.
93
     * Not implementing a UserInterface, because methods defined there will not be used.
94
     *
95
     * @return string
96
     */
97
    public function __toString()
98
    {
99
        return $this->nameId;
100
    }
101
}
102