Completed
Push — master ( 09ebf6...b9b55a )
by Nicolas
03:13 queued 02:16
created

MemoryContributor::formatBytes()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 11
loc 11
c 0
b 0
f 0
ccs 0
cts 7
cp 0
rs 9.9
cc 2
nc 1
nop 2
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nwidart\Actuator\Health;
6
7
class MemoryContributor implements HealthContributor
8
{
9 1
    public function run(): array
10
    {
11
        return [
12 1
            'free' => $this->getMemoryFree(),
13 1
            'memory' => $this->getMemoryAllocated(),
14
        ];
15
    }
16
17
    /**
18
     * Return the memory free in kbytes
19
     */
20 1
    private function getMemoryFree(): int
21
    {
22 1
        return $this->getMemoryAllocated() - $this->getMemoryUsage();
23
    }
24
25
    /**
26
     * Return the maximum memory allocated to php in kbytes
27
     */
28 1
    private function getMemoryAllocated(): int
29
    {
30 1
        return ((int) ini_get('memory_limit')) * 1024;
31
    }
32
33
    /**
34
     * Return the memory usage in kbytes
35
     */
36 1
    private function getMemoryUsage(): int
37
    {
38 1
        return memory_get_usage(true) / 1024;
39
    }
40
}
41