| 1 |
<?php |
| 2 |
declare(strict_types = 1); |
| 3 |
|
| 4 |
namespace DASPRiD\EnumTest; |
| 5 |
|
| 6 |
use DASPRiD\Enum\AbstractEnum; |
| 7 |
|
| 8 |
/** |
| 9 |
* @method static self MERCURY() |
| 10 |
* @method static self VENUS() |
| 11 |
* @method static self EARTH() |
| 12 |
* @method static self MARS() |
| 13 |
* @method static self JUPITER() |
| 14 |
* @method static self SATURN() |
| 15 |
* @method static self URANUS() |
| 16 |
* @method static self NEPTUNE() |
| 17 |
*/ |
| 18 |
final class Planet extends AbstractEnum |
| 19 |
{ |
| 20 |
protected const MERCURY = [3.303e+23, 2.4397e6]; |
| 21 |
protected const VENUS = [4.869e+24, 6.0518e6]; |
| 22 |
protected const EARTH = [5.976e+24, 6.37814e6]; |
| 23 |
protected const MARS = [6.421e+23, 3.3972e6]; |
| 24 |
protected const JUPITER = [1.9e+27, 7.1492e7]; |
| 25 |
protected const SATURN = [5.688e+26, 6.0268e7]; |
| 26 |
protected const URANUS = [8.686e+25, 2.5559e7]; |
| 27 |
protected const NEPTUNE = [1.024e+26, 2.4746e7]; |
| 28 |
|
| 29 |
/** |
| 30 |
* Universal gravitational constant. |
| 31 |
*/ |
| 32 |
private const G = 6.67300E-11; |
| 33 |
|
| 34 |
/** |
| 35 |
* Mass in kilograms. |
| 36 |
* |
| 37 |
* @var float |
| 38 |
*/ |
| 39 |
private $mass; |
| 40 |
|
| 41 |
/** |
| 42 |
* Radius in meters. |
| 43 |
* |
| 44 |
* @var float |
| 45 |
*/ |
| 46 |
private $radius; |
| 47 |
|
| 48 |
protected function __construct(float $mass, float $radius) |
| 49 |
{ |
| 50 |
$this->mass = $mass; |
| 51 |
$this->radius = $radius; |
| 52 |
} |
| 53 |
|
| 54 |
public function mass() : float |
| 55 |
{ |
| 56 |
return $this->mass; |
| 57 |
} |
| 58 |
|
| 59 |
public function radius() : float |
| 60 |
{ |
| 61 |
return $this->radius; |
| 62 |
} |
| 63 |
|
| 64 |
public function surfaceGravity() : float |
| 65 |
{ |
| 66 |
return self::G * $this->mass / ($this->radius * $this->radius); |
| 67 |
} |
| 68 |
|
| 69 |
public function surfaceWeight(float $otherMass) : float |
| 70 |
{ |
| 71 |
return $otherMass * $this->surfaceGravity(); |
| 72 |
} |
| 73 |
} |