Skip to content

fix: array callables + collect() - #56

Merged
kbond merged 1 commit into
zenstruck:1.xfrom
kbond:phpstan-fixes
Aug 12, 2026
Merged

fix: array callables + collect()#56
kbond merged 1 commit into
zenstruck:1.xfrom
kbond:phpstan-fixes

Conversation

@kbond

@kbond kbond commented Aug 12, 2026

Copy link
Copy Markdown
Member

This pull request enhances the collect() function to handle callable sources more robustly and improves type safety and test coverage. The main focus is on distinguishing between arrays and callables, ensuring the correct collection type is returned, and thoroughly testing these behaviors.

Enhancements to collect() function:

  • Improved callable detection and handling:
    • The PHPStan return type annotation for collect() was updated to correctly prioritize callables over arrays, ensuring that callable sources are always treated as such.
    • The implementation now checks if the source is callable before checking for arrays, returning a LazyCollection when appropriate.

Testing improvements:

  • Added comprehensive tests for collect():
    • New tests verify that callables, arrays, traversables, Doctrine collections, and already-instantiated collections are handled as expected, ensuring correct instantiation and behavior for each source type.
    • Helper methods and global functions were added to support these new test cases.
    • Additional type assertions were added to the stubs to verify static analysis expectations for various usages of collect().

Test utilities and imports:

  • Added necessary imports for new collection types to the test suite, supporting the expanded test coverage.

@kbond
kbond merged commit 1cd06a5 into zenstruck:1.x Aug 12, 2026
23 of 36 checks passed
@kbond
kbond deleted the phpstan-fixes branch August 12, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant