Completed
Push — remote-vetting ( 4132ed...71cf35 )
by
unknown
01:30
created

Profile   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromData() 0 14 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
    public static function fromData(array $data)
80
    {
81
        $identity = new self();
82
        $identity->id = $data['id'];
83
        $identity->nameId = $data['name_id'];
84
        $identity->institution = $data['institution'];
85
        $identity->email = $data['email'];
86
        $identity->commonName = $data['common_name'];
87
        $identity->preferredLocale = $data['preferred_locale'];
88
        $identity->authorizations = $data['authorizations'];
89
        $identity->isSraa = $data['is_sraa'];
90
91
        return $identity;
92
    }
93
94
95
    /**
96
     * @return array List with institutions
97
     */
98
    public function getRaaInstitutions()
99
    {
100
        $choices = [];
101
        foreach ($this->authorizations as $institution => $role) {
102
            if ($role[0] == 'raa') {
103
                $choices[$institution] = $institution;
104
            }
105
        }
106
107
        return $choices;
108
    }
109
}
110