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 dg commented Mar 15, 2019

Is it supported by IDEs?

@adaamz
Copy link
Contributor Author

@adaamz 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 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 adaamz commented Apr 5, 2019

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

@ondrejmirtes
Copy link
Contributor

@ondrejmirtes ondrejmirtes commented Apr 5, 2019

👍 from me

@dg
Copy link
Member

@dg dg commented Apr 6, 2019

Thanks! Can you post PR for Application too?

@dg dg merged commit e2c8d4b into nette:master Apr 6, 2019
1 check failed
@adaamz adaamz deleted the patch-1 branch Apr 7, 2019
dg pushed a commit that referenced this issue Apr 9, 2019
@ondrejmirtes
Copy link
Contributor

@ondrejmirtes 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 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 ondrejmirtes commented Nov 26, 2019

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

Successfully merging this pull request may close these issues.

None yet

3 participants