Skip to content

Use phpstan callable definitions - #216

Merged
dg merged 1 commit into
nette:masterfrom
adaamz:patch-1
Apr 6, 2019
Merged

Use phpstan callable definitions#216
dg merged 1 commit into
nette:masterfrom
adaamz:patch-1

Conversation

@adaamz

@adaamz adaamz commented Mar 15, 2019

Copy link
Copy Markdown
Contributor
  • 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

dg commented Mar 15, 2019

Copy link
Copy Markdown
Member

Is it supported by IDEs?

@adaamz

adaamz commented Mar 15, 2019

Copy link
Copy Markdown
Contributor Author

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

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

@dg

dg commented Apr 4, 2019

Copy link
Copy Markdown
Member

It seems good.

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

adaamz commented Apr 5, 2019

Copy link
Copy Markdown
Contributor Author

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

@ondrejmirtes

Copy link
Copy Markdown
Contributor

👍 from me

@dg

dg commented Apr 6, 2019

Copy link
Copy Markdown
Member

Thanks! Can you post PR for Application too?

@ondrejmirtes

ondrejmirtes commented Nov 26, 2019

Copy link
Copy Markdown
Contributor

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

dg commented Nov 26, 2019

Copy link
Copy Markdown
Member

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

@ondrejmirtes

ondrejmirtes commented Nov 26, 2019 via email

Copy link
Copy Markdown
Contributor

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