2017-10-12
@used-by dfp_currency()
@param object|string $m
@return self
516817
final static function f($m) {return dfcf(function(M $m) { /** @var self $i */
		$i = df_new(df_con_heir($m, __CLASS__)); $i->_m = $m; return $i;
	}, [dfpm($m)]);}
220496
public function it_returns_the_default_currency()
    {
        $currency = new Currency('XXX', 2);

        $this->setDefaultCurrency($currency);

        $this->getDefaultCurrency()->shouldReturn($currency);
    }
986136
public function currency($currency = null) {
        $currency = $currency == null ? $this->currency : $currency;
        return $this->getWord($this->number) . ' ' . $currency;
    }
596733
public static function getBySymbol(string $symbol): CurrencyCollection
    {
        $currencies = Currency::get();

        /** @var CurrencyCollection $currencies */
        $currencies = $currencies->where("symbol", $symbol);
        return new CurrencyCollection($currencies->elements());
    }
1201016
public function fromFloat($amount, $currency = null)
    {
        if ($currency) {
            $this->setCurrency($currency);
        }

        if (!is_float($amount)) {
            throw new InvalidArgumentException(sprintf(
                'Amount must be a float, %s given',
                gettype($amount)
            ));
        }
        
        $this->amount = $this->toInt(
            round(
                $this->getSubUnit() * round($amount, $this->getFractionDigits(), PHP_ROUND_HALF_UP),
                0,
                PHP_ROUND_HALF_UP
            )
        );
        return $this;
    }
877840
public function convertAndFormat($money, $language = null, $currency = null)
    {
        if (!$currency) {
            $currency = $this->currencyCode;
        }

        $convertedMoney = $money->convertToCurrency($currency);

        return $this->intlFormatter($language)->format($convertedMoney);
    }
1056891
public function add(Money $money)
    {
        if (!$this->currency->equals($money->getCurrency())) {
            throw new CurrencyMismatchException($this.' does not match '.$money);
        }

        $amount = bcadd($this->amount, $money->getAmount(), self::BCSCALE);

        return self::valueOf($amount, $this->currency);
    }
797984
protected function getCurrency()
    {
        if (null === $this->currency) {
            $this->currency = $this->getSession() ? $this->getSession()->getCurrency(true) : Currency::getDefaultCurrency();
        }

        return $this->currency;
    }
1237343
static function s($m) {
		/**
		 * 2018-02-06
		 * $m->getInfoInstance() fixes the issue:
		 * «iPay88 showed "not yet paid" on admin backend.
		 * However, according to record from iPay88 those orders were "successful paid" payment»
		 * https://github.com/mage2pro/ipay88/issues/9
		 */
		return dfcf(function(M $m) {return new self($m);}, [$m = dfpm($m), $m->getInfoInstance()]);
	}
325751
public function subtract(self $subtrahend)
    {
        $this->assertSameCurrency($subtrahend);

        return new self($this->amount - $subtrahend->amount, $this->currency);
    }
205664
public static function fromInt(int $value, string $currency) : Price
    {
        return new self($value * self::DEFAULT_PRECISION, $currency);
    }
72529
final static function sn(M $m) {return dfcf(function(M $m) {return df_new(
		df_con_heir($m, __CLASS__), $m
	);}, [$m]);}
1329257
public static function getCurrencyBundle()
    {
        @trigger_error(sprintf('The method "%s()" is deprecated since Symfony 4.3, use "%s" instead.', __METHOD__, Currencies::class), E_USER_DEPRECATED);

        if (null === self::$currencyBundle) {
            self::$currencyBundle = new CurrencyBundle(
                self::getDataDirectory().'/'.self::CURRENCY_DIR,
                self::getEntryReader(),
                self::$localeBundle ?? self::$localeBundle = new LocaleBundle(self::getDataDirectory().'/'.self::LOCALE_DIR, self::getEntryReader())
            );
        }

        return self::$currencyBundle;
    }
125234
final static function s($m, C $c) {return dfcf(function($m, C $c) {
		/**
		 * 2017-07-19
		 * Unable to reduce the implementation to:
		 * 		df_new(df_con_hier($m, self::class), $c);
		 * because @uses __construct() is protected.
		 * It is similar to @see \Df\Payment\Facade::s()
		 * https://github.com/mage2pro/core/blob/2.8.25/Payment/Facade.php#L75-L87
		 */
		$class = df_con_hier($m, self::class); /** @var string $class */
		return new $class($c);
	}, func_get_args());}
147105
static function withOrderNumberAmountAndCurrency($orderNumber, $amount, $currency)
    {
        return (new static())
            ->setOrderNumber($orderNumber)
            ->setAmount($amount)
            ->setCurrency($currency)
            ;
    }
1228256
public function subtract(Money $money)
    {
        if (!$this->currency->equals($money->getCurrency())) {
            throw new CurrencyMismatchException($this.' does not match '.$money);
        }

        $amount = bcsub($this->amount, $money->getAmount(), self::BCSCALE);

        return self::valueOf($amount, $this->currency);
    }
280044
public function subtract(Money $other)
    {
        $other = $other->convertToCurrency($this->currency);
        $this->assertSameCurrency($this, $other);

        $value = $this->amount - $other->getAmount();

        $this->assertIsFloat($value);

        return $this->newMoney($value);
    }