Problem/Motivation

phpcs --standard=Drupal modules/user/src/EventSubscriber/AccessDeniedSubscriber.php

FILE: ...core/modules/user/src/EventSubscriber/AccessDeniedSubscriber.php
----------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 3 LINES
----------------------------------------------------------------------
  3 | ERROR   | [x] Namespaced classes, interfaces and traits should
    |         |     not begin with a file doc comment
 13 | WARNING | [x] Unused use statement
 46 | ERROR   | [ ] Expected type hint "UrlGeneratorInterface"; found
    |         |     "URLGeneratorInterface" for $url_generator

This is because the use statement is:

use Drupal\Core\Routing\UrlGeneratorInterface;

and the code is:

  public function __construct(AccountInterface $account, URLGeneratorInterface $url_generator) {

The problem is UrlGeneratorInterface vs URLGeneratorInterface. So either the fix here is wrong - it is removes the use statement - or the sniff is wrong. I think the sniff is wrong because PHP is not case sensitive.

Proposed resolution

tbd

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Comments

alexpott created an issue. See original summary.

alexpott’s picture

klausi’s picture

Title: Drupal.Classes.UnusedUseStatement has some false positives » UnusedUseStatement sniff must not be case sensitive

Ok, so this sniff should not be case sensitive. We should also create a sniff that makes sure that class names are spelled out the exact same way as in the use statement.

alexpott’s picture

exact same way as in the use statement

That's not quite right - the use statement can be in the wrong case too :(

klausi’s picture

Yeah, I mean Drupal should invent a coding standard that the casing has to be the same in the use statement and the statement referencing the class.

  • klausi committed 9d6cfa1 on 8.x-2.x
    Issue #2674598: Fixed UnusedUseStatement sniff must not be case...
klausi’s picture

Status: Active » Fixed

Committed a fix.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.