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   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 23
c 2
b 0
f 2
dl 0
loc 64
rs 10
ccs 22
cts 24
cp 0.9167
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A cpu() 0 3 1
A tmp() 0 3 1
A memory() 0 18 3
A loadAverage() 0 3 1
A disk() 0 3 1
A __construct() 0 8 1
A processes() 0 3 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