CookieSession   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 59
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A get() 0 4 1
A set() 0 6 1
A clear() 0 6 1
1
<?php
2
3
namespace Reallyli\AB\Session;
4
5
use Illuminate\Support\Facades\Cookie;
6
7
class CookieSession implements SessionInterface
8
{
9
    /**
10
     * The name of the cookie.
11
     *
12
     * @var string
13
     */
14
    protected $cookieName = 'ab';
15
16
    /**
17
     * A copy of the session data.
18
     *
19
     * @var array
20
     */
21
    protected $data = null;
22
23
    /**
24
     * Cookie lifetime.
25
     *
26
     * @var int
27
     */
28
    protected $minutes = 60;
29
30
    /**
31
     * Constructor.
32
     */
33
    public function __construct()
34
    {
35
        $this->data = Cookie::get($this->cookieName) ? json_decode(Cookie::get($this->cookieName), true) : [];
0 ignored issues
show
Documentation Bug introduced by
It seems like \Illuminate\Support\Faca...eName), true) : array() of type * is incompatible with the declared type array of property $data.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function get($name, $default = null)
42
    {
43
        return array_get($this->data, $name, $default);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function set($name, $value)
50
    {
51
        $this->data[$name] = $value;
52
53
        return response(Cookie::queue($this->cookieName, json_encode($this->data)));
0 ignored issues
show
Unused Code introduced by
The call to Cookie::queue() has too many arguments starting with json_encode($this->data).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function clear()
60
    {
61
        $this->data = [];
62
63
        return Cookie::queue($this->cookieName, null, -2628000);
0 ignored issues
show
Unused Code introduced by
The call to Cookie::queue() has too many arguments starting with null.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
64
    }
65
}
66