DiskStatsService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDiskStats() 0 19 3
1
<?php
2
3
namespace App\Service;
4
5
use Exception;
6
7
class DiskStatsService {
8
    /**
9
     * @return array<String, float>
10
     */
11
    public function getDiskStats(string $directory): array
12
    {
13
        $disk = [];
14
15
        $free = disk_free_space($directory);
16
        if ($free === false) {
17
            throw new Exception("Couldn't discover free disk space");
18
        }
19
20
        $total = disk_total_space($directory);
21
        if ($total === false) {
22
            throw new Exception("Couldn't discover free disk total space");
23
        }
24
25
        $disk['free'] = $free;
26
        $disk['total'] = $total;
27
        $disk['used'] = $disk['total'] - $disk['free'];
28
        $disk['percent'] = $disk['used'] / $disk['total'];
29
        return $disk;
30
    }
31
}
32