Completed
Push — develop ( 279d91...fe8037 )
by
unknown
05:38 queued 03:31
created

Profile   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 91
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromData() 0 15 1
A getRaaInstitutions() 0 11 3
1
<?php
2
3
/**
4
 * Copyright 2019 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 Surfnet\StepupMiddlewareClientBundle\Identity\Dto;
20
21
use Surfnet\StepupMiddlewareClientBundle\Dto\Dto;
22
use Symfony\Component\Validator\Constraints as Assert;
23
24
class Profile implements Dto
25
{
26
    /**
27
     * @Assert\NotBlank(message="middleware_client.dto.identity.id.must_not_be_blank")
28
     * @Assert\Type(type="string", message="middleware_client.dto.identity.id.must_be_string")
29
     * @var string
30
     */
31
    public $id;
32
33
    /**
34
     * @Assert\NotBlank(message="middleware_client.dto.identity.name_id.must_not_be_blank")
35
     * @Assert\Type(type="string", message="middleware_client.dto.identity.name_id.must_be_string")
36
     * @var string
37
     */
38
    public $nameId;
39
40
    /**
41
     * @Assert\NotBlank(message="middleware_client.dto.identity.institution.must_not_be_blank")
42
     * @Assert\Type(type="string", message="middleware_client.dto.identity.institution.must_be_string")
43
     * @var string
44
     */
45
    public $institution;
46
47
    /**
48
     * @Assert\NotBlank(message="middleware_client.dto.identity.email.must_not_be_blank")
49
     * @Assert\Type(type="string", message="middleware_client.dto.identity.email.must_be_string")
50
     * @var string
51
     */
52
    public $email;
53
54
    /**
55
     * @Assert\NotBlank(message="middleware_client.dto.identity.common_name.must_not_be_blank")
56
     * @Assert\Type(type="string", message="middleware_client.dto.identity.common_name.must_be_string")
57
     * @var string
58
     */
59
    public $commonName;
60
61
    /**
62
     * @Assert\NotBlank(message="middleware_client.dto.identity.preferred_locale.must_not_be_blank")
63
     * @Assert\Type(type="string", message="middleware_client.dto.identity.preferred_locale.must_be_string")
64
     * @var string
65
     */
66
    public $preferredLocale;
67
68
    /**
69
     * @var bool
70
     */
71
    public $isSraa;
72
73
    /**
74
     * @var array
75
     */
76
    public $authorizations;
77
78
    /**
79
     * @var array
80
     */
81
    public $implicitRaaAt;
82
83
    public static function fromData(array $data)
84
    {
85
        $identity = new self();
86
        $identity->id = $data['id'];
87
        $identity->nameId = $data['name_id'];
88
        $identity->institution = $data['institution'];
89
        $identity->email = $data['email'];
90
        $identity->commonName = $data['common_name'];
91
        $identity->preferredLocale = $data['preferred_locale'];
92
        $identity->authorizations = $data['authorizations'];
93
        $identity->implicitRaaAt = $data['implicit_raa_at'];
94
        $identity->isSraa = $data['is_sraa'];
95
96
        return $identity;
97
    }
98
99
100
    /**
101
     * @return array List with institutions
102
     */
103
    public function getRaaInstitutions()
104
    {
105
        $choices = [];
106
        foreach ($this->authorizations as $institution => $role) {
107
            if ($role[0] == 'raa') {
108
                $choices[$institution] = $institution;
109
            }
110
        }
111
112
        return $choices;
113
    }
114
}
115