A warning is generated for "unused use statement" when the class name is not mentioned in the code, but is mentioned in a comment. Sometimes, it is necessary to hint to the IDE using an inline @var declaration, so the sniff needs to be aware that it should be looking in the code comments as well as the code before assuming something is unused.

use Drupal\mymodule\MyNamespace\MyClass;

/** @var MyClass[] $hard_to_determine_class */
$hard_to_determine_class = module_invoke_all('mymodule_do_stuff');

In the above example, @var is necessary because of the ridiculous way that hooks are invoked and the crippling limitations Drupal enforces as a result.

Comments

chriscohen created an issue. See original summary.

klausi’s picture

Status: Active » Closed (won't fix)

Since the Drupal convention is to always use the fully qualified namespace when referencing classes in documentation you don't need a use statement. See https://www.drupal.org/coding-standards/docs#var

The /** @var ... */ syntax has not been added to the coding standards yet, but as you can see in Drupal core we always use fully namespaced names, so we can assume that is going to be the standard. This is discussed in #2305593: [policy] Set a standard for @var inline variable type declarations.

psynaptic’s picture

Ahh, shame. We need this too.