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.

LinuxFacade   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 18
c 1
b 0
f 1
dl 0
loc 29
ccs 17
cts 18
cp 0.9444
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 27 4
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
    Server\Cpu\Cores,
10
    Exception\CpuUsageNotAccessible,
11
};
12
use Innmind\Immutable\Str;
13
use Symfony\Component\Process\Process;
14
15
final class LinuxFacade
16
{
17 6
    public function __invoke(): Cpu
18
    {
19 6
        $process = Process::fromShellCommandline('top -bn1 | grep \'%Cpu\'');
20 6
        $process->run();
21
22 6
        if (!$process->isSuccessful()) {
23
            throw new CpuUsageNotAccessible;
24
        }
25
26 6
        $percentages = Str::of($process->getOutput())
27 6
            ->trim()
28 6
            ->capture(
29 6
                '~^%Cpu\(s\): *(?P<user>\d+\.?\d*) us, *(?P<sys>\d+\.?\d*) sy, *(\d+\.?\d*) ni, *(?P<idle>\d+\.?\d*) id~'
30
            );
31
32 6
        $process = Process::fromShellCommandline('nproc');
33 6
        $process->run();
34
35 6
        if ($process->isSuccessful()) {
36 6
            $cores = ((int) (string) $process->getOutput()) ?: 1;
37
        }
38
39 6
        return new Cpu(
40 6
            new Percentage((float) $percentages->get('user')->toString()),
41 6
            new Percentage((float) $percentages->get('sys')->toString()),
42 6
            new Percentage((float) $percentages->get('idle')->toString()),
43 6
            new Cores((int) (string) ($cores ?? 1)),
44
        );
45
    }
46
}
47