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

OSXFacade   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 22.73%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 22
c 1
b 0
f 1
dl 0
loc 34
ccs 5
cts 22
cp 0.2273
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 32 3
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 OSXFacade
16
{
17 3
    public function __invoke(): Cpu
18
    {
19 3
        $process = new Process('top -l 1 -s 0 | grep \'CPU usage\'');
0 ignored issues
show
Bug introduced by
'top -l 1 -s 0 | grep 'CPU usage'' 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 -l 1 -s 0 | grep \'CPU usage\'');
Loading history...
20 3
        $process->run();
21
22 3
        if (!$process->isSuccessful()) {
23 3
            throw new CpuUsageNotAccessible;
24
        }
25
26
        $percentages = (new Str($process->getOutput()))
27
            ->trim()
28
            ->capture(
29
                '~^CPU usage: (?P<user>\d+\.?\d*)% user, (?P<sys>\d+\.?\d*)% sys, (?P<idle>\d+\.?\d*)% idle$~'
30
            );
31
32
        $process = new Process('sysctl -a | grep \'hw.ncpu:\'');
33
        $process->run();
34
35
        if ($process->isSuccessful()) {
36
            $match = (new Str($process->getOutput()))
37
                ->trim()
38
                ->capture(
39
                    '~^hw.ncpu: (?P<cores>\d+)$~'
40
                );
41
            $cores = $match['cores'];
42
        }
43
44
        return new Cpu(
45
            new Percentage((float) (string) $percentages->get('user')),
46
            new Percentage((float) (string) $percentages->get('sys')),
47
            new Percentage((float) (string) $percentages->get('idle')),
48
            new Cores((int) (string) ($cores ?? 1))
49
        );
50
    }
51
}
52