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

SubmitButton::$onClick type causes problems for PHPStan users #265

Closed
ondrejmirtes opened this issue Jan 31, 2021 · 2 comments
Closed

SubmitButton::$onClick type causes problems for PHPStan users #265

ondrejmirtes opened this issue Jan 31, 2021 · 2 comments

Comments

@ondrejmirtes
Copy link
Contributor

Version: 3.1.0

/cc @adaamz @milo @dg

This commit 2fce9b9 changed SubmitButton::$onClick type to:

/** @var callable[]&((callable(Nette\Forms\Form|SubmitButton, array|object): void)|(callable(array|object): void))[]

Which means "pass a callable that's ready to accept either Nette\Forms\Form or SubmitButton". But users usually pass in a callable that only accepts "SubmitButton" and it looks like SubmitButton will only ever be passed as an argument:

Nette\Utils\Arrays::invoke($this->onClick, $this);

This change causes PHPStan to report this error on valid code:

Array (array<callable(Nette\Forms\Controls\SubmitButton|Nette\Forms\Form, array|object): void>) does not accept Closure(Nette\Forms\Controls\SubmitButton, array): void.

Is my train of thought correct? Or should user's callables be ready to accept Form instance in some cases too?

ondrejmirtes referenced this issue in spaze/michalspacek.cz Jan 31, 2021
@dg
Copy link
Member

dg commented Jan 31, 2021

It works in such a way that, depending on the type hint, it passes either a button or a form (or values). How to write annotation?

@ondrejmirtes
Copy link
Contributor Author

Looks like this could work: https://phpstan.org/r/1f32ff3f-5bdf-4fb2-a64a-7e3eff3025f8

/** @var array<callable(Form): void|callable(Button): void> */
public $onClick = [];

@dg dg closed this as completed in 05d14fe Feb 4, 2021
spaze added a commit to spaze/michalspacek.cz that referenced this issue Feb 4, 2021
Reverts commit 91be65e

The issue was fixed in nette/forms#265 Thanks!
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

No branches or pull requests

2 participants