Can PhpStorm be configured to recognize functions as used when called via callbacks or as methods of an object?
I'm working with a WordPress plugin. It has some functions which are used only in callbacks and/or as methods of an object. PhpStorm detects these as being "unused" functions. Is there a way to have PhpStorm detect these functions as being utilized?
Example 1:
A method of the `GCS_Sermons` object appears as unused:
`public function most_recent_with_taxonomy($taxonomy_id)`
But is used by the `most_recent_sermon()` method in the object `GCS_Taxonomies_Base`:
`return $this->sermons->most_recent_with_taxonomy( $this->id );`
Example 2:
Sometimes a function only used as a callback appears as unused. For example:
`public function plugin_options_validate( $input )`
Will appear unused even though it is utilized:
`register_setting( $this->plugin_option_key, $this->plugin_option_key, array( $this, 'plugin_options_validate' ));`
Strangely enough on other occasions the function will be correctly denoted as used, for example the following function and callback:
`function lqd_customize_register ( $wp_customize )`
Which is only used here:
`add_action( 'customize_register', 'lqd_customize_register' );`
....
Any ideas?
Thanks!
Please sign in to leave a comment.
Do I get right that Ctrl/Cmd+clicking the method call doesn't bring you to the method definition? Not sure, maybe class definitions are resolved wrongly, hard to say without looking at the project.
This is hard to support. We've tried that with namespace and class names, that was the result: https://youtrack.jetbrains.com/issue/WI-43858
Anyways, please vote: https://youtrack.jetbrains.com/issue/WI-27761
This is something the Wordpress plugin takes credit for, it's easier to make references for add_action() than for every possible way of calling a method.
Yes, Ctrl+Click does not bring me to the method definition. Instead I get a message, "Cannot find declaration to go to".
The project is open source and available at (if you have a minute to look at the code): https://github.com/LiquidChurch/lqd-messages/tree/major-04-22-20 (current dev branch)
The files referenced in my original post are:
https://github.com/LiquidChurch/lqd-messages/blob/major-04-22-20/includes/post-types/class-sermons.php (see line 594 and following)
https://github.com/LiquidChurch/lqd-messages/blob/major-04-22-20/includes/taxonomies/class-taxonomies-base.php (see line 217 and enclosing function).
https://github.com/LiquidChurch/lqd-messages/blob/major-04-22-20/includes/pages/class-option-page.php (see line 104 and following for function declaration, line 365 for function callback)
I've added my vote to the issue in youtrack.
Appreciate the help!
PhpStorm doesn't know what the
$sermonsproperty is, you might wanna type-hint it with the PHPDoc@vartag.Ahh, then I caused that problem myself. I wasn't a fan of how verbose the PHPDocs were and slimmed it down on the variables. I don't suppose you know of another way to slim them down?
Just seems to clutter things up and not really be useful to me...but if the hints are needed for PHPStorm intelligence...
> This is something the Wordpress plugin takes credit for, it's easier to make references for add_action() than for every possible way of calling a method.
I'd be happy with an ability to custom annotate a callback function name string.
Also here looking to get something like ` 'callback' => [ $this, 'has_closed_popup' ],` recognized.