Skip to content

Return static from the chainable methods - #20

Merged
jarstelfox merged 1 commit into
masterfrom
chain-methods-return-static
Nov 24, 2026
Merged

jarstelfox merged 1 commit into
masterfrom
chain-methods-return-static

Conversation

@jarstelfox

Copy link
Copy Markdown
Member

🤖
Follow-up to #19. That PR typed __call as returning static, but the chainable methods that are real methods still say self. So a chain through one of them drops back to plain QueryGenerator. In (new SubQuery)->join(...)->skipValidation()->getAll(), Psalm resolves getAll through __call and thinks the rows are a QueryGenerator. Tracked in iFixit/ifixit#66899.

Changes

  • Chainable methods: skipValidation(), useOr(), union(), unionAll() (and the private addUnion()) now return static. Each already returns $this.
  • build(): documented as list{string, list<mixed>} instead of array{0: string, 1: list<mixed>}. It returns [$query, $params], so a list is accurate, and callers that declare array{string, array} now accept it. The params keep list<mixed> because they are whatever values callers pass in.

Checks

Run locally on PHP 8.3, the version CI uses:

  • vendor/bin/phpunit QueryGeneratorTest.php: 17 tests, 111 assertions, OK
  • vendor/bin/psalm --no-cache: no errors, no baseline change

🤖 Generated with Claude Code

The previous change gave __call a `static` return type, but the real
chainable methods (skipValidation, useOr, union, unionAll) still
declared `self`. A chain that passes through one of them drops back to
QueryGenerator, so a subclass's own methods after it, like
`(new SubQuery)->...->skipValidation()->getAll()`, resolve to __call and
type as QueryGenerator instead of the subclass's result.

build() always returns `[$query, $params]`, a two-element list.
Declaring it as `list{string, list<mixed>}` instead of
`array{0: string, 1: list<mixed>}` lets callers that declare
`array{string, array}` accept it. The params stay `list<mixed>`: they
are whatever values callers pass in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jarstelfox
jarstelfox marked this pull request as ready for review November 24, 2026 00:05
@jarstelfox
jarstelfox merged commit b02cdf8 into master Nov 24, 2026
4 checks passed
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.

1 participant