MemoryContributor::getMemoryFree()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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
nc 1
nop 0
crap 1
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