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::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 39
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 2.0002

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 26
c 2
b 0
f 1
dl 0
loc 39
ccs 26
cts 27
cp 0.963
rs 9.504
cc 2
nc 2
nop 0
crap 2.0002
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 6
    public function __invoke(): Memory
28
    {
29 6
        $process = new Process('cat /proc/meminfo');
0 ignored issues
show
Bug introduced by
'cat /proc/meminfo' 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

29
        $process = new Process(/** @scrutinizer ignore-type */ 'cat /proc/meminfo');
Loading history...
30 6
        $process->run();
31
32 6
        if (!$process->isSuccessful()) {
33
            throw new MemoryUsageNotAccessible;
34
        }
35
36 6
        $amounts = (new Str($process->getOutput()))
37 6
            ->trim()
38 6
            ->split("\n")
39
            ->filter(static function(Str $line): bool {
40 6
                return $line->matches(
41 6
                    '~^('.implode('|', array_keys(self::$entries)).'):~'
42
                );
43 6
            })
44 6
            ->reduce(
45 6
                new Map('string', 'int'),
46
                static function(Map $map, Str $line): Map {
47 6
                    $elements = $line->capture('~^(?P<key>[a-zA-Z]+): +(?P<value>\d+) kB$~');
48
49 6
                    return $map->put(
50 6
                        self::$entries[(string) $elements->get('key')],
51 6
                        ((int) (string) $elements->get('value')) * Bytes::BYTES
52
                    );
53 6
                }
54
            );
55
56 6
        $used = $amounts->get('total') - $amounts->get('free');
57 6
        $wired = $used - $amounts->get('active') - $amounts->get('inactive');
58
59 6
        return new Memory(
60 6
            new Bytes($amounts->get('total')),
61 6
            new Bytes($wired),
62 6
            new Bytes($amounts->get('active')),
63 6
            new Bytes($amounts->get('free')),
64 6
            new Bytes($amounts->get('swap')),
65 6
            new Bytes($used)
66
        );
67
    }
68
}
69