Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This code produced an 'Unused use statement' error:
"<?php"
2 => ""
3 => "namespace Drupal\test_module\Plugin\CatFeeder;"
4 => ""
5 => "use Drupal\Component\Plugin\PluginBase;"
6 => "use Drupal\test_module\Plugin\CatFeeder\CatFeederInterface;"
7 => ""
8 => "/**"
9 => " * Base class for Cat Feeder plugins."
10 => " */"
11 => "abstract class CatFeederBase extends PluginBase implements CatFeederInterface {"
12 => ""
13 => "}"
14 => ""
]
The problem is actually that the imported CatFeederInterface is in the same namespace as the class.
This code in the sniff checks for that:
// Check if the referenced class is in the same namespace as the current
// file. If it is then the use statement is not necessary.
$namespacePtr = $phpcsFile->findPrevious([T_NAMESPACE], $stackPtr);
The error message would be clearer if it specifically said that for this case.
Comments