Planet.php 1.6 KB

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