CimLogicalDisk   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 14
dl 0
loc 33
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convertBytes() 0 6 1
A getSize() 0 3 1
A getFreeSpace() 0 3 1
1
<?php
2
3
namespace PhpWinTools\WmiScripting\Cim;
4
5
/**
6
 * @link https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/cim-logicaldisk
7
 */
8
class CimLogicalDisk extends CimStorageExtent
9
{
10
    protected $byte_suffixes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
11
12
    protected $uuid = '{8502C539-5FBB-11D2-AAC1-006008C78BC7}';
13
14
    protected $freeSpace;
15
16
    protected $size;
17
18
    protected $hidden_attributes = ['byte_suffixes'];
19
20
    protected $attribute_casting = [
21
        'freeSpace' => 'int',
22
        'size'      => 'int',
23
    ];
24
25
    public function getFreeSpace(int $decimal_places = 2, array $byte_suffixes = null)
26
    {
27
        return $this->convertBytes($this->getAttribute('freeSpace'), $decimal_places, $byte_suffixes);
28
    }
29
30
    public function getSize(int $decimal_places = 2, array $byte_suffixes = null)
31
    {
32
        return $this->convertBytes($this->getAttribute('size'), $decimal_places, $byte_suffixes);
33
    }
34
35
    protected function convertBytes($bytes, int $decimal_places = 2, array $byte_suffixes = null)
36
    {
37
        $byte_suffixes = $byte_suffixes ?? $this->byte_suffixes;
38
        $factor = floor((strlen($bytes) - 1) / 3);
39
40
        return sprintf("%.{$decimal_places}f", $bytes / pow(1024, $factor)) . ' ' . $byte_suffixes[(int) $factor] ?? '';
41
    }
42
}
43