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.

CacheMemory::loadAverage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Server\Status\Servers\Decorator;
5
6
use Innmind\Server\Status\{
7
    Server,
8
    Server\Cpu,
9
    Server\Memory,
10
    Server\Processes,
11
    Server\LoadAverage,
12
    Server\Disk,
13
};
14
use Innmind\TimeContinuum\{
15
    Clock,
16
    ElapsedPeriod,
17
    PointInTime,
18
};
19
use Innmind\Url\Path;
20
21
final class CacheMemory implements Server
22
{
23
    private Server $server;
24
    private Clock $clock;
25
    private ElapsedPeriod $threshold;
26
    private ?PointInTime $cachedAt = null;
27
    private ?Memory $data = null;
28 18
29
    public function __construct(
30
        Server $server,
31
        Clock $clock,
32
        ElapsedPeriod $threshold
33 18
    ) {
34 18
        $this->server = $server;
35 18
        $this->clock = $clock;
36 18
        $this->threshold = $threshold;
37
    }
38 3
39
    public function cpu(): Cpu
40 3
    {
41
        return $this->server->cpu();
42
    }
43 3
44
    /**
45 3
     * @psalm-suppress InvalidNullableReturnType
46
     */
47
    public function memory(): Memory
48 3
    {
49 3
        $now = $this->clock->now();
50 3
51
        if (
52
            $this->cachedAt &&
53 3
            $this->threshold->longerThan(
54
                $now->elapsedSince($this->cachedAt)
55
            )
56 3
        ) {
57 3
            /** @psalm-suppress NullableReturnStatement */
58
            return $this->data;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->data could return the type null which is incompatible with the type-hinted return Innmind\Server\Status\Server\Memory. Consider adding an additional type-check to rule them out.
Loading history...
59 3
        }
60
61
        $this->data = $this->server->memory();
62 3
        $this->cachedAt = $now;
63
64 3
        return $this->data;
65
    }
66
67 3
    public function processes(): Processes
68
    {
69 3
        return $this->server->processes();
70
    }
71
72 3
    public function loadAverage(): LoadAverage
73
    {
74 3
        return $this->server->loadAverage();
75
    }
76
77
    public function disk(): Disk
78
    {
79
        return $this->server->disk();
80
    }
81
82
    public function tmp(): Path
83
    {
84
        return $this->server->tmp();
85
    }
86
}
87