diff --git a/src/Casts/MoneyCast.php b/src/Casts/MoneyCast.php index 7838d7e..76f79d7 100644 --- a/src/Casts/MoneyCast.php +++ b/src/Casts/MoneyCast.php @@ -27,7 +27,7 @@ abstract class MoneyCast implements CastsAttributes * * @param mixed $forceDecimals */ - public function __construct(string $currency = null, $forceDecimals = null) + public function __construct(?string $currency = null, $forceDecimals = null) { $this->currency = $currency; $this->forceDecimals = is_string($forceDecimals) diff --git a/src/Formatters/CurrencySymbolMoneyFormatter.php b/src/Formatters/CurrencySymbolMoneyFormatter.php index f0a086a..ad19937 100644 --- a/src/Formatters/CurrencySymbolMoneyFormatter.php +++ b/src/Formatters/CurrencySymbolMoneyFormatter.php @@ -31,7 +31,7 @@ class CurrencySymbolMoneyFormatter implements MoneyFormatter * @param bool $right * @param string|null $locale */ - public function __construct($right = false, $locale = null, Currencies $currencies = null) + public function __construct($right = false, $locale = null, ?Currencies $currencies = null) { $this->right = $right; $this->locale = $locale ?: Money::getLocale(); diff --git a/src/Money.php b/src/Money.php index 810bd0b..10470a5 100644 --- a/src/Money.php +++ b/src/Money.php @@ -7,7 +7,6 @@ use Illuminate\Contracts\Support\Jsonable; use Illuminate\Support\Traits\Macroable; use JsonSerializable; -use ReflectionMethod; /** * Money. @@ -41,16 +40,16 @@ class Money implements Arrayable, Jsonable, JsonSerializable { use CurrenciesTrait; use LocaleTrait; + use Macroable { + Macroable::__call as macroCall; + Macroable::__callStatic as macroCallStatic; + } use MoneyFactory { MoneyFactory::__callStatic as factoryCallStatic; } use MoneyFormatterTrait; - use MoneySerializerTrait; use MoneyParserTrait; - use Macroable { - Macroable::__call as macroCall; - Macroable::__callStatic as macroCallStatic; - } + use MoneySerializerTrait; /** * @var \Money\Money @@ -281,41 +280,4 @@ private static function convertResult($result) return $results; } - - /** - * Resolve calculator. - * - * @return \Money\Calculator - * - * @throws \RuntimeException - */ - private static function resolveCalculator() - { - $reflection = new ReflectionMethod(\Money\Money::class, 'getCalculator'); - - if ($reflection->isPublic()) { - $calculator = call_user_func([\Money\Money::class, 'getCalculator']); - - return new $calculator(); - } - - $calculators = [ - \Money\Calculator\BcMathCalculator::class, - \Money\Calculator\GmpCalculator::class, - \Money\Calculator\PhpCalculator::class, - ]; - - foreach ($calculators as $calculator) { - if (! class_exists($calculator)) { - continue; - } - - /** @var Calculator $calculator */ - if ($calculator::supported()) { - return new $calculator(); - } - } - - throw new \RuntimeException('Cannot find calculator for money calculations'); - } } diff --git a/src/MoneyFormatterTrait.php b/src/MoneyFormatterTrait.php index 1f09f95..19c6d16 100644 --- a/src/MoneyFormatterTrait.php +++ b/src/MoneyFormatterTrait.php @@ -25,7 +25,7 @@ trait MoneyFormatterTrait * * @throws \InvalidArgumentException */ - public function format($locale = null, Currencies $currencies = null, $style = NumberFormatter::CURRENCY) + public function format($locale = null, ?Currencies $currencies = null, $style = NumberFormatter::CURRENCY) { $defaultFormatter = config('money.defaultFormatter'); @@ -69,7 +69,7 @@ public function formatByAggregate(array $formatters) * @param int $fractionDigits * @return string */ - public function formatByBitcoin($fractionDigits = 2, Currencies $currencies = null) + public function formatByBitcoin($fractionDigits = 2, ?Currencies $currencies = null) { $formatter = new BitcoinMoneyFormatter($fractionDigits, $currencies ?: new BitcoinCurrencies()); @@ -81,10 +81,9 @@ public function formatByBitcoin($fractionDigits = 2, Currencies $currencies = nu * * @param bool $right * @param string|null $locale - * @param \Money\Currencies $currencies * @return string */ - public function formatByCurrencySymbol($right = false, $locale = null, Currencies $currencies = null) + public function formatByCurrencySymbol($right = false, $locale = null, ?Currencies $currencies = null) { $formatter = new CurrencySymbolMoneyFormatter($right, $locale ?: static::getLocale(), $currencies ?: static::getCurrencies()); @@ -96,7 +95,7 @@ public function formatByCurrencySymbol($right = false, $locale = null, Currencie * * @return string */ - public function formatByDecimal(Currencies $currencies = null) + public function formatByDecimal(?Currencies $currencies = null) { $formatter = new DecimalMoneyFormatter($currencies ?: static::getCurrencies()); @@ -110,7 +109,7 @@ public function formatByDecimal(Currencies $currencies = null) * @param int $style * @return string */ - public function formatByIntl($locale = null, Currencies $currencies = null, $style = NumberFormatter::CURRENCY) + public function formatByIntl($locale = null, ?Currencies $currencies = null, $style = NumberFormatter::CURRENCY) { $numberFormatter = new NumberFormatter($locale ?: static::getLocale(), $style); $formatter = new IntlMoneyFormatter($numberFormatter, $currencies ?: static::getCurrencies()); @@ -127,7 +126,7 @@ public function formatByIntl($locale = null, Currencies $currencies = null, $sty */ public function formatByIntlLocalizedDecimal( $locale = null, - Currencies $currencies = null, + ?Currencies $currencies = null, $style = NumberFormatter::CURRENCY ) { $numberFormatter = new NumberFormatter($locale ?: static::getLocale(), $style); diff --git a/src/MoneyParserTrait.php b/src/MoneyParserTrait.php index d1f6fee..4bf8e80 100644 --- a/src/MoneyParserTrait.php +++ b/src/MoneyParserTrait.php @@ -156,7 +156,7 @@ public static function parseByBitcoin( public static function parseByDecimal( $money, $fallbackCurrency = null, - Currencies $currencies = null, + ?Currencies $currencies = null, $convert = true ) { $parser = new DecimalMoneyParser($currencies ?: static::getCurrencies()); @@ -178,7 +178,7 @@ public static function parseByIntl( $money, $fallbackCurrency = null, $locale = null, - Currencies $currencies = null, + ?Currencies $currencies = null, $style = null, $convert = true ) { @@ -206,7 +206,7 @@ public static function parseByIntlLocalizedDecimal( $money, $fallbackCurrency = null, $locale = null, - Currencies $currencies = null, + ?Currencies $currencies = null, $style = null, $convert = true ) { diff --git a/src/MoneySerializerTrait.php b/src/MoneySerializerTrait.php index ced876f..cbb22ef 100644 --- a/src/MoneySerializerTrait.php +++ b/src/MoneySerializerTrait.php @@ -57,7 +57,6 @@ public function serializeByArray() /** * Serialize by serializer. * - * @param \Cknow\Money\MoneySerializer $serializer * @return mixed */ public function serializeBySerializer(MoneySerializer $serializer) diff --git a/src/helpers.php b/src/helpers.php index 7bf3b3d..de7d557 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -151,14 +151,13 @@ function money_parse_by_bitcoin( * * @param string $money * @param \Money\Currency|string|null $fallbackCurrency - * @param \Money\Currencies|null $currencies * @param bool $convert * @return \Cknow\Money\Money|\Money\Money */ function money_parse_by_decimal( $money, $fallbackCurrency = null, - Money\Currencies $currencies = null, + ?Money\Currencies $currencies = null, $convert = true ) { return Cknow\Money\Money::parseByDecimal( @@ -177,7 +176,6 @@ function money_parse_by_decimal( * @param string $money * @param \Money\Currency|string|null $fallbackCurrency * @param string|null $locale - * @param \Money\Currencies|null $currencies * @param int|null $style * @param bool $convert * @return \Cknow\Money\Money|\Money\Money @@ -186,7 +184,7 @@ function money_parse_by_intl( $money, $fallbackCurrency = null, $locale = null, - Money\Currencies $currencies = null, + ?Money\Currencies $currencies = null, $style = null, $convert = true ) { @@ -208,7 +206,6 @@ function money_parse_by_intl( * @param string $money * @param \Money\Currency|string|null $fallbackCurrency * @param string|null $locale - * @param \Money\Currencies|null $currencies * @param int|null $style * @param bool $convert * @return \Cknow\Money\Money|\Money\Money @@ -217,7 +214,7 @@ function money_parse_by_intl_localized_decimal( $money, $fallbackCurrency = null, $locale = null, - Money\Currencies $currencies = null, + ?Money\Currencies $currencies = null, $style = null, $convert = true ) { diff --git a/tests/TestCase.php b/tests/TestCase.php index 0512238..22b9d56 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,7 +11,6 @@ abstract class TestCase extends AbstractPackageTestCase * Setup the application environment. * * @param \Illuminate\Contracts\Foundation\Application $app - * @return void */ protected function getEnvironmentSetUp($app): void { @@ -22,8 +21,6 @@ protected function getEnvironmentSetUp($app): void /** * Get the service provider class. - * - * @return string */ protected static function getServiceProviderClass(): string {