Skip to content

Fix File::types() discarding prior chain configuration#59587

Closed
vashukarn wants to merge 1 commit intolaravel:13.xfrom
vashukarn:fix/file-rule-types-chain
Closed

Fix File::types() discarding prior chain configuration#59587
vashukarn wants to merge 1 commit intolaravel:13.xfrom
vashukarn:fix/file-rule-types-chain

Conversation

@vashukarn
Copy link
Copy Markdown

@vashukarn vashukarn commented Apr 8, 2026

Summary

Fixes #59242. File::types() was a static factory returning new static(), so calling it fluently after image()/max() (e.g. File::image()->max(1)->types(['jpg'])) silently dropped all prior constraints with no warning.

This routes both static and instance calls to types() through __call/__callStatic, delegating to a protected applyTypes() setter:

  • File::types([...]) — still works (BC preserved), now via __callStatic.
  • File::image()->max(1)->types([...]) — now mutates the existing instance instead of throwing away configuration.

Macroable's magic methods are aliased so existing macro support is unaffected. @method annotations are added so IDEs and static analysis still recognize both forms.

Test plan

  • New regression test: File::image()->max(1)->types(['jpg', 'jpeg']) correctly fails on an oversized image.
  • New positive chain test: same chain passes when the file is within max.
  • New BC test: File::types(['png']) static form still works.
  • Full test suite green (13345 tests).

When called as an instance method (e.g. File::image()->max(1)->types([...])),
types() was a static factory that silently constructed a fresh instance,
dropping any previously chained constraints. Route both static and instance
calls through magic methods so chaining mutates the existing instance while
preserving the documented File::types(...) factory entry point.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@vashukarn vashukarn marked this pull request as ready for review April 8, 2026 06:08
@vashukarn vashukarn deleted the fix/file-rule-types-chain branch April 8, 2026 13:30
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.

File::types() silently discards prior chain configuration when called as instance method

2 participants