Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rules currency and money #119

Merged
merged 3 commits into from
May 20, 2022
Merged

Add rules currency and money #119

merged 3 commits into from
May 20, 2022

Conversation

ricardogobbosouza
Copy link
Member

@ricardogobbosouza ricardogobbosouza commented May 3, 2022

Resolve #49

Rules

Below is a list of all available validation rules and their function:

currency

The field under validation must be a valid currency.

Validator::make([
  'currency1' => 'USD',
  'currency2' => 'EUR',
  'currency3' => new \Money\Currency('BRL'),
], [
  'currency1' => new \Cknow\Money\Rules\Currency(),
  'currency2' => new \Cknow\Money\Rules\Currency(),
  'currency3' => 'currency',
]);

money

The field under validation must be a valid money.

Validator::make([
  'money1' => '$10.00'
  'money2' => '€10.00',
  'money3' => 'R$10,00',
  'money4' => '$10.00'
  'money5' => '€10.00',
  'money6' => 'R$10,00',
], [
  'money1' => new \Cknow\Money\Rules\Money(),
  'money2' => new \Cknow\Money\Rules\Money('EUR'), // forcing currency
  'money3' => new \Cknow\Money\Rules\Money('BRL', 'pt_BR'), // forcing currency and locale
  'money4' => 'money',
  'money5' => 'money:EUR', // forcing currency
  'money6' => 'money:BRL,pt_BR', // forcing currency and locale
]);

@codecov
Copy link

codecov bot commented May 3, 2022

Codecov Report

Merging #119 (50f4d3d) into main (d37ceea) will not change coverage.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##                main      #119   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       132       142   +10     
===========================================
  Files             14        16    +2     
  Lines            291       325   +34     
===========================================
+ Hits             291       325   +34     
Impacted Files Coverage Δ
src/MoneyServiceProvider.php 100.00% <100.00%> (ø)
src/Rules/Currency.php 100.00% <100.00%> (ø)
src/Rules/Money.php 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d37ceea...50f4d3d. Read the comment docs.

@ricardogobbosouza ricardogobbosouza merged commit 93aa13d into main May 20, 2022
@ricardogobbosouza ricardogobbosouza deleted the feat-rules branch May 20, 2022 12:52
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.

Validation rule for ISO currencies
1 participant