Passed
Push — master ( f070bb...4ac1e0 )
by Marcel
10:45
created

RequestState::__unserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-Core package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace LightSaml\State\Request;
13
14
use LightSaml\Meta\ParameterBag;
15
16
class RequestState
17
{
18
    /** @var string */
19
    private $id;
20
21
    /** @var ParameterBag */
22
    private $parameters;
23
24
    /**
25
     * @param string $id
26
     * @param mixed  $nonce
27
     */
28
    public function __construct($id = null, $nonce = null)
29
    {
30
        $this->id = $id;
31
        $this->parameters = new ParameterBag();
32
        if ($nonce) {
33
            $this->parameters->set('nonce', $nonce);
34
        }
35
    }
36
37
    /**
38
     * @param string $id
39
     *
40
     * @return RequestState
41
     */
42
    public function setId($id)
43
    {
44
        $this->id = $id;
45
46
        return $this;
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getId()
53
    {
54
        return $this->id;
55
    }
56
57
    /**
58
     * @return ParameterBag
59
     */
60
    public function getParameters()
61
    {
62
        return $this->parameters;
63
    }
64
65
    /**
66
     * @deprecated Since 1.2, to be removed in 2.0. Use getParameters() instead
67
     *
68
     * @param mixed $nonce
69
     *
70
     * @return RequestState
71
     */
72
    public function setNonce($nonce)
73
    {
74
        $this->parameters->set('nonce', $nonce);
75
76
        return $this;
77
    }
78
79
    /**
80
     * @deprecated Since 1.2, to be removed in 2.0. Use getParameters() instead
81
     *
82
     * @return mixed
83
     */
84
    public function getNonce()
85
    {
86
        return $this->parameters->get('nonce');
87
    }
88
89
    public function __serialize(): array {
90
        return [
91
            'id' => $this->id,
92
            'parameters' => $this->parameters->all()
93
        ];
94
    }
95
96
    public function __unserialize(array $data): void {
97
        $this->id = $data['id'];
98
        $this->parameters = new ParameterBag($data['parameters']);
99
    }
100
}
101