3

PhpStorm uses yellow font for method names if it detects that the method is in use elsewhere in the app.

It uses a grey font for unused methods.

This is really helpful for identifying stale code.

But PhpStorm doesn't recognize my methods that I am using in the /routes directory since they are called magically from a string.

For example, I am only using the sendPayout method in /routes, but the chargeCustomer is called directly from within another method.

enter image description here

For example, this line in /routes/web.php should ideally force the sendPayout method shown in the screenshot to appear in yellow font.

Route::post('/api/send-offer','StripeController@sendPayout');

Is there any way to get PhpStorm to recognize this, either by changing settings or using a certain plugin?

I am using PhpStorm 2019.3.1, MacOS Catalina version 10.15.2, and Laravel 5.8. I already have the Laravel plugin installed to PhpStorm.

4
  • 1
    This is new inspection in 2019.3 -- "unused public method". You either disable it .. or configure such methods (or even whole classes) as entry points. As for Laravel, it requires special support from Laravel plugin for that (as IDE itself will not provide such framework-specific support). Existing Laravel plugin is barely maintained, so nobody knows when it will be supported, but there is new Laravel Idea plugin, it's a paid one, but it does provide more/different functionality and may do this already (and if not it's actively developed so may support it soon) Commented Jan 12, 2020 at 10:50
  • 1
    Other than that -- see this ticket: youtrack.jetbrains.com/issue/WI-49024. Original discussion (why is that etc) -- youtrack.jetbrains.com/issue/WI-47685 Commented Jan 12, 2020 at 10:52
  • Nice, thanks! Good to know on the background of the issue and very surprising that JetBrains released this inspection as a default without better native support for it on major frameworks. Anyhow, the Laravel Idea plugin totally solves the issue. Now all methods are being recognized which is great. Commented Jan 13, 2020 at 7:28
  • 1
    You can use PHPDoc @uses directive Commented Aug 12, 2021 at 13:52

3 Answers 3

3

Per @LazyOne's comments, the plugin "Laravel Idea" does solve the recognization issue for all Symfony and Laravel methods that aren't already picked up by PhpStorm's default. I definitely recommend this plugin now that I am using it.

Sign up to request clarification or add additional context in comments.

Comments

0

There is special file for this called '.phpstorm.meta'. So you can "map" methods. Read more here: https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html

1 Comment

This is helpful to know, however the ideal solution would be to have PhpStorm automatically recognize these methods as I update the file. Thanks for the answer!
0

As zxdx mentioned: You can use PHPDoc @uses directive

This solution has the best cross-IDE support.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.