diff --git a/README.md b/README.md index 3f966ee..095ede4 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ We are not fear of criticism, our cats will cheer us up. - [Meter](src/Distance/Meter.php) - [NavyMile](src/Distance/NavyMile.php) - [Parsec](src/Distance/Parsec.php) + - [Currency](src/Currency) - to many to list them all - [Time](src/Time): - [Hour](src/Time/Hour.php) - [Ke](src/Time/Ke.php) @@ -22,7 +23,7 @@ We are not fear of criticism, our cats will cheer us up. - [Svedberg](src/Time/Svedberg.php) - [Speed](src/Speed/Speed.php) - possible every combination of [Distance](src/Distance) and [Time](src/Time) units - + diff --git a/src/Currency/AbstractCurrency.php b/src/Currency/AbstractCurrency.php new file mode 100644 index 0000000..2cd78e0 --- /dev/null +++ b/src/Currency/AbstractCurrency.php @@ -0,0 +1,107 @@ +subUnitQuality = $subUnitQuality; + } elseif (false === empty($quality)) { + $this->subUnitQuality = intval($quality * static::SUBUNIT_TO_UNIT); + } else { + throw new \InvalidArgumentException('quality or subunit quality required'); + } + } + + /** + * @inheritdoc + */ + public function isEqualTo(ValueObjectInterface $compare): bool + { + if (!$compare instanceof AbstractCurrency || !$compare instanceof static::class) { + throw new \InvalidArgumentException('You may compare only same currency'); + } + return $compare->getQuality() == $this->getQuality(); + } + + /** + * @inheritdoc + */ + public function __toString(): string + { + return ($this->subUnitQuality / static::SUBUNIT_TO_UNIT) . ' ' . static::SYMBOL; + } + + /** + * @return string + */ + public function getSubUnitQuality() + { + return $this->subUnitQuality . ' ' . static::SUBUNIT; + } + + /** + * @return string + */ + public function getSymbol() + { + return static::SYMBOL; + } + + /** + * @return string + */ + public function getName() + { + return static::FULL_NAME; + } + + /** + * @return string + */ + public function getSubUnit() + { + return static::SUBUNIT; + } + + /** + * @return float + */ + public function getQuality() + { + return $this->subUnitQuality / static::SUBUNIT_TO_UNIT; + } + + /** + * @return int + */ + public function getSubQuality() + { + return $this->subUnitQuality; + } +} diff --git a/src/Currency/AfghanAfghani.php b/src/Currency/AfghanAfghani.php new file mode 100644 index 0000000..c5bb18d --- /dev/null +++ b/src/Currency/AfghanAfghani.php @@ -0,0 +1,16 @@ +