From 0b38cc80059030ac7a36336594303e6201b7c1e7 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 6 Jul 2016 10:49:52 +0200 Subject: [PATCH] Implement OperationInterface --- Localization/Money.php | 62 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/Localization/Money.php b/Localization/Money.php index cd044b73d..794b2fab9 100644 --- a/Localization/Money.php +++ b/Localization/Money.php @@ -15,6 +15,8 @@ */ namespace phpOMS\Localization; +use \phpOMS\Math\Number\OperationInterface; + /** * Money class. * @@ -26,7 +28,7 @@ namespace phpOMS\Localization; * @link http://orange-management.com * @since 1.0.0 */ -class Money implements \Serializable +class Money implements \Serializable, OperationInterface { /** @@ -187,12 +189,12 @@ class Money implements \Serializable * * @param Money|string|int|float $value * - * @return void + * @return Money * * @since 1.0.0 * @author Dennis Eichhorn */ - public function add($value) + public function add($value) : Money { if(is_string($value) || is_float($value)) { $this->value += self::toInt((string) $value, $this->decimal, $this->thousands); @@ -201,6 +203,8 @@ class Money implements \Serializable } elseif($value instanceof Money) { $this->value += $value->getInt(); } + + return $this; } /** @@ -208,12 +212,12 @@ class Money implements \Serializable * * @param Money|string|int|float $value * - * @return void + * @return Money * * @since 1.0.0 * @author Dennis Eichhorn */ - public function sub($value) + public function sub($value) : Money { if(is_string($value) || is_float($value)) { $this->value -= self::toInt((string) $value, $this->decimal, $this->thousands); @@ -222,6 +226,8 @@ class Money implements \Serializable } elseif($value instanceof Money) { $this->value -= $value->getInt(); } + + return $this; } /** @@ -229,16 +235,18 @@ class Money implements \Serializable * * @param int|float $value * - * @return void + * @return Money * * @since 1.0.0 * @author Dennis Eichhorn */ - public function mult($value) + public function mult($value) : Money { if(is_float($value) || is_int($value)) { $this->value *= $value; } + + return $this; } /** @@ -246,16 +254,52 @@ class Money implements \Serializable * * @param int|float $value * - * @return void + * @return Money * * @since 1.0.0 * @author Dennis Eichhorn */ - public function div($value) + public function div($value) : Money { if(is_float($value) || is_int($value)) { $this->value = self::toInt((string) ($this->value / $value), $this->decimal, $this->thousands); } + + return $this; + } + + /** + * Abs. + * + * @return Money + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function abs() : Money + { + $this->value = abs($this->value); + + return $this; + } + + /** + * Power. + * + * @param int|float $value + * + * @return Money + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function pow($value) : Money + { + if(is_float($value) || is_int($value)) { + $this->value = $this->value ** $value; + } + + return $this; } /**