GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#2)
by Cees-Jan
01:27
created

Session   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 79.41%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 105
ccs 27
cts 34
cp 0.7941
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getId() 0 4 1
A setContents() 0 4 1
A getContents() 0 4 1
A begin() 0 12 3
A end() 0 9 2
A isActive() 0 4 1
A regenerate() 0 11 2
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\React\Http\Middleware;
4
5
final class Session
6
{
7
    /**
8
     * @var string
9
     */
10
    private $id = '';
11
12
    /**
13
     * @var array
14
     */
15
    private $contents = [];
16
17
    /**
18
     * @var SessionIdInterface
19
     */
20
    private $sessionId = [];
21
22
    /**
23
     * @var int
24
     */
25
    private $status = \PHP_SESSION_NONE;
26
27
    /**
28
     * @param string             $id
29
     * @param array              $contents
30
     * @param SessionIdInterface $sessionId
31
     */
32 14
    public function __construct(string $id, array $contents, SessionIdInterface $sessionId)
33
    {
34 14
        $this->id = $id;
35 14
        $this->contents = $contents;
36 14
        $this->sessionId = $sessionId;
37
38 14
        if ($this->id !== '') {
39 4
            $this->status = \PHP_SESSION_ACTIVE;
40
        }
41 14
    }
42
43
    /**
44
     * @return string
45
     */
46 13
    public function getId(): string
47
    {
48 13
        return $this->id;
49
    }
50
51
    /**
52
     * @param array $contents
53
     */
54 3
    public function setContents(array $contents)
55
    {
56 3
        $this->contents = $contents;
57 3
    }
58
59
    /**
60
     * @return array
61
     */
62 13
    public function getContents(): array
63
    {
64 13
        return $this->contents;
65
    }
66
67 1
    public function begin()
68
    {
69 1
        if ($this->status === \PHP_SESSION_ACTIVE) {
70
            return true;
71
        }
72
73 1
        $this->status = \PHP_SESSION_ACTIVE;
74
75 1
        if ($this->id === '') {
76 1
            $this->id = $this->sessionId->generate();
77
        }
78 1
    }
79
80 1
    public function end()
81
    {
82 1
        if ($this->status === \PHP_SESSION_NONE) {
83
            return true;
84
        }
85
86 1
        $this->status = \PHP_SESSION_NONE;
87 1
        $this->id = '';
88 1
    }
89
90
    /**
91
     * @return bool
92
     */
93 4
    public function isActive(): bool
94
    {
95 4
        return $this->status === \PHP_SESSION_ACTIVE;
96
    }
97
98
    public function regenerate()
99
    {
100
        // Can only regenerate active sessions
101
        if ($this->status !== \PHP_SESSION_ACTIVE) {
102
            return false;
103
        }
104
105
        $this->id = $this->sessionId->generate();
106
107
        return true;
108
    }
109
}
110