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

Callable prototypes #430

Closed
wants to merge 10 commits into from
Closed

Callable prototypes #430

wants to merge 10 commits into from

Conversation

dktapps
Copy link
Contributor

@dktapps dktapps commented Jan 24, 2021

This is a working implementation, although a bit rough around the edges.

A new toggle checkMissingCallablePrototype is added, disabled by default (as per @ondrejmirtes request).

TypeTraverser::map($type, static function (Type $type, callable $traverse) use (&$result): Type {
if (
($type instanceof CallableType && $type->isCommonCallable()) ||
($type instanceof ObjectType && $type->getClassName() === \Closure::class)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only thing I'm not happy with. I think there should be a better, more generalized way to do this, but if there is one it's not apparent to me.

Copy link
Member

Choose a reason for hiding this comment

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

This is probably fine... There's Type::isCallable() and Type::getCallableParametersAcceptors() but there's no way to extract whether it's general callable or already specified callable from that.

So as long as this place is synchronized with TypeNodeResolver::resolveCallableTypeNode(), we're fine.

@ondrejmirtes
Copy link
Member

I've already added a few commits locally, I'm taking over the PR, thanks.

@ondrejmirtes
Copy link
Member

In master. Thank you.

@ondrejmirtes
Copy link
Member

@dktapps Please submit a documentation change that explains this setting somewhere here: https://phpstan.org/config-reference#stricter-analysis Thanks.

@dktapps
Copy link
Contributor Author

dktapps commented Jan 24, 2021

Awesome, thanks! Will attend to the docs as soon as I get home.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants