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
Push — master ( 7ce72c...a45381 )
by Cees-Jan
12s
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 string[]
24
     */
25
    private $oldIds = [];
26
27
    /**
28
     * @var int
29
     */
30
    private $status = \PHP_SESSION_NONE;
31
32
    /**
33
     * @param string             $id
34
     * @param array              $contents
35
     * @param SessionIdInterface $sessionId
36
     */
37 15
    public function __construct(string $id, array $contents, SessionIdInterface $sessionId)
38
    {
39 15
        $this->id = $id;
40 15
        $this->contents = $contents;
41 15
        $this->sessionId = $sessionId;
42
43 15
        if ($this->id !== '') {
44 4
            $this->status = \PHP_SESSION_ACTIVE;
45
        }
46 15
    }
47
48
    /**
49
     * @return string
50
     */
51 12
    public function getId(): string
52
    {
53 12
        return $this->id;
54
    }
55
56
    /**
57
     * @param array $contents
58
     */
59 4
    public function setContents(array $contents)
60
    {
61 4
        $this->contents = $contents;
62 4
    }
63
64
    /**
65
     * @return array
66
     */
67 12
    public function getContents(): array
68
    {
69 12
        return $this->contents;
70
    }
71
72
    /**
73
     * @return string[]
74
     */
75 13
    public function getOldIds(): array
76
    {
77 13
        return $this->oldIds;
78
    }
79
80 10 View Code Duplication
    public function begin()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82 10
        if ($this->status === \PHP_SESSION_ACTIVE) {
83
            return true;
84
        }
85
86 10
        $this->status = \PHP_SESSION_ACTIVE;
87
88 10
        if ($this->id === '') {
89 10
            $this->id = $this->sessionId->generate();
90
        }
91 10
    }
92
93 2
    public function end()
94
    {
95 2
        if ($this->status === \PHP_SESSION_NONE) {
96
            return true;
97
        }
98
99 2
        $this->oldIds[] = $this->id;
100 2
        $this->status = \PHP_SESSION_NONE;
101 2
        $this->id = '';
102 2
        $this->contents = [];
103 2
    }
104
105
    /**
106
     * @return bool
107
     */
108 13
    public function isActive(): bool
109
    {
110 13
        return $this->status === \PHP_SESSION_ACTIVE;
111
    }
112
113 1 View Code Duplication
    public function regenerate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
    {
115
        // Can only regenerate active sessions
116 1
        if ($this->status !== \PHP_SESSION_ACTIVE) {
117
            return false;
118
        }
119
120 1
        $this->oldIds[] = $this->id;
121 1
        $this->id = $this->sessionId->generate();
122
123 1
        return true;
124
    }
125
}
126