Completed
Push — master ( 4e85d3...2a4bc0 )
by Antonio Carlos
02:15
created

Session::makeSessionVarName()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PragmaRX\Google2FALaravel\Support;
4
5
trait Session
6
{
7
    /**
8
     * Make a session var name for.
9
     *
10
     * @param null $name
11
     *
12
     * @return mixed
13
     */
14 7
    protected function makeSessionVarName($name = null)
15
    {
16 7
        return $this->config('session_var').(is_null($name) || empty($name) ? '' : '.'.$name);
17
    }
18
19
    /**
20
     * Get a session var value.
21
     *
22
     * @param null $var
23
     *
24
     * @return mixed
25
     */
26 8
    public function sessionGet($var = null, $default = null)
27
    {
28 8
        if ($this->stateless) {
0 ignored issues
show
Bug introduced by
The property stateless does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29 1
            return $default;
30
        }
31
32 7
        return $this->getRequest()->session()->get(
33 7
            $this->makeSessionVarName($var),
34
            $default
35
        );
36
    }
37
38
    /**
39
     * Put a var value to the current session.
40
     *
41
     * @param $var
42
     * @param $value
43
     *
44
     * @return mixed
45
     */
46 4
    protected function sessionPut($var, $value)
47
    {
48 4
        if ($this->stateless) {
49
            return $value;
50
        }
51
52 4
        $this->getRequest()->session()->put(
53 4
            $this->makeSessionVarName($var),
54
            $value
55
        );
56
57 4
        return $value;
58
    }
59
60
    /**
61
     * Forget a session var.
62
     *
63
     * @param null $var
64
     */
65 3
    protected function sessionForget($var = null)
66
    {
67 3
        if ($this->stateless) {
68
            return;
69
        }
70
71 3
        $this->getRequest()->session()->forget(
72 3
            $this->makeSessionVarName($var)
73
        );
74 3
    }
75
76
    abstract protected function config($string, $children = []);
77
78
    abstract public function getRequest();
79
}
80