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

Session   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 121
Duplicated Lines 19.83 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 24
loc 121
ccs 36
cts 39
cp 0.9231
rs 10
c 0
b 0
f 0

9 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 getOldIds() 0 4 1
A begin() 12 12 3
A end() 0 11 2
A isActive() 0 4 1
A regenerate() 12 12 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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