Completed
Push — master ( 9a65be...fb506a )
by Antonio Carlos
02:32 queued 11s
created

Session::setStateless()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PragmaRX\Google2FALaravel\Support;
4
5
trait Session
6
{
7
    /**
8
     * Flag to disable the session for API usage.
9
     *
10
     * @var bool
11
     */
12
    protected $stateless = false;
13
14
    /**
15
     * Make a session var name for.
16
     *
17
     * @param null $name
18
     *
19
     * @return mixed
20
     */
21 8
    protected function makeSessionVarName($name = null)
22
    {
23 8
        return $this->config('session_var').(is_null($name) || empty($name) ? '' : '.'.$name);
24
    }
25
26
    /**
27
     * Get a session var value.
28
     *
29
     * @param null $var
30
     *
31
     * @return mixed
32
     */
33 8
    public function sessionGet($var = null, $default = null)
34
    {
35 8
        if ($this->stateless) {
36 1
            return $default;
37
        }
38
39 7
        return $this->getRequest()->session()->get(
40 7
            $this->makeSessionVarName($var),
41
            $default
42
        );
43
    }
44
45
    /**
46
     * Put a var value to the current session.
47
     *
48
     * @param $var
49
     * @param $value
50
     *
51
     * @return mixed
52
     */
53 5
    protected function sessionPut($var, $value)
54
    {
55 5
        if ($this->stateless) {
56
            return $value;
57
        }
58
59 5
        $this->getRequest()->session()->put(
60 5
            $this->makeSessionVarName($var),
61
            $value
62
        );
63
64 5
        return $value;
65
    }
66
67
    /**
68
     * Forget a session var.
69
     *
70
     * @param null $var
71
     */
72 3
    protected function sessionForget($var = null)
73
    {
74 3
        if ($this->stateless) {
75
            return;
76
        }
77
78 3
        $this->getRequest()->session()->forget(
79 3
            $this->makeSessionVarName($var)
80
        );
81 3
    }
82
83
    /**
84
     * @param mixed $stateless
85
     *
86
     * @return Authenticator
87
     */
88 1
    public function setStateless($stateless = true)
89
    {
90 1
        $this->stateless = $stateless;
91
92 1
        return $this;
93
    }
94
95
    abstract protected function config($string, $children = []);
96
97
    abstract public function getRequest();
98
}
99