feat(SelectQuery): refine Psalm integer types on query bounds#257
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #257 +/- ##
=========================================
Coverage 95.68% 95.68%
Complexity 2038 2038
=========================================
Files 137 137
Lines 5775 5775
=========================================
Hits 5526 5526
Misses 249 249 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
7c66df1 to
b2d4cad
Compare
b2d4cad to
ff647ca
Compare
Express numeric bounds via Psalm types so static analysis flags invalid values at call sites: - runChunks() chunk size as int<1, max> (a non-positive value never advances the offset and spins in an endless loop); - getLimit() / getOffset() as int<0, max>|null; - count() as int<0, max> (a row count is never negative). Also drop the redundant `psalm-` prefix from the existing non-empty-string column/method hints: plain `@param` advanced types are now broadly supported (Psalm, PHPStan, PhpStorm). Return-type refinements only; LessSpecificReturnStatement / MoreSpecificReturnType are already suppressed project-wide, and setter params are left intact to preserve the PaginableInterface contract. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ff647ca to
39d0018
Compare
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.
🔍 What was changed
Refined the Psalm types in
SelectQueryso numeric bounds and string constraints are expressed at the type level.Added integer bounds:
runChunks()@param int<1, max> $limitgetLimit()@return int<0, max>|null>= 0ornull(0disables limiting).getOffset()@return int<0, max>|null>= 0ornull.count()@return int<0, max>Simplified existing hints: dropped the redundant
psalm-prefix from thenon-empty-stringcolumn/method hints oncount(),avg(),max(),min(),sum()andrunAggregate()— plain@paramadvanced types are now broadly supported (Psalm, PHPStan, PhpStorm).Note
Annotation-only — runtime behaviour and public signatures are unchanged.
🤔 Why?
Expressing these bounds as Psalm types lets static analysis catch invalid values at the call site instead of failing (or hanging) at runtime, and gives consumers more precise return types. The endless-loop risk on a non-positive chunk size was surfaced by the Copilot review on #255.
Setter params (
limit()/offset()) are intentionally left as-is: narrowing them would break theSpiral\Pagination\PaginableInterfacecontract (MoreSpecificImplementedParamType). The return-type refinements are safe becauseLessSpecificReturnStatement/MoreSpecificReturnTypeare already suppressed project-wide inpsalm.xml.📝 Checklist
How was this tested:
Verified with
psalm(no new issues introduced) andphp-cs-fixer(clean). No unit tests are added — these are static-analysis annotations with no runtime effect.📃 Documentation
Not needed — type-level annotations, public API signatures unchanged.