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.

ClientIdSession   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 3 1
A generateId() 0 3 1
A __construct() 0 4 1
A get() 0 3 1
1
<?php
2
3
namespace ProtoneMedia\AnalyticsEventTracking\Http;
4
5
use Illuminate\Session\Store;
6
use Illuminate\Support\Str;
7
8
class ClientIdSession implements ClientIdRepository
9
{
10
    private Store $session;
11
    private string $key;
12
13
    public function __construct(Store $session, string $key)
14
    {
15
        $this->session = $session;
16
        $this->key     = $key;
17
    }
18
19
    /**
20
     * Stores the Client ID in the session.
21
     */
22
    public function update(string $clientId): void
23
    {
24
        $this->session->put($this->key, $clientId);
25
    }
26
27
    /**
28
     * Gets the Client ID from the session or generates one.
29
     */
30
    public function get(): ?string
31
    {
32
        return $this->session->get($this->key, fn () => $this->generateId());
33
    }
34
35
    /**
36
     * Generates a UUID and stores it in the session.
37
     */
38
    private function generateId(): string
39
    {
40
        return tap(Str::uuid(), fn ($id) => $this->update($id));
41
    }
42
}
43