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

MemoryContributor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 7 1
A getMemoryFree() 0 4 1
A getMemoryAllocated() 0 4 1
A getMemoryUsage() 0 4 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