-
Notifications
You must be signed in to change notification settings - Fork 0
/
Length.php
70 lines (60 loc) · 877 Bytes
/
Length.php
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
<?php
declare(strict_types=1);
namespace UnitConvert;
class Length
{
private float $m;
/**
* From meters (m)
*/
public static function from_m(float $m): self
{
return new static ($m);
}
/**
* From kilometers (km)
*/
public static function from_km(float $km): self
{
return new static ($km * 1000);
}
public function __construct(float $m)
{
$this->m = $m;
}
/**
* To meters (m)
*/
public function to_m(): float
{
return $this->m;
}
/**
* To kilometers (km)
*/
public function to_km(): float
{
return $this->m / 1000;
}
/**
* To inches (")
*/
public function to_inch(): float
{
return $this->m * 39.37007874;
}
/**
* To feet (ft)
*/
public function to_ft(): float
{
return $this->m * 3.280839895;
}
/**
* To miles (mi)
*/
public function to_mi(): float
{
return $this->m * 0.000621371192;
}
}