Passed
Push — bugfix/5.1-profile ( 934735...50d43f )
by Michiel
04:55
created

RegistrationAuthorityRole::ra()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
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
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
namespace Surfnet\Stepup\Identity\Value;
20
21
use Broadway\Serializer\Serializable as SerializableInterface;
22
use Surfnet\Stepup\Exception\InvalidArgumentException;
23
24
final class RegistrationAuthorityRole implements SerializableInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class RegistrationAuthorityRole
Loading history...
25
{
26
    const ROLE_RA   = 1;
27
    const ROLE_RAA  = 2;
28
    const ROLE_SRAA = 3;
29
30
    /**RegistrationAuthorityRole
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Doc comment short description must be on the first line
Loading history...
31
     * @var int
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
32
     */
33
    private $role;
34
35
    /**
36
     * @param string $role may not be an empty string
37
     */
38
    public function __construct($role)
39
    {
40
        if (!is_int($role) || !in_array($role, [self::ROLE_RA, self::ROLE_RAA, self::ROLE_SRAA])) {
0 ignored issues
show
introduced by
The condition is_int($role) is always false.
Loading history...
41
            throw new InvalidArgumentException(
42
                'Invalid role given, role must be one of RegistrationAuthorityRole::[ROLE_RA|ROLE_RAA|ROLE_SRAA]'
43
            );
44
        }
45
46
        $this->role = $role;
47
    }
48
49
    public static function ra()
50
    {
51
        return new self(self::ROLE_RA);
52
    }
53
54
    public static function raa()
55
    {
56
        return new self(self::ROLE_RAA);
57
    }
58
59
    /**
60
     * @param RegistrationAuthorityRole $role
0 ignored issues
show
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
61
     * @return bool
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
62
     */
63
    public function equals(RegistrationAuthorityRole $role)
64
    {
65
        return $this->role === $role->role;
66
    }
67
68
    /**
69
     * @return bool
70
     */
71
    public function isRa()
72
    {
73
        return $this->role === self::ROLE_RA;
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function isRaa()
80
    {
81
        return $this->role === self::ROLE_RAA;
82
    }
83
84
    public function jsonSerialize()
85
    {
86
        return $this->role;
87
    }
88
89
    public function __toString()
90
    {
91
        return (string) $this->role;
92
    }
93
94
    public static function deserialize(array $data)
95
    {
96
        return new self($data['role']);
97
    }
98
99
    public function serialize(): array
100
    {
101
        return ['role' => $this->role];
102
    }
103
}
104