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 — develop ( 9ca8cc...2705d1 )
by Baptiste
03:06
created

CacheCpu::loadAverage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
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
};
13
use Innmind\TimeContinuum\{
14
    TimeContinuumInterface,
15
    ElapsedPeriod
16
};
17
18 View Code Duplication
final class CacheCpu implements Server
1 ignored issue
show
Duplication introduced by
This class 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...
19
{
20
    private $server;
21
    private $clock;
22
    private $threshold;
23
    private $cachedAt;
24
    private $data;
25
26 5
    public function __construct(
27
        Server $server,
28
        TimeContinuumInterface $clock,
29
        ElapsedPeriod $threshold
30
    ) {
31 5
        $this->server = $server;
32 5
        $this->clock = $clock;
33 5
        $this->threshold = $threshold;
34 5
    }
35
36 1
    public function cpu(): Cpu
37
    {
38 1
        $now = $this->clock->now();
39
40
        if (
41 1
            $this->cachedAt &&
42 1
            $this->threshold->longerThan(
43 1
                $now->elapsedSince($this->cachedAt)
44
            )
45
        ) {
46 1
            return $this->data;
47
        }
48
49 1
        $this->data = $this->server->cpu();
50 1
        $this->cachedAt = $now;
51
52 1
        return $this->data;
53
    }
54
55 1
    public function memory(): Memory
56
    {
57 1
        return $this->server->memory();
58
    }
59
60 1
    public function processes(): Processes
61
    {
62 1
        return $this->server->processes();
63
    }
64
65 1
    public function loadAverage(): LoadAverage
66
    {
67 1
        return $this->server->loadAverage();
68
    }
69
}
70