Token::toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace nyx\auth;
2
3
/**
4
 * Token
5
 *
6
 * @package     Nyx\Auth
7
 * @version     0.1.0
8
 * @author      Michal Chojnacki <[email protected]>
9
 * @copyright   2012-2017 Nyx Dev Team
10
 * @link        https://github.com/unyx/nyx
11
 */
12
class Token implements interfaces\Token
13
{
14
    /**
15
     * @var string  The Token's identifier.
16
     */
17
    protected $id;
18
19
    /**
20
     * Creates a new Token instance.
21
     *
22
     * @param   string  $id     The Token's identifier.
23
     */
24
    public function __construct(string $id)
25
    {
26
        $this->id = $id;
27
    }
28
29
    /**
30
     * {@inheritDoc}
31
     */
32
    public function getId() : string
33
    {
34
        return $this->id;
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40
    public function matches(interfaces\Token $that) : bool
41
    {
42
        return $this->id === $that->getId();
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    public function serialize() : string
49
    {
50
        return serialize($this->id);
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     */
56
    public function unserialize($data)
57
    {
58
        $this->id = unserialize($data);
59
    }
60
61
    /**
62
     * {@inheritDoc}
63
     */
64
    public function jsonSerialize()
65
    {
66
        return $this->id;
67
    }
68
69
    /**
70
     * {@inheritDoc}
71
     */
72
    public function toJson(int $options = 0) : string
73
    {
74
        return json_encode($this->jsonSerialize(), $options);
75
    }
76
77
    /**
78
     * {@inheritDoc}
79
     */
80
    public function toString() : string
81
    {
82
        return $this->id;
83
    }
84
85
    /**
86
     * {@inheritDoc}
87
     */
88
    public function __toString() : string
89
    {
90
        return $this->toString();
91
    }
92
93
    /**
94
     * {@inheritDoc}
95
     */
96
    public function toArray() : array
97
    {
98
        return [
99
            'id' => $this->id
100
        ];
101
    }
102
}
103