ShipmentStatus.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Model\Shipment;
  6. use Temando\Shipping\Api\Shipment\ShipmentStatusInterface;
  7. /**
  8. * Temando Shipment Status
  9. *
  10. * @package Temando\Shipping\Model
  11. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  12. * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  13. * @link https://www.temando.com/
  14. */
  15. class ShipmentStatus implements ShipmentStatusInterface
  16. {
  17. /**
  18. * Obtain complete list of available shipment status codes
  19. *
  20. * @return int[]
  21. */
  22. private function getStatusMap(): array
  23. {
  24. $statusMap = [
  25. 'pending' => self::STATUS_PENDING,
  26. 'fulfilled' => self::STATUS_FULFILLED,
  27. 'cancelled' => self::STATUS_CANCELLED,
  28. 'completing' => self::STATUS_COMPLETING,
  29. 'completed' => self::STATUS_COMPLETED,
  30. 'error' => self::STATUS_ERROR,
  31. ];
  32. return $statusMap;
  33. }
  34. /**
  35. * Obtain human readable representation of shipment status.
  36. *
  37. * @param int $statusCode
  38. * @return string
  39. */
  40. public function getStatusText(int $statusCode): string
  41. {
  42. $statusMap = $this->getStatusMap();
  43. $statusMap = array_flip($statusMap);
  44. if (!isset($statusMap[$statusCode])) {
  45. return '';
  46. }
  47. return $statusMap[$statusCode];
  48. }
  49. /**
  50. * Obtain numeric representation of shipment status.
  51. *
  52. * @param string $status
  53. * @return int
  54. */
  55. public function getStatusCode(string $status): int
  56. {
  57. $statusMap = $this->getStatusMap();
  58. if (!isset($statusMap[$status])) {
  59. return 0;
  60. }
  61. return $statusMap[$status];
  62. }
  63. }