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 ( e41626...d433ef )
by Baptiste
02:32
created

LinuxFacade   A

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 = new Process('top -bn1 | grep \'%Cpu\'');
0 ignored issues
show
Bug introduced by
'top -bn1 | grep '%Cpu'' of type string is incompatible with the type array expected by parameter $command of Symfony\Component\Process\Process::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
        $process = new Process(/** @scrutinizer ignore-type */ 'top -bn1 | grep \'%Cpu\'');
Loading history...
20 6
        $process->run();
21
22 6
        if (!$process->isSuccessful()) {
23
            throw new CpuUsageNotAccessible;
24
        }
25
26 6
        $percentages = (new Str($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 = new Process('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) (string) $percentages->get('user')),
41 6
            new Percentage((float) (string) $percentages->get('sys')),
42 6
            new Percentage((float) (string) $percentages->get('idle')),
43 6
            new Cores((int) (string) ($cores ?? 1))
44
        );
45
    }
46
}
47