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

Add type checking for hook callbacks in add_action and add_filter #121

Merged
merged 1 commit into from Nov 9, 2022

Conversation

szepeviktor
Copy link
Owner

… (#107)

  • Setup the hook callback rule and test.

  • Add the wp-hooks library.

  • Start adding tests.

  • Preparing more tests.

  • If we don't have enough arguments, bail out and let PHPStan handle the error.

  • If the callback is not valid, bail out and let PHPStan handle the error:

  • Simplify this.

  • More valid test cases.

  • Update some test line numbers.

  • First pass at detecting mismatching accepted and expected argument counts.

  • Remove some accidental duplicates.

  • Fix some logic.

  • Let's split this up before it gets out of hand.

  • Reduce this down.

  • More tidying up.

  • We're going to be needing this in multiple methods soon.

  • Prep for callback return type checking, not yet functional.

  • Split action return type assertion into its own method.

  • Bring this message more inline with those used by PHPStan.

  • Add detection for filter callbacks with no return value.

  • Don't need this just yet.

  • Use early exit to reduce code nesting.

  • Remove unused imports.

  • Yoda comparisons are disallowed.

  • Coding standards.

  • Remove unused code.

  • Use early return to reduce code nesting.

  • Remove more unused code.

  • Renaming.

  • Use early return to reduce code nesting.

  • Tidying up.

  • Correct logic introduced during refactoring.

  • Exclude "maybe" callables.

  • More handling for parameter counts.

  • More handling for optional parameters in hook callbacks.

  • Make the tests more manageable.

  • Tests for more callback types.

  • Tidying up.

  • This isn't used.

  • More test cases.

  • Tests for variadic callbacks.

  • More specific handling for variadic callbacks.

  • More tests.

  • The hooks names are not relevant to the tests.

  • Remove an else.

  • I'm still not entirely sure why this works, but it does. Props @herndlm.

  • Another test for an action with a return value.

  • More variadic handling.

  • Turns out PHPStan handles typed and untyped functions differently.

  • Partly broken callbacks will trigger an error in PHPStan so we don't need to handle them.

  • Terminology.

  • Refactoring.

  • PHP 7.2 compatibility.

  • Reorder the processing so the return type is checked first.

  • More tests.

Co-authored-by: Viktor Szépe viktor@szepe.net

…#107)

* Setup the hook callback rule and test.

* Add the wp-hooks library.

* Start adding tests.

* Preparing more tests.

* If we don't have enough arguments, bail out and let PHPStan handle the error.

* If the callback is not valid, bail out and let PHPStan handle the error:

* Simplify this.

* More valid test cases.

* Update some test line numbers.

* First pass at detecting mismatching accepted and expected argument counts.

* Remove some accidental duplicates.

* Fix some logic.

* Let's split this up before it gets out of hand.

* Reduce this down.

* More tidying up.

* We're going to be needing this in multiple methods soon.

* Prep for callback return type checking, not yet functional.

* Split action return type assertion into its own method.

* Bring this message more inline with those used by PHPStan.

* Add detection for filter callbacks with no return value.

* Don't need this just yet.

* Use early exit to reduce code nesting.

* Remove unused imports.

* Yoda comparisons are disallowed.

* Coding standards.

* Remove unused code.

* Use early return to reduce code nesting.

* Remove more unused code.

* Renaming.

* Use early return to reduce code nesting.

* Tidying up.

* Correct logic introduced during refactoring.

* Exclude "maybe" callables.

* More handling for parameter counts.

* More handling for optional parameters in hook callbacks.

* Make the tests more manageable.

* Tests for more callback types.

* Tidying up.

* This isn't used.

* More test cases.

* Tests for variadic callbacks.

* More specific handling for variadic callbacks.

* More tests.

* The hooks names are not relevant to the tests.

* Remove an `else`.

* I'm still not entirely sure why this works, but it does. Props @herndlm.

* Another test for an action with a return value.

* More variadic handling.

* Turns out PHPStan handles typed and untyped functions differently.

* Partly broken callbacks will trigger an error in PHPStan so we don't need to handle them.

* Terminology.

* Refactoring.

* PHP 7.2 compatibility.

* Reorder the processing so the return type is checked first.

* More tests.

Co-authored-by: Viktor Szépe <viktor@szepe.net>
@szepeviktor szepeviktor merged commit 5909d3d into fix/fqcn Nov 9, 2022
szepeviktor added a commit that referenced this pull request Nov 9, 2022
* Fix FQCN

* Add type checking for hook callbacks in `add_action` and `add_filter` (#107) (#121)

* Setup the hook callback rule and test.

* Add the wp-hooks library.

* Start adding tests.

* Preparing more tests.

* If we don't have enough arguments, bail out and let PHPStan handle the error.

* If the callback is not valid, bail out and let PHPStan handle the error:

* Simplify this.

* More valid test cases.

* Update some test line numbers.

* First pass at detecting mismatching accepted and expected argument counts.

* Remove some accidental duplicates.

* Fix some logic.

* Let's split this up before it gets out of hand.

* Reduce this down.

* More tidying up.

* We're going to be needing this in multiple methods soon.

* Prep for callback return type checking, not yet functional.

* Split action return type assertion into its own method.

* Bring this message more inline with those used by PHPStan.

* Add detection for filter callbacks with no return value.

* Don't need this just yet.

* Use early exit to reduce code nesting.

* Remove unused imports.

* Yoda comparisons are disallowed.

* Coding standards.

* Remove unused code.

* Use early return to reduce code nesting.

* Remove more unused code.

* Renaming.

* Use early return to reduce code nesting.

* Tidying up.

* Correct logic introduced during refactoring.

* Exclude "maybe" callables.

* More handling for parameter counts.

* More handling for optional parameters in hook callbacks.

* Make the tests more manageable.

* Tests for more callback types.

* Tidying up.

* This isn't used.

* More test cases.

* Tests for variadic callbacks.

* More specific handling for variadic callbacks.

* More tests.

* The hooks names are not relevant to the tests.

* Remove an `else`.

* I'm still not entirely sure why this works, but it does. Props @herndlm.

* Another test for an action with a return value.

* More variadic handling.

* Turns out PHPStan handles typed and untyped functions differently.

* Partly broken callbacks will trigger an error in PHPStan so we don't need to handle them.

* Terminology.

* Refactoring.

* PHP 7.2 compatibility.

* Reorder the processing so the return type is checked first.

* More tests.

Co-authored-by: Viktor Szépe <viktor@szepe.net>

Co-authored-by: John Blackbourn <john@humanmade.com>

* Fix

* Fix

Co-authored-by: John Blackbourn <john@humanmade.com>
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.

None yet

2 participants