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 ( 160f54...78c84d )
by Baptiste
04:03
created

LinuxFacade   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 24
loc 24
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 21 21 2

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\Facade\Cpu;
5
6
use Innmind\Server\Status\{
7
    Server\Cpu,
8
    Server\Cpu\Percentage,
9
    Exception\CpuUsageNotAccessible
10
};
11
use Innmind\Immutable\Str;
12
use Symfony\Component\Process\Process;
13
14 View Code Duplication
final class LinuxFacade
15
{
16 2
    public function __invoke(): Cpu
17
    {
18 2
        $process = new Process('top -bn1 | grep \'%Cpu\'');
19 2
        $process->run();
20
21 2
        if (!$process->isSuccessful()) {
22
            throw new CpuUsageNotAccessible;
23
        }
24
25 2
        $percentages = (new Str($process->getOutput()))
26 2
            ->trim()
27 2
            ->capture(
28 2
                '~^%Cpu\(s\): *(?P<user>\d+\.?\d*) us, *(?P<sys>\d+\.?\d*) sy, *(\d+\.?\d*) ni, *(?P<idle>\d+\.?\d*) id~'
29
            );
30
31 2
        return new Cpu(
32 2
            new Percentage((float) (string) $percentages->get('user')),
33 2
            new Percentage((float) (string) $percentages->get('sys')),
34 2
            new Percentage((float) (string) $percentages->get('idle'))
35
        );
36
    }
37
}
38