Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/currency/PhortuneCurrency.php
| Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | public static function newFromValueAndCurrency($value, $currency) { | ||||
| $obj->value = $value; | $obj->value = $value; | ||||
| $obj->currency = $currency; | $obj->currency = $currency; | ||||
| return $obj; | return $obj; | ||||
| } | } | ||||
| public static function newFromList(array $list) { | public static function newFromList(array $list) { | ||||
| assert_instances_of($list, 'PhortuneCurrency'); | assert_instances_of($list, __CLASS__); | ||||
| if (!$list) { | if (!$list) { | ||||
| return PhortuneCurrency::newEmptyCurrency(); | return self::newEmptyCurrency(); | ||||
| } | } | ||||
| $total = null; | $total = null; | ||||
| foreach ($list as $item) { | foreach ($list as $item) { | ||||
| if ($total === null) { | if ($total === null) { | ||||
| $total = $item; | $total = $item; | ||||
| } else { | } else { | ||||
| $total = $total->add($item); | $total = $total->add($item); | ||||
| ▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | final class PhortuneCurrency extends Phobject { | ||||
| * has the expected sign. | * has the expected sign. | ||||
| * | * | ||||
| * @param string|null Currency string, or null to skip check. | * @param string|null Currency string, or null to skip check. | ||||
| * @param string|null Currency string, or null to skip check. | * @param string|null Currency string, or null to skip check. | ||||
| * @return this | * @return this | ||||
| */ | */ | ||||
| public function assertInRange($minimum, $maximum) { | public function assertInRange($minimum, $maximum) { | ||||
| if ($minimum !== null && $maximum !== null) { | if ($minimum !== null && $maximum !== null) { | ||||
| $min = PhortuneCurrency::newFromString($minimum); | $min = self::newFromString($minimum); | ||||
| $max = PhortuneCurrency::newFromString($maximum); | $max = self::newFromString($maximum); | ||||
| if ($min->value > $max->value) { | if ($min->value > $max->value) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Range (%s - %s) is not valid!', | 'Range (%s - %s) is not valid!', | ||||
| $min->formatForDisplay(), | $min->formatForDisplay(), | ||||
| $max->formatForDisplay())); | $max->formatForDisplay())); | ||||
| } | } | ||||
| } | } | ||||
| if ($minimum !== null) { | if ($minimum !== null) { | ||||
| $min = PhortuneCurrency::newFromString($minimum); | $min = self::newFromString($minimum); | ||||
| if ($min->value > $this->value) { | if ($min->value > $this->value) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Minimum allowed amount is %s.', | 'Minimum allowed amount is %s.', | ||||
| $min->formatForDisplay())); | $min->formatForDisplay())); | ||||
| } | } | ||||
| } | } | ||||
| if ($maximum !== null) { | if ($maximum !== null) { | ||||
| $max = PhortuneCurrency::newFromString($maximum); | $max = self::newFromString($maximum); | ||||
| if ($max->value < $this->value) { | if ($max->value < $this->value) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Maximum allowed amount is %s.', | 'Maximum allowed amount is %s.', | ||||
| $max->formatForDisplay())); | $max->formatForDisplay())); | ||||
| } | } | ||||
| } | } | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| } | } | ||||