Skip to content

Conversation

@CodeLieutenant
Copy link

It's really a common case to define currencies as enum, espacially with PHP 8.1, laravel also supports them (both saving and retrieving from the database).

Usecase

// Enums/Currency.php
enum Currency: string {
   case USD = 'USD';
}

// Models/Item.php
class Item extends Model {
   protected function casts(): array {
       return [
           'total' => MoneyDecimalCast::class . ':currency',
           'currency' => Currency::class,
       ];
   }
}

Without this, Money::parseCurrency just returns the enum passed to it and then Money\Money fails with exception, since it require $currency to be either string or Money\Currency

@codecov
Copy link

codecov bot commented Mar 8, 2025

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.79%. Comparing base (fdca65e) to head (20bcac9).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/CurrenciesTrait.php 75.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##                main     #177      +/-   ##
=============================================
- Coverage     100.00%   99.79%   -0.21%     
- Complexity       172      174       +2     
=============================================
  Files             22       22              
  Lines            475      479       +4     
=============================================
+ Hits             475      478       +3     
- Misses             0        1       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@ricardogobbosouza ricardogobbosouza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @CodeLieutenant

Just one thing the coverage complained about.

Thanks for the PR

}

if ($currency instanceof \StringBackedEnum) {
return new Currency($currency->value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is not being covered by the tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants