WindDirection.php 939 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Yr\Forecast\Tabular\Time;
  3. /**
  4. * Wind direction
  5. *
  6. * @author Joachim M. Giæver (joachim[]giaever.org)
  7. */
  8. class WindDirection extends AbstractUnit{
  9. const DEFAULT_VARIANCE = 22.5;
  10. private $name;
  11. /**
  12. * @param \SimpleXMLElement $xml XML element containing the wind direction
  13. */
  14. public function __construct(\SimpleXMLElement $xml) {
  15. parent::__construct(
  16. (float)$xml['deg'],
  17. (string)$xml['code']
  18. );
  19. $this->name = (string)$xml['name'];
  20. }
  21. /**
  22. * Returns the wind direction in full,
  23. * e.g «Northeast».
  24. *
  25. * @return string
  26. */
  27. public function getName(): string {
  28. return $this->name;
  29. }
  30. /**
  31. * {@inheritDoc}
  32. */
  33. public function diff(DiffInterface $d): int {
  34. if ($diff = parent::diff($d))
  35. return $diff > static::DEFAULT_VARIANCE ? 1 : 0;
  36. return 0;
  37. }
  38. }