axelerant / drupal-quality-checker

Pre-commit code quality checker for Drupal based projects.
https://packagist.org/packages/axelerant/drupal-quality-checker
12 stars 9 forks source link

Cannot use root namespace classes/interfaces/traits #8

Closed hussainweb closed 3 years ago

hussainweb commented 3 years ago

Coder recently added a sniff to check if root namespace classes (or interfaces or traits) are fully namespaced. As a consequence, the following code does not pass the sniff.

use Twig_Extension;
use Twig_SimpleFilter;

new Twig_Extension();

The new sniffs check that the code references classes in the root namespace use the full name and not get imported.

new \Twig_Extension();

However, this causes an issue with phpmd: the above example will not pass phpmd's cleancode rules.

There is no workaround to this situation except bypassing checks (git commit -n).

We should adhere to Drupal's coding standards, or at least, coder's interpretation of Drupal's coding standards in this case. The fix would be to exclude this specific rule from phpmd.