Session::removeRedirectUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/patron/license
6
 * @link       https://www.flipboxfactory.com/software/patron/
7
 */
8
9
namespace flipbox\patron\services;
10
11
use Craft;
12
use flipbox\patron\Patron;
13
use yii\base\Component;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class Session extends Component
20
{
21
    /**
22
     * @return string
23
     */
24
    public static function stateKey(): string
25
    {
26
        return md5('Craft.' . Patron::class . '.' . Craft::$app->id . '.State');
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public static function providerKey(): string
33
    {
34
        return md5('Craft.' . Patron::class . '.' . Craft::$app->id . '.Provider');
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public static function redirectKey(): string
41
    {
42
        return md5('Craft.' . Patron::class . '.' . Craft::$app->id . '.Redirect');
43
    }
44
45
    /**
46
     * @return static
47
     */
48
    public function removeAll()
49
    {
50
        return $this->removeProvider()
51
            ->removeState()
52
            ->removeRedirectUrl();
53
    }
54
55
    /**
56
     * @return string|null
57
     */
58
    public function getState()
59
    {
60
        return Craft::$app->getSession()->get(static::stateKey());
61
    }
62
63
    /**
64
     * @param string $value
65
     * @return static
66
     */
67
    public function setState(string $value)
68
    {
69
        Craft::$app->getSession()->set(static::stateKey(), $value);
70
        return $this;
71
    }
72
73
    /**
74
     * @return static
75
     */
76
    public function removeState()
77
    {
78
        Craft::$app->getSession()->remove(static::stateKey());
79
        return $this;
80
    }
81
82
    /**
83
     * @return string|null
84
     */
85
    public function getProvider()
86
    {
87
        return Craft::$app->getSession()->get(static::providerKey());
88
    }
89
90
    /**
91
     * @param string $value
92
     * @return static
93
     */
94
    public function setProvider(string $value)
95
    {
96
        Craft::$app->getSession()->set(static::providerKey(), $value);
97
        return $this;
98
    }
99
100
    /**
101
     * @return static
102
     */
103
    public function removeProvider()
104
    {
105
        Craft::$app->getSession()->remove(static::providerKey());
106
        return $this;
107
    }
108
109
    /**
110
     * @return string|null
111
     */
112
    public function getRedirectUrl()
113
    {
114
        return Craft::$app->getSession()->get(static::redirectKey());
115
    }
116
117
    /**
118
     * @param string $value
119
     * @return static
120
     */
121
    public function setRedirectUrl(string $value)
122
    {
123
        Craft::$app->getSession()->set(static::redirectKey(), $value);
124
        return $this;
125
    }
126
127
    /**
128
     * @return static
129
     */
130
    public function removeRedirectUrl()
131
    {
132
        Craft::$app->getSession()->remove(static::redirectKey());
133
        return $this;
134
    }
135
}
136