Skip to content
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

Fix typing for factory #102

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

Mopolo
Copy link
Contributor

@Mopolo Mopolo commented Jan 9, 2025

The current annotations are correct but not complete enough.

Since repositories extend a base class, they can have method that are not in this base class.

The issue with using Repository<T> as the return type is that PHPStan cannot see those methods.

For example: https://phpstan.org/r/65389bf5-b00d-4e5d-b993-8c6f274b7545

With this change, PHPStan understands the correct class while still forcing classes to extend Repository.

For example: https://phpstan.org/r/d40317b1-1834-407b-9284-ca1e7b0d3325

You can try removing the @extends Repository<Foo> or the extends Repository to see the correct errors.

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Licence Apache-2.0

Since repositories extend a base class, they can have method
that are not in this base class.

The issue with using `Repository<T>` as the return type is
that PHPStan cannot see those methods.

For example: https://phpstan.org/r/65389bf5-b00d-4e5d-b993-8c6f274b7545

With this change, PHPStan understands the correct class while still
forcing classes to extend `Repository`.

For example: https://phpstan.org/r/d40317b1-1834-407b-9284-ca1e7b0d3325
@Mopolo Mopolo marked this pull request as ready for review January 9, 2025 14:21
@Mopolo Mopolo requested a review from vgreb as a code owner January 9, 2025 14:21
Copy link
Contributor

@vgreb vgreb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Mopolo, thank you for this PR. Your right, we need 2 differents templates !

@vgreb vgreb merged commit b2f0cb3 into ccmbenchmark:master Jan 9, 2025
10 checks passed
@Mopolo Mopolo deleted the fix-repository-factory-typing branch January 9, 2025 15:41
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.

2 participants