Add SelectQueryFindListReturnTypeExtension for find('list')->toArray()#64
Merged
rochamarcelo merged 5 commits intoCakeDC:4.next-cake5from Mar 27, 2026
Merged
Conversation
This extension provides proper return type inference for find('list')->toArray(),
returning array<int|string, string> instead of the generic entity array type.
The extension:
- Detects find('list') in the method chain before toArray()
- Works with chained queries (where, orderBy, limit, etc.)
- Returns null for non-list finders to preserve default behavior
Fixes the common issue where $roles = $table->find('list')->toArray()
would require a @var annotation to suppress PHPStan varTag.type errors.
Collaborator
Author
|
"The job was not started because your account is locked due to a billing issue" |
Member
|
let me check that... |
Contributor
|
It looks good. Have you checked what happens when groupField is used |
When find('list', groupField: '...') is used, the return type
changes to array<int|string, array<int|string, string>> instead
of the simple array<int|string, string>.
Member
fixed |
Collaborator
Author
|
The phpstan fail is not mine, and fixing it would require 5.3+ bump or silencing. |
Collaborator
Author
|
@rochamarcelo Both ways are now supported. |
rochamarcelo
approved these changes
Mar 27, 2026
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.
Summary
This PR adds a PHPStan dynamic return type extension that provides proper type inference for
find('list')->toArray().Problem
Currently, when using
find('list'), PHPStan infers the return type asarray<array|EntityInterface>, butfind('list')actually returnsarray<int|string, string>. This causes developers to need@varannotations:Without the annotation, PHPStan reports
varTag.typeerrors.Solution
The
SelectQueryFindListReturnTypeExtensiondetectsfind('list')in the method call chain beforetoArray()and returns the correct typearray<int|string, string>.Features:
find('list')anywhere in the method chainfind('list')->where([...])->orderBy([...])->toArray()nullfor non-list finders to preserve default behaviorTests
Added test cases for:
find('list')->toArray()usageExample
Before (with annotation):
After (no annotation needed):