Skip to content

Normalise currency codes in CurrencyHelper#41

Merged
TomK merged 1 commit into
masterfrom
currency-code-normalisation
Jul 10, 2026
Merged

Normalise currency codes in CurrencyHelper#41
TomK merged 1 commit into
masterfrom
currency-code-normalisation

Conversation

@TomK

@TomK TomK commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary

  • CurrencyHelper::getCurrency() now trims and uppercases the incoming code before building the class name, so lowercase or whitespace-padded input ('usd ', "\tusd\n") resolves the correct currency class — this previously failed on case-sensitive filesystems where PSR-4 autoloading is path-sensitive.
  • The cast is applied outside the ?: fallback so a null code with a null default no longer passes null to trim() (PHP 8.1 deprecation, TypeError in PHP 9) — keeps the guarantees from Guard string functions against null input (PHP 8.1 deprecation) #40 intact.
  • The fallback guard compares against the normalised default, so an invalid code with an identical invalid default throws immediately instead of recursing once.
  • listAllCurrencies() normalises constant values so returned array keys are always canonical.

Test plan

  • Added 5 tests to tests/Currency/CurrencyTest.php covering case/whitespace normalisation, fallback to (lowercase/padded) defaults, and the throw paths for invalid, invalid-with-invalid-default, and null input.
  • Full suite passes: 112 tests, 249 assertions (1 pre-existing unrelated risky test in UnknownTest).
  • Manually exercised getCurrency(null) with error_reporting=E_ALL to confirm it throws cleanly with no string-function warnings.

🤖 Generated with Claude Code

Trim and uppercase codes (and defaults) before lookup so lowercase or
padded input resolves the correct currency class, guarding against the
PHP 8.1 null-to-string deprecation when both code and default are null.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@TomK
TomK merged commit 12a1cf0 into master Jul 10, 2026
1 check passed
@TomK
TomK deleted the currency-code-normalisation branch July 10, 2026 08:53
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