Repository navigation
fix(references): --find-references-to finds the calls of a function - #14648
Conversation
…imeo#14197 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Behaviour change
|
✅ Performance: unchanged · Types: unchanged
How to read this table
head 21804c4 · base 9028ade (merge-base) · workflow run |
--find-references-to finds the calls of a function
alies-dev
left a comment
There was a problem hiding this comment.
Thanks, the fix looks correct. Both new FileReferenceTest cases fail on master and pass here. Since the reference is recorded after callable strings are resolved, call_user_func('App\helper'), array_map('App\helper', …), $s = 'App\helper'; $s(); and \App\helper(...) are found as well (part of #14198). It is also behind collect_locations, so normal, diff and unused-code runs are unaffected, and free functions are already roots in CodeUseGraph::isRoot().
A few small things:
- Leading
\only works for functions. Theltrimis applied only to the function lookup, so--find-references-to='\App\H'and'\App\H::a'still return nothing, whileApp\Hfinds thenew H()anduse App\H;lines. Moving$symbol = ltrim($symbol, '\\');to the top offindReferencesToSymbol()would fix every symbol kind, and the inlineltrimcould go. - CLI help:
Psalm.phpstill documents--find-references-to=[class|method|property]; it should mentionfunction. - Comment wording in
FunctionCallAnalyzer: "where the functions of the code are called is found as where methods are" is hard to parse. Maybe// record the call sites of user functions, as Methods::methodExists() does for methods.
Not blocking, could be a follow-up: use function App\helper; lines aren't reported. For classes, CanAlias records use App\H; in use_referencing_locations, but the TYPE_FUNCTION branch only fills aliased_functions, so a rename based on this list would miss the import.
Also mention functions in the --find-references-to help. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…meo#14199 vimeo#14648 records the call of a user function only when locations are collected, and this PR recorded it a second time at another place for the language server. Keep the one of vimeo#14648, with the name location and the used return value, and record it in every run, as for methods. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
--find-references-to(Codebase::findReferencesToSymbol()) finds no reference to a function, while it finds those to a method.Before
After
Fixes #14197