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.

OSXFacade::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 32
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 7.1521

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 21
c 1
b 0
f 1
dl 0
loc 32
ccs 5
cts 22
cp 0.2273
rs 9.584
cc 3
nc 3
nop 0
crap 7.1521
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 = Process::fromShellCommandline('top -l 1 -s 0 | grep \'CPU usage\'');
20 3
        $process->run();
21
22 3
        if (!$process->isSuccessful()) {
23 3
            throw new CpuUsageNotAccessible;
24
        }
25
26
        $percentages = Str::of($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 = Process::fromShellCommandline('sysctl -a | grep \'hw.ncpu:\'');
33
        $process->run();
34
35
        if ($process->isSuccessful()) {
36
            $match = Str::of($process->getOutput())
37
                ->trim()
38
                ->capture(
39
                    '~^hw.ncpu: (?P<cores>\d+)$~'
40
                );
41
            $cores = $match->get('cores')->toString();
42
        }
43
44
        return new Cpu(
45
            new Percentage((float) $percentages->get('user')->toString()),
46
            new Percentage((float) $percentages->get('sys')->toString()),
47
            new Percentage((float) $percentages->get('idle')->toString()),
48
            new Cores((int) ($cores ?? 1)),
49
        );
50
    }
51
}
52