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 ( 9ca8cc...2705d1 )
by Baptiste
03:06
created

OSXFacade::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 21
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2.9322

Importance

Changes 0
Metric Value
dl 21
loc 21
c 0
b 0
f 0
ccs 5
cts 13
cp 0.3846
rs 9.3142
cc 2
eloc 13
nc 2
nop 0
crap 2.9322
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 View Code Duplication
final class OSXFacade
1 ignored issue
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16 1
    public function __invoke(): Cpu
17
    {
18 1
        $process = new Process('top -l 1 -s 0 | grep \'CPU usage\'');
19 1
        $process->run();
20
21 1
        if (!$process->isSuccessful()) {
22 1
            throw new CpuUsageNotAccessible;
23
        }
24
25
        $percentages = (new Str($process->getOutput()))
26
            ->trim()
27
            ->capture(
28
                '~^CPU usage: (?P<user>\d+\.?\d*)% user, (?P<sys>\d+\.?\d*)% sys, (?P<idle>\d+\.?\d*)% idle$~'
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