How can I get the fully classified class name at the end of the PHPStorm code?

I'm new to PHPStorm and want to ask how can I get a fully classified class name (absolute class path) using Code Completion (Command + Space)?

For example, I have a function in my code:

<?php namespace A; use C\D\Class; /** * @return Class (what PHPStorm suggests) * @return \C\D\Class (what I need) */ function foo() { return new Class(); } ?> 

This function returns an instance of \ C \ D \ Class When creating a docblock for this function, I use Command + Space to place the class name after the @return keyword. PHPStorm offers a class in the extended list, but when I select the class I want, it only places the "class" instead of "\ C \ D \ Class".

How can i fix this?

Thanks in advance.

+6
source share
2 answers

I had the same problem. Actually it is very simple, but I also did not find an option. He is well hidden.

Open the settings and go to:

IDE Settings β†’ Editor β†’ Auto Import

Settings dialog in PhpStorm

There you will find the checkbox "Enable auto-import in namespace". Uncheck the box and namespaces will no longer be shrunk using the use keyword.

But now PhpStorm will tell you that there is no need to use the full namespace. To avoid this, simply disable the "Unnecessary full name" check.

Inspections in settings dialog in PhpStorm

You can still tell PhpStorm to import the namespace of the current class. For me, he simply marks the class with the cursor and presses ALT + ENTER. Then the following dialog box appears:

Import class dialog

When I confirm with ENTER, the namespace of this class becomes imported and shrinks: Shorten class name

+22
source

Currently, the only way to do this is to start typing \C\D\Cla and then complete. If this is not what you want, feel free to create a usability problem by Tracking Problems .

-1
source

Source: https://habr.com/ru/post/954378/


All Articles