Completed
Pull Request — develop (#225)
by
unknown
09:12 queued 07:20
created

RemoteVettingIdenityProviderDto::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Copyright 2020 SURFnet B.V.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Dto;
19
20
use Surfnet\StepupSelfService\SelfServiceBundle\Assert;
21
22
class RemoteVettingIdenityProviderDto
23
{
24
    /**
25
     * @var string
26
     */
27
    private $name;
28
29
    /**
30
     * @var string[]
31
     */
32
    private $descriptions;
33
34
    /**
35
     * @var string
36
     */
37
    private $logo;
38
39
    /**
40
     * @var string
41
     */
42
    private $slug;
43
44
45
    /**
46
     * @var string
47
     */
48
    private $entityId;
49
50
    /**
51
     * @var string
52
     */
53
    private $ssoUrl;
54
55
    /**
56
     * @var string
57
     */
58
    private $privateKey;
59
60
    /**
61
     * @var string
62
     */
63
    private $certificateFile;
64
65
    /**
66
     * @param string $identityId
0 ignored issues
show
Bug introduced by
There is no parameter named $identityId. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
67
     * @param string $secondFactorId
0 ignored issues
show
Bug introduced by
There is no parameter named $secondFactorId. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
68
     * @return RemoteVettingIdenityProviderDto
69
     */
70
    public static function create(array $configData)
71
    {
72
        Assert::notBlank($configData['name'], 'The name of a remote vetting identity provider must not be blank');
73
        Assert::string($configData['name'], 'The name of a remote vetting identity provider must be of type string');
74
        Assert::allString($configData['description'], 'All description entries must be of type string');
75
        Assert::notBlank($configData['logo'], 'The logo of a remote vetting identity provider must not be blank');
76
        Assert::string($configData['logo'], 'The logo of a remote vetting identity provider must be of type string');
77
        Assert::string($configData['slug'], 'The slug of a remote identity provider must be of type string');
78
        Assert::alnum($configData['slug'], 'The slug must be alphanumeric');
79
80
        Assert::keyExists($configData, 'entityId', 'entityId should be set');
81
        Assert::keyExists($configData, 'ssoUrl', 'ssoUrl should be set');
82
        Assert::keyExists($configData, 'privateKey', 'privateKey should be set');
83
        Assert::keyExists($configData, 'certificateFile', 'certificateFile should be set');
84
85
        Assert::url($configData['entityId'], 'entityId should be an url');
86
        Assert::url($configData['ssoUrl'], 'ssoUrl should be an url');
87
        Assert::string($configData['privateKey'], 'privateKey should be a string');
88
        Assert::string($configData['certificateFile'], 'certificateFile should be a string');
89
90
        $identityProvider = new self();
91
        $identityProvider->name = $configData['name'];
92
        $identityProvider->descriptions = $configData['description'];
93
        $identityProvider->logo = $configData['logo'];
94
        $identityProvider->slug = $configData['slug'];
95
96
        $identityProvider->entityId = $configData['entityId'];
97
        $identityProvider->ssoUrl = $configData['ssoUrl'];
98
        $identityProvider->privateKey = $configData['privateKey'];
99
        $identityProvider->certificateFile = $configData['certificateFile'];
100
101
        return $identityProvider;
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    public function getName()
108
    {
109
        return $this->name;
110
    }
111
112
    /**
113
     * @return string[]
0 ignored issues
show
Documentation introduced by
Should the return type not be string?

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...
114
     */
115
    public function getDescription($lang)
116
    {
117
        Assert::keyExists($this->descriptions, $lang);
118
        return $this->descriptions[$lang];
119
    }
120
121
    /**
122
     * @return string
123
     */
124
    public function getLogo()
125
    {
126
        return $this->logo;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getSlug()
133
    {
134
        return $this->slug;
135
    }
136
137
    /**
138
     * @return string
139
     */
140
    public function getSsoUrl(): string
141
    {
142
        return $this->ssoUrl;
143
    }
144
145
    /**
146
     * @return string
147
     */
148
    public function getPrivateKey(): string
149
    {
150
        return $this->privateKey;
151
    }
152
153
    /**
154
     * @return string
155
     */
156
    public function getCertificateFile(): string
157
    {
158
        return $this->certificateFile;
159
    }
160
161
    /**
162
     * @return string
163
     */
164
    public function getEntityId(): string
165
    {
166
        return $this->entityId;
167
    }
168
}
169