Uh oh!
There was an error while loading. Please reload this page.
Make file size messages human-readable - #803
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the File validation rule to render size-related placeholders ({limit}, {exactly}) as human-readable values (e.g. 50 MB) instead of raw byte counts, and aligns defaults, tests, and documentation with that behavior.
Changes:
- Format
{limit}/{exactly}placeholders as human-readable sizes inFileHandler. - Update default
Filesize messages to use{limit}/{exactly}directly (no ICU number/plural formatting). - Add regression tests and document the new placeholder behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/Rule/FileHandler.php | Formats size placeholders before they’re passed into error message parameters. |
src/Rule/File.php | Updates default size messages and placeholder documentation to reflect human-readable sizing. |
tests/Rule/FileTest.php | Adds/updates regression cases asserting new human-readable size output. |
docs/guide/en/built-in-rules-file.md | Documents that size placeholders are now human-readable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
4700917 to
3dfc85bCompare79319f6 to
b4e4c86CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
53fb650 to
7d12a71CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
7d12a71 to
f93aa4aCompareUh oh!
There was an error while loading. Please reload this page.
| } | ||
| return match ($unit) { | ||
| 'byte' => 'The size of {property} must be exactly {exactlyValue, number} ' |
There was a problem hiding this comment.
Add new variable {prettyExactly} and use it as default message in rule "The size of {property} must be exactly {prettyExactly}". Then insert the appropriate value in the handler.
This approach simplify code (not need constants with array of messages).
Even better use pretty value for {exactly} and create new {exactlyHuman}. So, it will be:
{exactly}- pretty value{exactlyHuman}- expected exact size as a human-readable string.{exactlyValue}: expected exact size numeric value converted to a human-readable unit.{exactlyUnit}: expected exact size unit identifier. Possible values arebyte,KB,MB,GB,TB,PB.{exactlyBytes}: expected exact size in bytes.
The same is true for new "limit" variables.
There was a problem hiding this comment.
@vjik that won't work for pretty values since units are to be translated as well.
10 Mb -> 10 Мб
2 bytes -> 2 байта
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
Resolves#802.
Summary
Tests
Full vendor/bin/phpunit was also run; it fails only on existing EmailTest DNS-dependent cases for gmail.com and ñandu.cl domains in this environment.