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 ( e478fb...dd0027 )
by Baptiste
03:53
created

LinuxFacade::__invoke()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 41
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 2.0001

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 28
cts 29
cp 0.9655
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 27
nc 2
nop 0
crap 2.0001
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Server\Status\Facade\Memory;
5
6
use Innmind\Server\Status\{
7
    Server\Memory,
8
    Server\Memory\Bytes,
9
    Exception\MemoryUsageNotAccessible
10
};
11
use Innmind\Immutable\{
12
    Str,
13
    Map
14
};
15
use Symfony\Component\Process\Process;
16
17
final class LinuxFacade
18
{
19
    private static $entries = [
20
        'MemTotal' => 'total',
21
        'Active' => 'active',
22
        'Inactive' => 'inactive',
23
        'MemFree' => 'free',
24
        'SwapCached' => 'swap',
25
    ];
26
27 4
    public function __invoke(): Memory
28
    {
29 4
        $process = new Process('cat /proc/meminfo');
30 4
        $process->run();
31
32 4
        if (!$process->isSuccessful()) {
33
            throw new MemoryUsageNotAccessible;
34
        }
35
36 4
        $amounts = (new Str($process->getOutput()))
37 4
            ->trim()
38 4
            ->split("\n")
39 4
            ->filter(static function(Str $line): bool {
40 4
                return $line->matches(
41 4
                    '~^('.implode('|', array_keys(self::$entries)).'):~'
42
                );
43 4
            })
44 4
            ->reduce(
45 4
                new Map('string', 'int'),
46 4
                static function(Map $map, Str $line): Map {
47 4
                    $elements = $line->capture('~^(?P<key>[a-zA-Z]+): +(?P<value>\d+) kB$~');
48
49 4
                    return $map->put(
50 4
                        self::$entries[(string) $elements->get('key')],
51 4
                        ((int) (string) $elements->get('value')) * Bytes::BYTES
52
                    );
53 4
                }
54
            );
55
56 4
        $used = $amounts->get('total') - $amounts->get('free');
57 4
        $wired = $used - $amounts->get('active') - $amounts->get('inactive');
58
59 4
        return new Memory(
60 4
            new Bytes($amounts->get('total')),
61 4
            new Bytes($wired),
62 4
            new Bytes($amounts->get('active')),
63 4
            new Bytes($amounts->get('free')),
64 4
            new Bytes($amounts->get('swap')),
65 4
            new Bytes($used)
66
        );
67
    }
68
}
69