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:26
created

Session::isActive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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 15
    public function __construct(string $id, array $contents, SessionIdInterface $sessionId)
33
    {
34 15
        $this->id = $id;
35 15
        $this->contents = $contents;
36 15
        $this->sessionId = $sessionId;
37
38 15
        if ($this->id !== '') {
39 4
            $this->status = \PHP_SESSION_ACTIVE;
40
        }
41 15
    }
42
43
    /**
44
     * @return string
45
     */
46 14
    public function getId(): string
47
    {
48 14
        return $this->id;
49
    }
50
51
    /**
52
     * @param array $contents
53
     */
54 4
    public function setContents(array $contents)
55
    {
56 4
        $this->contents = $contents;
57 4
    }
58
59
    /**
60
     * @return array
61
     */
62 14
    public function getContents(): array
63
    {
64 14
        return $this->contents;
65
    }
66
67 2
    public function begin()
68
    {
69 2
        if ($this->status === \PHP_SESSION_ACTIVE) {
70
            return true;
71
        }
72
73 2
        $this->status = \PHP_SESSION_ACTIVE;
74
75 2
        if ($this->id === '') {
76 2
            $this->id = $this->sessionId->generate();
77
        }
78 2
    }
79
80 2
    public function end()
81
    {
82 2
        if ($this->status === \PHP_SESSION_NONE) {
83
            return true;
84
        }
85
86 2
        $this->status = \PHP_SESSION_NONE;
87 2
        $this->id = '';
88 2
    }
89
90
    /**
91
     * @return bool
92
     */
93 5
    public function isActive(): bool
94
    {
95 5
        return $this->status === \PHP_SESSION_ACTIVE;
96
    }
97
98 1
    public function regenerate()
99
    {
100
        // Can only regenerate active sessions
101 1
        if ($this->status !== \PHP_SESSION_ACTIVE) {
102
            return false;
103
        }
104
105 1
        $this->id = $this->sessionId->generate();
106
107 1
        return true;
108
    }
109
}
110