Drupal.Classes.FullyQualifiedNamespace sniff doesn't work with attributes

Created on 26 October 2024, about 1 month ago

Problem/Motivation

I'm trying to upgrade test code for PHPUnit 10 attribures, and the Rector rule (Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100) works great, but leaves fully-qualified class names.

So I'm trying to use the Drupal.Classes.FullyQualifiedNamespace sniff as a second step, but it's not picking up classes in attributes.

I think the problem is here maybe:

        if ($tokens[($stackPtr - 1)]['code'] !== T_STRING || $tokens[($stackPtr + 1)]['code'] !== T_STRING) {

but I'm not sure, as doing a dump($tokens) before this gets me a list of tokens that look like AFTER the changes have been made to classnames it does find!

I'm confused by tokens like this in the attribute classname:

  49 => array:11 [
    "code" => 262 <-- that's not the value of T_STRING, which is 313.
    "type" => "T_STRING" <-- but that says T_STRING!
    "content" => "PHPUnit"
    "line" => 11
    "column" => 4
    "length" => 7
    "attribute_opener" => 47
    "attribute_closer" => 59
    "level" => 0
    "conditions" => []
    "nested_attributes" => array:1 [
      47 => 59
    ]
  ]

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

8.3

Component

Review/Rules

Created by

🇬🇧United Kingdom joachim

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

Comments & Activities

Production build 0.71.5 2024