UseGlobalClass sniff reporting for every 'use' statement

Created on 18 November 2021, about 3 years ago
Updated 19 May 2023, over 1 year ago

Problem/Motivation

I have recently noticed the sniff "Drupal.Classes.UseGlobalClass.RedundantUseStatement" is firing for all imports in any class.
I assume something is not set up correctly in my project but cannot see any issue.

My PHPCS constraints from composer.json are as follows

  "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
  "drupal/coder": "^8.3",

When running PHPCS using coder with the drupal standards I am receiving the "Non-namespaced classes/interfaces/traits should not be referenced with use statements" error, these errors are reported to all be on line 1.

FOUND 14 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------
1 | ERROR | [x] Non-namespaced classes/interfaces/traits should not
| | be referenced with use statements
1 | ERROR | [x] Non-namespaced classes/interfaces/traits should not
| | be referenced with use statements
1 | ERROR | [x] Non-namespaced classes/interfaces/traits should not
| | be referenced with use statements

Here is an example of a class that has the error.

<?php
namespace Drupal\pricing\Form;

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;

class PricingCronForm extends ConfigFormBase {

In the above example, I will receive 3 errors saying that each import is incorrect :(.

Steps to reproduce

Unsure exactly how to reproduce from a fresh project, I am hoping someone else is having this issue and can point me in the right direction.

Thanks for any help.

UPDATE

I have since spotted 2 related issues that are confirming the same behaviour.
It seems to work correctly in v8.3.9 but the issue occurs in v8.3.10+.

💬 Support request
Status

Fixed

Version

8.3

Component

Coder Sniffer

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024