Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm: Find usage of function that includes parameter

If I have a function like this:

<?php

function foo($used, $maybe_unused = '') { ... }

Alt-F7 will find ALL calls to foo(). However, I want to find out if any of the calls include the second parameter or not. If none of the calls include the second parameter, I'll know it's safe to remove. Without looking through the entire list of results, I want to know if there are any calls like this:

foo('first', 'second');

or, if they are all like this:

foo('first');

and therefore I can remove the second parameter.

like image 288
Michael Arrison Avatar asked Apr 09 '26 01:04

Michael Arrison


2 Answers

You may want to use the Structural Search feature:
https://www.jetbrains.com/help/phpstorm/structural-search-and-replace.html

Moreover, there is an existing template named "Function call with 2 parameters" that should do the trick in your scenario. The only thing you will have to edit there is $a$ variable, just put your function name as a filter > text.

Hope it helps!

like image 137
duck_in_hat Avatar answered Apr 10 '26 15:04

duck_in_hat


Finally found a reasonable way to do this, thanks to a Reddit comment.

Put the cursor on the method argument, and from the Code menu, select the Analyze Code submenu, and finally select Dataflow to Here…. You'll see all that argument's usages listed in a new pane.

like image 32
miken32 Avatar answered Apr 10 '26 15:04

miken32