Completed
Push — feature/fine-grained-authoriza... ( 5fbefa )
by
unknown
02:52
created

InstitutionRole::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * Copyright 2018 SURFnet B.V.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not select 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\Stepup\Configuration\Value;
19
20
use JsonSerializable;
21
use Surfnet\Stepup\Exception\InvalidArgumentException;
22
23
final class InstitutionRole implements JsonSerializable
24
{
25
    const ROLE_USE_RA = 'use_ra';
26
    const ROLE_USE_RAA = 'use_raa';
27
    const ROLE_SELECT_RAA = 'select_raa';
28
29
    private static $validRoles = [
30
        self::ROLE_USE_RA,
31
        self::ROLE_USE_RAA,
32
        self::ROLE_SELECT_RAA,
33
    ];
34
35
    /**
36
     * @var string
37
     */
38
    private $type;
39
40
    /**
41
     * InstitutionRole constructor.
42
     * @param $type
43
     */
44
    public function __construct($type)
45
    {
46
        if (!in_array($type, self::$validRoles)) {
47
            throw new InvalidArgumentException();
48
        }
49
50
        $this->type = $type;
51
    }
52
53
    /**
54
     * @return InstitutionRole
55
     */
56
    public static function useRa()
57
    {
58
        return new self(self::ROLE_USE_RA);
59
    }
60
61
    /**
62
     * @return InstitutionRole
63
     */
64
    public static function useRaa()
65
    {
66
        return new self(self::ROLE_USE_RAA);
67
    }
68
69
    /**
70
     * @return InstitutionRole
71
     */
72
    public static function selectRaa()
73
    {
74
        return new self(self::ROLE_SELECT_RAA);
75
    }
76
77
    /**
78
     * @param InstitutionRole $role
79
     * @return bool
80
     */
81
    public function equals(InstitutionRole $role)
82
    {
83
        return $this->type == $role->getType();
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getType()
90
    {
91
        return $this->type;
92
    }
93
94
    public function jsonSerialize()
95
    {
96
        return $this->type;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function __toString()
103
    {
104
        return $this->type;
105
    }
106
}
107