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
Push — master ( 2352be...4fa160 )
by Baptiste
03:32 queued 59s
created

CacheCpu   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 23
dl 0
loc 60
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A cpu() 0 17 3
A disk() 0 3 1
A tmp() 0 3 1
A processes() 0 3 1
A loadAverage() 0 3 1
A __construct() 0 8 1
A memory() 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
    TimeContinuumInterface,
16
    ElapsedPeriod
17
};
18
use Innmind\Url\PathInterface;
19
20
final class CacheCpu implements Server
21
{
22
    private $server;
23
    private $clock;
24
    private $threshold;
25
    private $cachedAt;
26
    private $data;
27
28
    public function __construct(
29
        Server $server,
30
        TimeContinuumInterface $clock,
31
        ElapsedPeriod $threshold
32
    ) {
33
        $this->server = $server;
34
        $this->clock = $clock;
35
        $this->threshold = $threshold;
36
    }
37
38
    public function cpu(): Cpu
39
    {
40
        $now = $this->clock->now();
41
42
        if (
43
            $this->cachedAt &&
44
            $this->threshold->longerThan(
45
                $now->elapsedSince($this->cachedAt)
46
            )
47
        ) {
48
            return $this->data;
49
        }
50
51
        $this->data = $this->server->cpu();
52
        $this->cachedAt = $now;
53
54
        return $this->data;
55
    }
56
57
    public function memory(): Memory
58
    {
59
        return $this->server->memory();
60
    }
61
62
    public function processes(): Processes
63
    {
64
        return $this->server->processes();
65
    }
66
67
    public function loadAverage(): LoadAverage
68
    {
69
        return $this->server->loadAverage();
70
    }
71
72
    public function disk(): Disk
73
    {
74
        return $this->server->disk();
75
    }
76
77
    public function tmp(): PathInterface
78
    {
79
        return $this->server->tmp();
80
    }
81
}
82