feature: Added PHPStan type analysis for hyperf/collection#7578
Merged
limingxinleo merged 3 commits intohyperf:masterfrom Oct 29, 2025
Merged
feature: Added PHPStan type analysis for hyperf/collection#7578limingxinleo merged 3 commits intohyperf:masterfrom
hyperf/collection#7578limingxinleo merged 3 commits intohyperf:masterfrom
Conversation
- Fixed all 14 PHPStan type errors in collection and database type tests
- Reorganized type test files from `src/database/tests/types` to proper locations:
- Collection type tests moved to `src/collection/types/`
- Database type tests moved to `src/database/types/`
- Updated PHPStan configuration to reflect new directory structure
Changes:
1. Collection type fixes:
- Fixed float/int union types in mapToDictionary and mapToGroups
- Fixed array type inference in zip method
- Updated Functions.php to use proper numeric types
2. LazyCollection type fixes:
- Updated type assertions to match PHPStan's precise string type inference
- Fixed mapToDictionary, mapWithKeys, and flatMap type expectations
3. Database Builder type fixes:
- Fixed union type ordering for findOr and firstOr methods (42|User instead of User|int)
- Updated to match PHPStan's literal type inference
4. Database Collection type fixes:
- Changed generic string type to literal string type ('string'|User)
5. Database Relations type fixes:
- Updated Relation::noConstraints return type to match precise inference
All type checks now pass without errors.
hyperf/collection
limingxinleo
approved these changes
Oct 29, 2025
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
Fixed all 14 PHPStan type analysis errors and reorganized type test files into a more logical directory structure.
Changes
Type Test File Reorganization
src/database/tests/types/tosrc/collection/types/src/database/tests/types/tosrc/database/types/phpstan.types.neon.distconfiguration to reflect new pathsPHPStan Type Fixes
Collection Types (src/collection/types/)
Collection.php (3 errors fixed):
mapToDictionaryreturn type:array<int, float>→array<int, float|int>mapToGroupsreturn type:Collection<int, float>→Collection<int, float|int>zipreturn type:Collection<int, float|int>→Collection<int, array{float}|int>Functions.php (1 error fixed):
non-falsy-stringinstead of genericstringLazyCollection.php (4 errors fixed):
lowercase-string&numeric-string&uppercase-stringtypeDatabase Types (src/database/types/)
Model/Builder.php (4 errors fixed):
findOrandfirstOrunion type ordering:User|int→42|User(literal type)Model/Collection.php (1 error fixed):
string|User→'string'|User(literal string type)Model/Relations.php (1 error fixed):
Relation::noConstraintsreturn type to match PHPStan's precise inferenceTesting
All PHPStan type checks now pass:
composer analyse-types # ✅ [OK] No errorsRelated Issues
Fixes type analysis errors that were preventing proper type checking in the codebase.