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
05:37
created

Session::setContents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\React\Http\Middleware;
4
5
use const PHP_SESSION_NONE;
6
use const PHP_SESSION_ACTIVE;
7
8
final class Session
9
{
10
    /**
11
     * @var string
12
     */
13
    private $id = '';
14
15
    /**
16 10
     * @var array
17
     */
18 10
    private $contents = [];
19 10
20
    /**
21
     * @var SessionIdInterface
22
     */
23
    private $sessionId = [];
24 2
25
    /**
26 2
     * @var PHP_SESSION_NONE|PHP_SESSION_ACTIVE
27 2
     */
28
    private $status = PHP_SESSION_NONE;
29
30
    /**
31
     * @param string             $id
32 10
     * @param array              $contents
33
     * @param SessionIdInterface $sessionId
34 10
     */
35
    public function __construct(string $id, array $contents, SessionIdInterface $sessionId)
36
    {
37
        $this->id = $id;
38
        $this->contents = $contents;
39
        $this->sessionId = $sessionId;
40
41
        if ($this->id !== '') {
42
            $this->status = PHP_SESSION_ACTIVE;
0 ignored issues
show
Documentation Bug introduced by
It seems like \PHP_SESSION_ACTIVE of type integer is incompatible with the declared type object<PHP_SESSION_NONE>...ect<PHP_SESSION_ACTIVE> of property $status.

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...
43
        }
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getId(): string
50
    {
51
        return $this->id;
52
    }
53
54
    /**
55
     * @param array $contents
56
     */
57
    public function setContents(array $contents)
58
    {
59
        $this->contents = $contents;
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    public function getContents(): array
66
    {
67
        return $this->contents;
68
    }
69
70
    public function begin()
71
    {
72
        if ($this->status === PHP_SESSION_ACTIVE) {
73
            return true;
74
        }
75
76
        $this->status = PHP_SESSION_ACTIVE;
0 ignored issues
show
Documentation Bug introduced by
It seems like \PHP_SESSION_ACTIVE of type integer is incompatible with the declared type object<PHP_SESSION_NONE>...ect<PHP_SESSION_ACTIVE> of property $status.

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...
77
78
        if ($this->id === '') {
79
            $this->id = $this->sessionId->generate();
80
        }
81
    }
82
83
    public function end()
84
    {
85
        if ($this->status === PHP_SESSION_NONE) {
86
            return true;
87
        }
88
89
        $this->status = PHP_SESSION_NONE;
0 ignored issues
show
Documentation Bug introduced by
It seems like \PHP_SESSION_NONE of type integer is incompatible with the declared type object<PHP_SESSION_NONE>...ect<PHP_SESSION_ACTIVE> of property $status.

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...
90
        $this->id = '';
91
    }
92
93
    /**
94
     * @return bool
95
     */
96
    public function isActive(): bool
97
    {
98
        return $this->status === PHP_SESSION_ACTIVE;
99
    }
100
101
    public function regenerate()
102
    {
103
        // Can only regenerate active sessions
104
        if ($this->status !== PHP_SESSION_ACTIVE) {
105
            return false;
106
        }
107
108
        $this->id = $this->sessionId->generate();
109
110
        return true;
111
    }
112
}
113