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

Use phpstan callable definitions #216

Merged
merged 1 commit into from
Apr 6, 2019
Merged

Use phpstan callable definitions #216

merged 1 commit into from
Apr 6, 2019

Conversation

adaamz
Copy link
Contributor

@adaamz adaamz commented Mar 15, 2019

  • new feature
  • BC break? no

Hi,
are you interested in definition for callables like phpstan does?
format is like in php (without parameter names) callable(params): return_type

If you are interested I can change other classes/packages.

@dg
Copy link
Member

dg commented Mar 15, 2019

Is it supported by IDEs?

@adaamz
Copy link
Contributor Author

adaamz commented Mar 15, 2019

PhpStorm "supports" intersection workaround in format
callable[]&(callable(Form): void)[]

I do not have other IDEs like Eclipse or NetBeans...

@dg
Copy link
Member

dg commented Apr 4, 2019

It seems good.

@adaamz adaamz changed the title Form: use phpstan callable definition Use phpstan callable definitions Apr 5, 2019
@adaamz
Copy link
Contributor Author

adaamz commented Apr 5, 2019

Fixed union on Form::onSuccess.
Used phpstan syntax in other classes - SubmitButton and Container.

@ondrejmirtes
Copy link
Contributor

👍 from me

@dg
Copy link
Member

dg commented Apr 6, 2019

Thanks! Can you post PR for Application too?

@ondrejmirtes
Copy link
Contributor

ondrejmirtes commented Nov 26, 2019

This isn't exactly typesafe, we'd like to use:

// $form is our own CustomForm extending Nette\Forms\Form
$form->onSuccess[] = function (CustomForm $form): void {
});

Since in onSuccess there's callable(\Nette\Forms\Form), it's not typesafe to ask for a subtype in the callable. Nette might pass a different instance in there. I'm gonna experiment with callable(static) instead.

No need to change anything in Nette - phpstan-nette extension for PHPStan 0.12. will contain the fixed stub :) (Yeah, I've added support for custom phpDoc stubs to fix 3rd party phpDocs.)

@dg
Copy link
Member

dg commented Nov 26, 2019

This callable(Form) exists for PHPStan only, so there is no problem to change it to callable(static)

@ondrejmirtes
Copy link
Contributor

ondrejmirtes commented Nov 26, 2019 via email

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.

3 participants