-
Notifications
You must be signed in to change notification settings - Fork 27
Add support for generics #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
299343e
to
9999b50
Compare
9999b50
to
d294a72
Compare
Thank so much for helping out here :) I left some small comments, which might need the help of @JaZo. I think we are going to surface a few incinsistencies when we start running phpstan on max. :x |
(lets toy with copilot see what happens, boo php) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces generic type support via PHPDoc annotations to improve static analysis and developer experience when using the package.
- Added generics annotations to repository, document, and relation interfaces.
- Enhanced the HasRelations trait to properly document generic relation methods.
- Updated the Collection class and README documentation to reflect the new generics feature.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
src/Interfaces/RepositoryInterface.php | Added generics to the return types of repository methods. |
src/Interfaces/OneRelationInterface.php | Annotated relation methods with generics for type consistency. |
src/Interfaces/ManyRelationInterface.php | Updated phpdoc annotations with generics on collection types. |
src/Interfaces/ItemDocumentInterface.php | Specified generic return type for document data extraction. |
src/Interfaces/CollectionDocumentInterface.php | Added generics to collection return types. |
src/Concerns/HasRelations.php | Enhanced relation factory methods with inline generic templates. |
src/Collection.php | Added generics annotations to extend the Laravel Collection class. |
composer.json | Removed an author entry. |
README.md | Expanded documentation with usage examples on generics. |
So uhm, how can we move forward with this PR? Do you expect me to follow up on some things or can we merge as-is? |
Think we can just add a todo as @JaZo mentioned for now and move forward further when we have phpstan. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added type tests, inspired by these from Laravel, but they still fail on the repository types. I'd like some help resolving that.
The type tests are fixed (thx for the initial setup!) by adding some Further, upon second reading, I changed the signature of the |
c2904d5
to
78c530c
Compare
Great! Using int as collection key makes more sense yes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
Adds support for using generics (using PHPStan types), by adding the correct phpdoc annotations to Interfaces. No actual code has been changed, so this could be released as a minor.
The next step would be completely incorporating PHPStan and use it as a QA-tool in the pipeline.
Motivation and context
Modern IDE's have support for them and this greatly enhances the DX of using this package.
fixes #107
How has this been tested?
N/A
Types of changes
Checklist: