-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitTransferRateUnit.php
More file actions
71 lines (63 loc) · 2.12 KB
/
BitTransferRateUnit.php
File metadata and controls
71 lines (63 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
namespace Andante\Measurement\Unit\Digital\SI;
use Andante\Measurement\Contract\DimensionInterface;
use Andante\Measurement\Contract\UnitInterface;
use Andante\Measurement\Dimension\DataTransferRate;
use Andante\Measurement\Unit\SymbolNotation;
use Andante\Measurement\Unit\UnitSystem;
/**
* SI (decimal) Bit-based Data Transfer Rate units.
*
* Used for network speeds and data transfer measurements.
* 1 kbps = 1000 bps (decimal prefix)
*
* Supports multiple notations:
* - Default: "Gbps", "Mbps", etc. (most common)
* - IEEE: "Gbit/s", "Mbit/s", etc. (standards-compliant)
*/
enum BitTransferRateUnit implements UnitInterface
{
case BitPerSecond;
case KilobitPerSecond;
case MegabitPerSecond;
case GigabitPerSecond;
public function symbol(SymbolNotation $notation = SymbolNotation::Default): string
{
return match ($this) {
self::BitPerSecond => match ($notation) {
SymbolNotation::IEEE, SymbolNotation::Unicode => 'bit/s',
default => 'bps',
},
self::KilobitPerSecond => match ($notation) {
SymbolNotation::IEEE, SymbolNotation::Unicode => 'kbit/s',
default => 'kbps',
},
self::MegabitPerSecond => match ($notation) {
SymbolNotation::IEEE, SymbolNotation::Unicode => 'Mbit/s',
default => 'Mbps',
},
self::GigabitPerSecond => match ($notation) {
SymbolNotation::IEEE, SymbolNotation::Unicode => 'Gbit/s',
default => 'Gbps',
},
};
}
public function name(): string
{
return match ($this) {
self::BitPerSecond => 'bit per second',
self::KilobitPerSecond => 'kilobit per second',
self::MegabitPerSecond => 'megabit per second',
self::GigabitPerSecond => 'gigabit per second',
};
}
public function dimension(): DimensionInterface
{
return DataTransferRate::instance();
}
public function system(): UnitSystem
{
return UnitSystem::SI;
}
}