ConsentType::isImplicit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Copyright 2015 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 OpenConext\Profile\Value;
20
21
use OpenConext\Profile\Assert;
22
23
final class ConsentType
24
{
25
    const TYPE_EXPLICIT = 'explicit';
26
    const TYPE_IMPLICIT = 'implicit';
27
28
    /**
29
     * @var string
30
     */
31
    private $consentType;
32
33
    /**
34
     * @return ConsentType
35
     */
36
    public static function explicit()
37
    {
38
        return new self(self::TYPE_EXPLICIT);
39
    }
40
41
    /**
42
     * @return ConsentType
43
     */
44
    public static function implicit()
45
    {
46
        return new self(self::TYPE_IMPLICIT);
47
    }
48
49
    /**
50
     * @param string $consentType
51
     */
52
    private function __construct($consentType)
53
    {
54
        Assert::choice(
55
            $consentType,
56
            [ConsentType::TYPE_EXPLICIT, ConsentType::TYPE_IMPLICIT],
57
            '"%s" is not one of the valid ConsentTypes: %s'
58
        );
59
60
        $this->consentType = $consentType;
61
    }
62
63
    /**
64
     * @param ConsentType $other
65
     * @return bool
66
     */
67
    public function equals(ConsentType $other)
68
    {
69
        return $this->consentType === $other->consentType;
70
    }
71
72
    /**
73
     * @return bool
74
     */
75
    public function isExplicit()
76
    {
77
        return $this->consentType === self::TYPE_EXPLICIT;
78
    }
79
80
    /**
81
     * @return bool
82
     */
83
    public function isImplicit()
84
    {
85
        return $this->consentType === self::TYPE_IMPLICIT;
86
    }
87
88
    /**
89
     * @return string
90
     */
91
    public function __toString()
92
    {
93
        return $this->consentType;
94
    }
95
}
96