diff --git a/composer.json b/composer.json index e39bc63..c65b702 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "require": { "php": "^8.3", "ext-json": "*", - "brick/math": "^0.12", + "brick/math": "^0.17", "psr/http-client": "^1.0", "psr/http-factory": "^1.1", "psr/http-message": "^1.1 || ^2.0" diff --git a/composer.lock b/composer.lock index 78c327f..4fc2247 100644 --- a/composer.lock +++ b/composer.lock @@ -4,29 +4,28 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "94f4767d77d28e0fc91f1404d6596ff0", + "content-hash": "95f3afd74682366ea35c09f90373c4d4", "packages": [ { "name": "brick/math", - "version": "0.12.3", + "version": "0.17.1", "source": { "type": "git", "url": "https://github.com/brick/math.git", - "reference": "866551da34e9a618e64a819ee1e01c20d8a588ba" + "reference": "6aef71a9fbbd1ee7be0e313cd627f8e6f7125a5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brick/math/zipball/866551da34e9a618e64a819ee1e01c20d8a588ba", - "reference": "866551da34e9a618e64a819ee1e01c20d8a588ba", + "url": "https://api.github.com/repos/brick/math/zipball/6aef71a9fbbd1ee7be0e313cd627f8e6f7125a5b", + "reference": "6aef71a9fbbd1ee7be0e313cd627f8e6f7125a5b", "shasum": "" }, "require": { - "php": "^8.1" + "php": "^8.2" }, "require-dev": { - "php-coveralls/php-coveralls": "^2.2", - "phpunit/phpunit": "^10.1", - "vimeo/psalm": "6.8.8" + "phpstan/phpstan": "2.1.22", + "phpunit/phpunit": "^11.5" }, "type": "library", "autoload": { @@ -56,7 +55,7 @@ ], "support": { "issues": "https://github.com/brick/math/issues", - "source": "https://github.com/brick/math/tree/0.12.3" + "source": "https://github.com/brick/math/tree/0.17.1" }, "funding": [ { @@ -64,7 +63,7 @@ "type": "github" } ], - "time": "2025-02-28T13:11:00+00:00" + "time": "2026-04-19T20:55:20+00:00" }, { "name": "psr/http-client", diff --git a/src/Drivers/BaseCurrencyDriver.php b/src/Drivers/BaseCurrencyDriver.php index 1a8c32b..e60c242 100644 --- a/src/Drivers/BaseCurrencyDriver.php +++ b/src/Drivers/BaseCurrencyDriver.php @@ -200,7 +200,7 @@ public function convert( $response = $this->apiRequest('convert', $params); $rate = BigDecimal::of($this->responseString($response, 'result', static::class)) - ->dividedBy(BigDecimal::of((string) $this->amount), ConversionResult::DEFAULT_SCALE, RoundingMode::HALF_UP); + ->dividedBy(BigDecimal::of((string) $this->amount), ConversionResult::DEFAULT_SCALE, RoundingMode::HalfUp); return new ConversionResult( $this->getBaseCurrency(), diff --git a/src/Drivers/CurrencyApi.php b/src/Drivers/CurrencyApi.php index e72dd0e..072a2bd 100644 --- a/src/Drivers/CurrencyApi.php +++ b/src/Drivers/CurrencyApi.php @@ -120,7 +120,7 @@ public function convert( } $rate = BigDecimal::of((string) $converted) - ->dividedBy(BigDecimal::of((string) $this->amount), ConversionResult::DEFAULT_SCALE, RoundingMode::HALF_UP); + ->dividedBy(BigDecimal::of((string) $this->amount), ConversionResult::DEFAULT_SCALE, RoundingMode::HalfUp); return new ConversionResult( $this->getBaseCurrency(), diff --git a/src/Drivers/FastForex.php b/src/Drivers/FastForex.php index c693aae..a55d10b 100644 --- a/src/Drivers/FastForex.php +++ b/src/Drivers/FastForex.php @@ -123,7 +123,7 @@ public function convert( } $rate = BigDecimal::of((string) $rates[$target]) - ->dividedBy(BigDecimal::of((string) $this->amount), ConversionResult::DEFAULT_SCALE, RoundingMode::HALF_UP); + ->dividedBy(BigDecimal::of((string) $this->amount), ConversionResult::DEFAULT_SCALE, RoundingMode::HalfUp); return new ConversionResult( $this->optionalResponseString($response, 'base') ?? $this->getBaseCurrency(), diff --git a/src/Results/ConversionResult.php b/src/Results/ConversionResult.php index 2398f7d..2ea31c9 100644 --- a/src/Results/ConversionResult.php +++ b/src/Results/ConversionResult.php @@ -30,6 +30,7 @@ class ConversionResult /** * @param array $rates + * @param int<0, max> $scale * * @throws MathException If a rate value is not a valid numeric. */ @@ -86,7 +87,7 @@ public function setBaseCurrency(string|Currency $baseCurrency): self $rebased = []; foreach ($this->originalConversionRates as $currency => $rate) { - $rebased[$currency] = $rate->dividedBy($divisor, $this->scale, RoundingMode::HALF_UP); + $rebased[$currency] = $rate->dividedBy($divisor, $this->scale, RoundingMode::HalfUp); } $rebased[$code] = BigDecimal::one(); @@ -139,7 +140,7 @@ public function convert( return $this->toBigDecimal($amount) ->multipliedBy($this->originalConversionRates[$to]) - ->dividedBy($this->originalConversionRates[$from], $this->scale, RoundingMode::HALF_UP); + ->dividedBy($this->originalConversionRates[$from], $this->scale, RoundingMode::HalfUp); } /** @@ -168,6 +169,10 @@ public function allAsFloats(): array */ private function toBigDecimal(BigDecimal|float|int|string $value): BigDecimal { + if (is_float($value)) { + return BigDecimal::of((string) $value); + } + return $value instanceof BigDecimal ? $value : BigDecimal::of($value); } }