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 ( 78c84d...9bdc70 )
by Baptiste
04:48
created

CacheLoadAverage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
lcom 1
cbo 4
dl 57
loc 57
c 1
b 0
f 1
ccs 22
cts 22
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A cpu() 4 4 1
A memory() 4 4 1
A processes() 4 4 1
A loadAverage() 18 18 3
A disk() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
19 View Code Duplication
final class CacheLoadAverage implements Server
20
{
21
    private $server;
22
    private $clock;
23
    private $threshold;
24
    private $cachedAt;
25
    private $data;
26
27 6
    public function __construct(
28
        Server $server,
29
        TimeContinuumInterface $clock,
30
        ElapsedPeriod $threshold
31
    ) {
32 6
        $this->server = $server;
33 6
        $this->clock = $clock;
34 6
        $this->threshold = $threshold;
35 6
    }
36
37 1
    public function cpu(): Cpu
38
    {
39 1
        return $this->server->cpu();
40
    }
41
42 1
    public function memory(): Memory
43
    {
44 1
        return $this->server->memory();
45
    }
46
47 1
    public function processes(): Processes
48
    {
49 1
        return $this->server->processes();
50
    }
51
52 1
    public function loadAverage(): LoadAverage
53
    {
54 1
        $now = $this->clock->now();
55
56
        if (
57 1
            $this->cachedAt &&
58 1
            $this->threshold->longerThan(
59 1
                $now->elapsedSince($this->cachedAt)
60
            )
61
        ) {
62 1
            return $this->data;
63
        }
64
65 1
        $this->data = $this->server->loadAverage();
66 1
        $this->cachedAt = $now;
67
68 1
        return $this->data;
69
    }
70
71 1
    public function disk(): Disk
72
    {
73 1
        return $this->server->disk();
74
    }
75
}
76