L38 — Typed validated() array shapes from rules - #294
Open
shuvroroy wants to merge 3 commits into
Open
Conversation
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
validated() array shapes from rules*validated() array shapes from rules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
$request->validated()was declaredarrayand nothing more — no mainstream tool takes it further. The validation rules array is a static type contract, though: it names every key the result can hold and says what each one is. This translates that contract into anarray{…}shape instead of leaving it as barearray.See the commit message for the mechanism (rules→shape translation, optionality rules, the thread-local resolver, the two hook sites). Worth a reviewer's attention:
nullable≠ present. The obvious reading is thatnullableguarantees the key with a possibly-null value. I checked against the real validator:['age' => 'nullable|integer']validated against[]yields[], not['age' => null]. Sonullablealone leaves the key optional (age?: ?int); onlyrequired/presentguarantee it. This is pinned by a runtime assertion inexamples/laravel/assertions.phpso the demo comments can't drift from what Laravel actually does.SubjectExprpath (hover) and the AST/assignment path ($data = …) are genuinely parallel pipelines, and the existingconfigured_laravel_date_returnfeature is hooked into both for the same reason. Same pattern here, not duplication for its own sake.array. A shape that silently drops a real key would flag valid runtime input as an unknown-key diagnostic — worse than no shape at all.rules_in_scope(FormRequest's own rules, else the nearest precedingvalidate()) is factored out of L37's completion path so this feature and L37 share one definition instead of two that could quietly disagree about which rules apply at a given cursor.Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,examples/)config-schema.json) — no new config options