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

[TASK] Port some type annotation improvements from the Core #170

Merged

Conversation

oliverklee
Copy link
Collaborator

The Core recently has received some improvements on the type annotations/declerations. Port those over to our stubs.

Also rearrage some union type to have null always last.

@oliverklee oliverklee force-pushed the task/align-stubs-with-core branch 2 times, most recently from a8b53e4 to 01a9670 Compare August 3, 2024 16:41
@oliverklee
Copy link
Collaborator Author

I don't quite understand why PHPStan cannot resolve the type for Repository::setDefaultOrderings(), and I would welcome any help.

The Core recently has received some improvements on the type
annotations/declerations. Port those over to our stubs.

Also rearrage some union type to have `null` always last.
@oliverklee oliverklee force-pushed the task/align-stubs-with-core branch from 01a9670 to b56227c Compare August 3, 2024 16:57
@oliverklee
Copy link
Collaborator Author

Okay, I've simplified the type a bit for the time being to get this to green.

@sascha-egerer
Copy link
Owner

sascha-egerer commented Aug 3, 2024

@oliverklee I‘m on vacation but I’ll have a look end of next week

@sascha-egerer
Copy link
Owner

Looks like the previous issue was due to a bug in PHPStan that is not reproducible in the PHPStan playground. Once phpstan has created it's result caches the error is gone. If i remove the result cache i get the error again. Executing phpstan once again is successful. So it is somehow a bug that does only occur if result caches are not active. I'll further investigate and create a phpstan issue once i have a minimal reproducable setup. Maybe it is also somehow related to other parts of this package - I'll investigate and come back soon.

@sascha-egerer
Copy link
Owner

Ok, reason is phpstan/phpstan#10967 and the text in the orange box: https://phpstan.org/user-guide/stub-files

Why is PHPStan complaining about “Class not found” in a stub file?

Stub files are analysed independently from the rest of your codebase. This means that any type they’re referencing must also be present as a stub, even if you don’t want to override any of its PHPDocs.

This is a way of tackling the problem of optional dependencies. We want to report any undefined names used in the stubs to prevent typos, but at the same time we also need to support optional dependencies in PHPStan extensions. That’s why all the symbols must be defined again in the stubs, even as empty shells.

@sascha-egerer sascha-egerer self-requested a review August 9, 2024 16:12
stubs/QueryInterface.stub Show resolved Hide resolved
stubs/Repository.stub Outdated Show resolved Hide resolved
@sascha-egerer
Copy link
Owner

@oliverklee Looks like i'm not allowed to push my changes to your fork so i just made code suggestions.

@sascha-egerer
Copy link
Owner

@oliverklee Ok i was able to commit them via the GitHub interface. weird... But it should work now as expected.

@oliverklee
Copy link
Collaborator Author

@sascha-egerer Looks good, thanks! 🙏

@sascha-egerer sascha-egerer merged commit 71b09e3 into sascha-egerer:master Aug 9, 2024
20 checks passed
@oliverklee oliverklee deleted the task/align-stubs-with-core branch August 10, 2024 16:59
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