vendor/moneyphp/money/src/Currency.php line 86

Open in your IDE?
  1. <?php
  2. namespace Money;
  3. /**
  4.  * Currency Value Object.
  5.  *
  6.  * Holds Currency specific data.
  7.  *
  8.  * @author Mathias Verraes
  9.  *
  10.  * @psalm-immutable
  11.  */
  12. final class Currency implements \JsonSerializable
  13. {
  14.     /**
  15.      * Currency code.
  16.      *
  17.      * @var string
  18.      */
  19.     private $code;
  20.     /**
  21.      * @param string $code
  22.      */
  23.     public function __construct($code)
  24.     {
  25.         if (!is_string($code)) {
  26.             throw new \InvalidArgumentException('Currency code should be string');
  27.         }
  28.         if ($code === '') {
  29.             throw new \InvalidArgumentException('Currency code should not be empty string');
  30.         }
  31.         $this->code $code;
  32.     }
  33.     /**
  34.      * Returns the currency code.
  35.      *
  36.      * @return string
  37.      */
  38.     public function getCode()
  39.     {
  40.         return $this->code;
  41.     }
  42.     /**
  43.      * Checks whether this currency is the same as an other.
  44.      *
  45.      * @param Currency $other
  46.      *
  47.      * @return bool
  48.      */
  49.     public function equals(Currency $other)
  50.     {
  51.         return $this->code === $other->code;
  52.     }
  53.     /**
  54.      * Checks whether this currency is available in the passed context.
  55.      *
  56.      * @param Currencies $currencies
  57.      *
  58.      * @return bool
  59.      */
  60.     public function isAvailableWithin(Currencies $currencies)
  61.     {
  62.         return $currencies->contains($this);
  63.     }
  64.     /**
  65.      * @return string
  66.      */
  67.     public function __toString()
  68.     {
  69.         return $this->code;
  70.     }
  71.     /**
  72.      * {@inheritdoc}
  73.      *
  74.      * @return string
  75.      */
  76.     public function jsonSerialize()
  77.     {
  78.         return $this->code;
  79.     }
  80. }