Repository navigation
Declare that __call returns static - #19
Merged
Merged
Conversation
Every clause method (select, from, where, ...) goes through __call, which always ends with `return $this`, but it had no return type. Static analysis therefore treated each chained call as returning mixed, so a chain like `$q->select(...)->from(...)` lost its type after the first call and every method called on the result was unchecked. A native `: static` return type fixes that and is enforced at runtime. The package already requires PHP 8.2, and `static` has existed since 8.0. At a call site Psalm resolves `static` to the caller's class, so a subclass keeps its own methods through the chain. The baseline drops its PossiblyUnusedMethod entry for useOr: the test calls `->where(...)->useOr()`, which Psalm can now see. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
🤖
Every clause method on
QueryGenerator(select,from,whereand the rest) runs through__call, which always returns$thisbut declared no return type. Psalm therefore read each chained call as returningmixed, so in$q->select(...)->from(...)everything after the first call went unchecked. Tracked in iFixit/ifixit#66899.__callnow declares: static. The native type beats a@return $thisdocblock here because PHP enforces it at runtime, andcomposer.jsonalready requires PHP 8.2 (staticreturn types exist since 8.0). Psalm resolvesstaticto the calling class, so subclasses keep their own methods through a chain.The Psalm baseline loses its
PossiblyUnusedMethodentry foruseOr: the test's->where(...)->useOr()chain is now typed, so Psalm finds that call.Left out:
@methodlines per clause. They would add argument checking at every call site in the iFixit repo, which is a separate change.Checks
Run locally on PHP 8.3, the version CI uses:
vendor/bin/phpunit QueryGeneratorTest.php: 17 tests, 111 assertions, OKvendor/bin/psalm --no-cache: no errors (before the baseline edit, it reported the one unuseduseOrentry)🤖 Generated with Claude Code