Skip to content

Make file size messages human-readable - #803

Open
samdark wants to merge 2 commits into
masterfrom
issue-802-file-size-messages
Open

Make file size messages human-readable#803
samdark wants to merge 2 commits into
masterfrom
issue-802-file-size-messages

Conversation

@samdark

Copy link
Copy Markdown
Member

Resolves#802.

Summary

  • Format File size placeholders as human-readable values for {limit} and {exactly}.
  • Update default File size messages to use the formatted placeholders directly.
  • Add regression coverage and document the placeholder behavior.

Tests

  • vendor/bin/phpunit tests/Rule/FileTest.php --testdox
  • vendor/bin/psalm --config=psalm.xml --output-format=console --no-cache --threads=1
  • vendor/bin/php-cs-fixer fix --dry-run --diff --sequential --allow-unsupported-php-version=yes

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.

CopilotAI review requested due to automatic review settings June 4, 2026 19:00

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 in FileHandler.
  • Update default File size 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.

FileDescription
src/Rule/FileHandler.phpFormats size placeholders before they’re passed into error message parameters.
src/Rule/File.phpUpdates default size messages and placeholder documentation to reflect human-readable sizing.
tests/Rule/FileTest.phpAdds/updates regression cases asserting new human-readable size output.
docs/guide/en/built-in-rules-file.mdDocuments that size placeholders are now human-readable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/Rule/FileHandler.php Outdated
Comment threadsrc/Rule/FileHandler.php
Comment threadsrc/Rule/File.php
Comment threadsrc/Rule/File.php
Comment threaddocs/guide/en/built-in-rules-file.md Outdated
Comment threadtests/Rule/FileTest.php
@samdark
samdarkforce-pushed the issue-802-file-size-messages branch from 4700917 to 3dfc85bCompareJune 4, 2026 19:16
@samdark
samdark requested a review from CopilotJune 4, 2026 19:57
@samdark
samdarkforce-pushed the issue-802-file-size-messages branch 2 times, most recently from 79319f6 to b4e4c86CompareJune 4, 2026 20:00

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment threadsrc/Rule/FileHandler.php Outdated
Comment threadsrc/Rule/File.php Outdated
Comment threadCHANGELOG.md Outdated
@samdark
samdarkforce-pushed the issue-802-file-size-messages branch 5 times, most recently from 53fb650 to 7d12a71CompareJune 4, 2026 21:41
@samdark
samdark requested review from a team and CopilotJune 4, 2026 22:06

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment threadtests/Rule/FileTest.php Outdated
Comment threadsrc/Rule/FileHandler.php
@samdark
samdarkforce-pushed the issue-802-file-size-messages branch from 7d12a71 to f93aa4aCompareJune 5, 2026 20:38
Comment threadCHANGELOG.md Outdated
}

return match ($unit) {
'byte' => 'The size of {property} must be exactly {exactlyValue, number} '

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 are byte, KB, MB, GB, TB, PB.
  • {exactlyBytes}: expected exact size in bytes.

The same is true for new "limit" variables.

@samdarksamdarkJun 7, 2026

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

@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>
Sign up for freeto 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.

Make File size validation messages human-readable

3 participants

@samdark@vjik