Passed
Push — release/5.1 ( 34e089...a6d03f )
by Michiel
12:26
created

RegistrationAuthorityRole::raa()   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
    /**
31
     * @var int
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
    /**
50
     * @SuppressWarnings(PHPMD.ShortMethodName) no use in lengthening a domain term for the sake of shutting up PHPMD
51
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
52
    public static function ra()
53
    {
54
        return new self(self::ROLE_RA);
55
    }
56
57
    public static function raa()
58
    {
59
        return new self(self::ROLE_RAA);
60
    }
61
62
    /**
63
     * @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...
64
     * @return bool
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
65
     */
66
    public function equals(RegistrationAuthorityRole $role)
67
    {
68
        return $this->role === $role->role;
69
    }
70
71
    /**
72
     * @return bool
73
     */
74
    public function isRa()
75
    {
76
        return $this->role === self::ROLE_RA;
77
    }
78
79
    /**
80
     * @return bool
81
     */
82
    public function isRaa()
83
    {
84
        return $this->role === self::ROLE_RAA;
85
    }
86
87
    public function jsonSerialize()
88
    {
89
        return $this->role;
90
    }
91
92
    public function __toString()
93
    {
94
        return (string) $this->role;
95
    }
96
97
    public static function deserialize(array $data)
98
    {
99
        return new self($data['role']);
100
    }
101
102
    public function serialize(): array
103
    {
104
        return ['role' => $this->role];
105
    }
106
}
107