Completed
Push — develop ( 7a755c...9656fb )
by
unknown
02:36 queued 10s
created

ServiceProvider   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 5

Importance

Changes 0
Metric Value
wmc 12
lcom 3
cbo 5
dl 0
loc 120
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A getEntity() 0 4 1
A getDisplayName() 0 4 1
A getNameIdFormat() 0 4 1
A getLocaleAwareEntityName() 0 10 2
A hasEulaUrl() 0 4 1
A getEulaUrl() 0 8 2
A hasSupportEmail() 0 4 1
A getSupportEmail() 0 8 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\Consent;
20
21
use OpenConext\EngineBlockApiClientBundle\Exception\LogicException;
22
use OpenConext\Profile\Assert;
23
use OpenConext\Profile\Value\DisplayName;
24
use OpenConext\Profile\Value\NameIdFormat;
25
use OpenConext\Profile\Value\ContactEmailAddress;
26
use OpenConext\Profile\Value\Entity;
27
use OpenConext\Profile\Value\Url;
28
29
final class ServiceProvider
30
{
31
    /**
32
     * @var Entity
33
     */
34
    private $entity;
35
36
    /**
37
     * @var DisplayName
38
     */
39
    private $displayName;
40
41
    /**
42
     * @var NameIdFormat
43
     */
44
    private $nameIdFormat;
45
46
    /**
47
     * @var Url|null
48
     */
49
    private $eulaUrl;
50
51
    /**
52
     * @var ContactEmailAddress|null
53
     */
54
    private $supportEmail;
55
56
    public function __construct(
57
        Entity $entity,
58
        DisplayName $displayName,
59
        NameIdFormat $nameIdFormat,
60
        Url $eulaUrl = null,
61
        ContactEmailAddress $supportEmail = null
62
    ) {
63
        $this->entity       = $entity;
64
        $this->displayName  = $displayName;
65
        $this->nameIdFormat = $nameIdFormat;
66
        $this->eulaUrl      = $eulaUrl;
67
        $this->supportEmail = $supportEmail;
68
    }
69
70
    /**
71
     * @return Entity
72
     */
73
    public function getEntity()
74
    {
75
        return $this->entity;
76
    }
77
78
    /**
79
     * @return DisplayName
80
     */
81
    public function getDisplayName()
82
    {
83
        return $this->displayName;
84
    }
85
86
    /**
87
     * @return NameIdFormat
88
     */
89
    public function getNameIdFormat()
90
    {
91
        return $this->nameIdFormat;
92
    }
93
94
    /**
95
     * @param string $locale
96
     * @return string
97
     */
98
    public function getLocaleAwareEntityName($locale)
99
    {
100
        Assert::string($locale);
101
102
        if ($this->displayName->hasFilledTranslationForLocale($locale)) {
103
            return $this->displayName->getTranslation($locale);
104
        }
105
106
        return $this->entity->getEntityId()->getEntityId();
107
    }
108
109
    /**
110
     * @return bool
111
     */
112
    public function hasEulaUrl()
113
    {
114
        return $this->eulaUrl !== null;
115
    }
116
117
    /**
118
     * @return Url
0 ignored issues
show
Documentation introduced by
Should the return type not be Url|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
119
     */
120
    public function getEulaUrl()
121
    {
122
        if (!$this->hasEulaUrl()) {
123
            throw new LogicException('Service provider has no EULA url');
124
        }
125
126
        return $this->eulaUrl;
127
    }
128
129
    /**
130
     * @return bool
131
     */
132
    public function hasSupportEmail()
133
    {
134
        return $this->supportEmail !== null;
135
    }
136
137
    /**
138
     * @return ContactEmailAddress
0 ignored issues
show
Documentation introduced by
Should the return type not be ContactEmailAddress|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
139
     */
140
    public function getSupportEmail()
141
    {
142
        if (!$this->hasSupportEmail()) {
143
            throw new LogicException('Service provider has no support e-mail address');
144
        }
145
146
        return $this->supportEmail;
147
    }
148
}
149