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
Branch develop (9ca8cc)
by Baptiste
03:18
created

Bytes::toInt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Server\Status\Server\Memory;
5
6
use Innmind\Server\Status\Exception\BytesCannotBeNegative;
7
8
final class Bytes
9
{
10
    private const BYTES = 1024;
11
    private const KILOBYTES = 1024 ** 2;
12
    private const MEGABYTES = 1024 ** 3;
13
    private const GIGABYTES = 1024 ** 4;
14
    private const TERABYTES = 1024 ** 5;
15
    private const PETABYTES = 1024 ** 6;
16
17
    private $value;
18
    private $string;
19
20 15
    public function __construct(int $value)
21
    {
22 15
        if ($value < 0) {
23 1
            throw new BytesCannotBeNegative;
24
        }
25
26 14
        $this->value = $value;
27
28
        switch (true) {
29 14
            case $value < self::BYTES:
30 4
                $this->string = $value.'B';
31 4
                break;
32
33 10
            case $value < self::KILOBYTES:
34 2
                $this->string = sprintf(
35 2
                    '%sKB',
36 2
                    round($value/self::BYTES, 3)
37
                );
38 2
                break;
39
40 8
            case $value < self::MEGABYTES:
41 2
                $this->string = sprintf(
42 2
                    '%sMB',
43 2
                    round($value/self::KILOBYTES, 3)
44
                );
45 2
                break;
46
47 6
            case $value < self::GIGABYTES:
48 2
                $this->string = sprintf(
49 2
                    '%sGB',
50 2
                    round($value/self::MEGABYTES, 3)
51
                );
52 2
                break;
53
54 4
            case $value < self::TERABYTES:
55 2
                $this->string = sprintf(
56 2
                    '%sTB',
57 2
                    round($value/self::GIGABYTES, 3)
58
                );
59 2
                break;
60
61 2
            case $value < self::PETABYTES:
62 2
                $this->string = sprintf(
63 2
                    '%sPB',
64 2
                    round($value/self::TERABYTES, 3)
65
                );
66 2
                break;
67
        }
68 14
    }
69
70 12
    public function toInt(): int
71
    {
72 12
        return $this->value;
73
    }
74
75 12
    public function __toString(): string
76
    {
77 12
        return $this->string;
78
    }
79
}
80