If SwapExchange would return a rate like 0.0000550000
PHP will display as 5.5E-5
thus simply casting to string will result to "5.5E-5"
. Then Converter passes ratio to the Number class which will throw invalid fractional part exception.
Although this issue has been handled in ExchangerExchange by using sprintf
:)
swap exchange use sprintf instead of cast (#744)
Fixes #743
Made it similar to ExchangerExchange
Tag with PHP 8.2 is now available. I also dropped PHP 7.4 support.
drop php 7.4
Merge pull request #8 from genkgo/drop_74
drop php 7.4
Add PHP 8.2 support
Merge pull request #7 from bcremer/add-php82-support
Add PHP 8.2 support
Yes, I am also using that for my PHP packages.
Good idea. Another option is to only support iOS/Mac etc versions that actually receive security updates by Apple. Users that really want support for older operating system versions are then forced to use older versions of the library.
If you would follow this path, this would lead to the following minimal operating system versions.
@morloderex I'd rather not provide an interface for value objects. Then the value object loses its purposes. Money\Exchange
and MoneyConverter
are tied to Money\CurrencyPair
by design. If it does not fit you, you can create own exchanges, converters and currency-pair-alike objects. Or, as I have suggested, have your own exchange and converter next to ours. Per use-case you can decide what to inject Money\Converter
, with limited conversion meta data, or Vendor\Converter
with extended meta data. I do this quite often in my own applications.
If you can make a PR with the sprintf
solution, including a test, would be great.
.sortedKeys requires iOS 11
I disagree.
namespace Vendor;
interface MyExchange {
public function quote(Currency $baseCurrency, Currency $counterCurrency): MyReturnType;
}
final class MyConverter {
public function __construct(private MyExchange $myExchange, private Money\Converter $moneyConverter) {}
/** @return array{0: Money, 1: MyReturnType} */
public function convertAndReturnWithMyReturnType(Money $money, Currency $counterCurrency, int $roundingMode = Money::ROUND_HALF_UP): array
{
$myPair = $this->myExchange->quote(
$money->getCurrency(),
$counterCurrency
);
$moneyCurrencyPair = new CurrencyPair($myPair->getBaseCurrency(), $myPair->getCounterCurrency(), $myPair->getConversionRatio());
return [$this->converter->convertAgainstCurrencyPair($money, $moneyCurrencyPair, $roundingMode), $myPair];
}
}
While I get where you are going with this, I wonder why you must talk to the Exchange
interface defined in this package.
namespace Vendor;
interface Exchange {
public function quote(Currency $baseCurrency, Currency $counterCurrency): MyReturnType;
}
final class MyExchange implements Exchange {
public function __construct(private Money\Exchange $moneyExchange) {}
public function quote(Currency $baseCurrency, Currency $counterCurrency): MyReturnType
{
$currencyPair = $this->moneyExchange->quote($baseCurrency, $counterCurrency);
return $this->convertToOrAddSpecificsAboutMyReturnType($currencyPair);
}
}
@aidantwoods Wonderful, thanks for all your work here!
Hi there,
Given:
$currencies = new \Money\Currencies\ISOCurrencies();
$money = \Money\Money::USD(10); //10 cent
$money->roundToUnit($currencies->subunitFor($money->getCurrency()));
should return \Money\Money::USD(0)
but will throw:
Fatal error: Uncaught InvalidArgumentException: Leading zeros are not allowed in /vendor/moneyphp/money/src/Number.php:216
Stack trace:
#0 /vendor/moneyphp/money/src/Number.php(44): Money\Number::parseIntegerPart('000')
#1 /vendor/moneyphp/money/src/Number.php(53): Money\Number->__construct('000', '')
#2 /vendor/moneyphp/money/src/Money.php(81): Money\Number::fromString('000')
#3 /vendor/moneyphp/money/src/Money.php(410): Money\Money->__construct('000', Object(Money\Currency))
#4 /test.php(10): Money\Money->roundToUnit(2)
#5 {main}
Thanks
Try reproduce bug #740 (#741)