Completed
Push — master ( 32a55a...fb9711 )
by Mitchel
02:18
created

TokenType::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Bunq\Token;
4
5
final class TokenType
6
{
7
    const INSTALLATION_TOKEN = 'installation.token';
8
    const SESSION_TOKEN      = 'session.token';
9
10
    /**
11
     * @var string
12
     */
13
    private $type;
14
15
    /**
16
     * @return self[]
17
     */
18
    public static function all()
19
    {
20
        return [
21
            self::INSTALLATION_TOKEN(),
22
            self::SESSION_TOKEN(),
23
        ];
24
    }
25
26
    /**
27
     * @return string[]
28
     */
29
    public static function allAsString()
30
    {
31
        return [
32
            self::INSTALLATION_TOKEN,
33
            self::SESSION_TOKEN,
34
        ];
35
    }
36
37
    /**
38
     * @return self
39
     */
40
    public static function INSTALLATION_TOKEN()
41
    {
42
        return new self(self::INSTALLATION_TOKEN);
43
    }
44
45
    /**
46
     * @return self
47
     */
48
    public static function SESSION_TOKEN()
49
    {
50
        return new self(self::SESSION_TOKEN);
51
    }
52
53
    /**
54
     * @param $type
55
     *
56
     * @return self
57
     */
58
    public static function fromString($type)
59
    {
60
        return new self($type);
61
    }
62
63
    /**
64
     * @param mixed $other
65
     *
66
     * @return bool
67
     */
68
    public function equals($other)
69
    {
70
        return $other == $this;
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function toString()
77
    {
78
        return $this->type;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function __toString()
85
    {
86
        return $this->toString();
87
    }
88
89
    /**
90
     * @param string $type
91
     */
92
    private function __construct($type)
93
    {
94
        $this->type = (string)$type;
95
96
        $this->protect();
97
    }
98
99
    /**
100
     * Check if the tokenType exists in our list
101
     */
102
    private function protect()
103
    {
104
        if (!in_array($this->type, self::allAsString(), true)) {
105
            throw new \InvalidArgumentException(sprintf('Invalid token type "%s"', $this->type));
106
        }
107
    }
108
}
109