Completed
Pull Request — develop (#38)
by A.
04:16
created

User   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 8
c 3
b 0
f 1
lcom 3
cbo 1
dl 0
loc 69
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A withSupportContactEmail() 0 7 1
A switchLocaleTo() 0 4 1
A hasSupportContactEmail() 0 4 1
A getSupportContactEmail() 0 4 1
A getLocale() 0 4 1
A getAttributes() 0 4 1
A getId() 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\Api\User as UserInterface;
22
use OpenConext\Profile\Value\EmailAddress;
23
use OpenConext\Profile\Value\Locale;
24
use Surfnet\SamlBundle\SAML2\Attribute\AttributeSet;
25
26
final class User implements UserInterface
27
{
28
    /**
29
     * @var AuthenticatedUser
30
     */
31
    private $authenticatedUser;
32
33
    /**
34
     * @var Locale
35
     */
36
    private $locale;
37
38
    /**
39
     * @var EmailAddress|null
40
     */
41
    private $supportContactEmail;
42
43
    /**
44
     * @param AuthenticatedUser $authenticatedUser
45
     * @param Locale $locale
46
     */
47
    public function __construct(AuthenticatedUser $authenticatedUser, Locale $locale)
48
    {
49
        $this->authenticatedUser = $authenticatedUser;
50
        $this->locale            = $locale;
51
    }
52
53
    /**
54
     * @param EmailAddress $supportContactEmail
55
     * @return User
56
     */
57
    public function withSupportContactEmail(EmailAddress $supportContactEmail)
58
    {
59
        $newUser = clone $this;
60
        $newUser->supportContactEmail = $supportContactEmail;
61
62
        return $newUser;
63
    }
64
65
    public function switchLocaleTo(Locale $locale)
66
    {
67
        $this->locale = $locale;
68
    }
69
70
    public function hasSupportContactEmail()
71
    {
72
        return $this->supportContactEmail !== null;
73
    }
74
75
    public function getSupportContactEmail()
76
    {
77
        return $this->supportContactEmail;
78
    }
79
80
    public function getLocale()
81
    {
82
        return $this->locale;
83
    }
84
85
    public function getAttributes()
86
    {
87
        return $this->authenticatedUser->getAttributes();
88
    }
89
90
    public function getId()
91
    {
92
        return $this->authenticatedUser->getNameId();
93
    }
94
}
95