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.
Passed
Push — develop ( dd0027...dc3f07 )
by Baptiste
03:07
created

LinuxFacade::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 19
c 0
b 0
f 0
ccs 0
cts 13
cp 0
rs 9.8666
cc 2
nc 2
nop 0
crap 6
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
final class LinuxFacade
15
{
16
    public function __invoke(): Cpu
17
    {
18
        $process = new Process('top -bn1 | grep \'%Cpu\'');
19
        $process->run();
20
21
        if (!$process->isSuccessful()) {
22
            throw new CpuUsageNotAccessible;
23
        }
24
25
        $percentages = (new Str($process->getOutput()))
26
            ->trim()
27
            ->capture(
28
                '~^%Cpu\(s\): *(?P<user>\d+\.?\d*) us, *(?P<sys>\d+\.?\d*) sy, *(\d+\.?\d*) ni, *(?P<idle>\d+\.?\d*) id~'
29
            );
30
31
        return new Cpu(
32
            new Percentage((float) (string) $percentages->get('user')),
33
            new Percentage((float) (string) $percentages->get('sys')),
34
            new Percentage((float) (string) $percentages->get('idle'))
35
        );
36
    }
37
}
38