Problem/Motivation

I've stumbled on (quite) a few undefined namespace in PHP DocBlocks.

Steps to reproduce

Run the PhpStorm inspection Undefined namespace on All The Things!

Proposed resolution

Correct the undefined namespaces into valid ones, if none apply any more delete them.

Remaining tasks

- Patch/MR
- Review
- Commit
- Rejoice

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3226198

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Spokje created an issue. See original summary.

spokje’s picture

Issue summary: View changes
spokje’s picture

Issue summary: View changes

spokje’s picture

Status: Active » Needs work

Let's see what TestBot thinks so far.

quietone’s picture

Shouldn't this be done in a sniff?

Adding related issue that has a patch. Maybe a duplicate - I haven't checked.

spokje’s picture

Thanks @quietone for finding the related issue, it's more a subset and also _very_ old. I think we can close that one? Not too sure if that would be due to being a duplicate or outdated?

> Shouldn't this be done in a sniff?

Good point, would however realistically mean this won't be done within the next 6 months looking at the lack of traction in the Coder issue queue and the fact that it would require a new release of Coder and getting that release into Cores dependencies.

Since I and reviewers have been burned before by putting (a lot of) time in bringing a non-sniff issue to RTBC only to be put back to postponed in the end for the lack of a sniff, let's postpone this one on approval of some Big Brains.

quietone’s picture

I wasn't sure if the changes here are for PhpStorm or for api.drupal.org so I picked a change to a migrate file to look at. The change here adds a leading slash to the @covers in core/modules/migrate/tests/src/Unit/process/FormatDateTest.php. On api.drupal.org that is correctly converted to a link to the source file. Maybe there are other changes that will improve api.drupal.org?

Possible coding standards issue #2341405: Decide on standard for referencing namespaced classes.

@Spokje, I ran the script in #2030977-5: Namespaces in documentation need leading \ and it created a 373K patch and on looking at the changes it it over zealous, which is pointed out later in #9. Since that is the older issue, this one should be made the duplicate and work/credit moved there. But before any of that let's get agreement on whether this should be done by a sniff or not.

quietone’s picture

spokje’s picture

Assigned: spokje » Unassigned

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

spokje’s picture

Ok, took me a while to circle back to this one.

So, the way I see it (which can be totally wrong) #2030977: Namespaces in documentation need leading \ is a kind of "Fix-All-The-Things!" related to namespaces not having a leading backslash.

This issue is "only" about incorrect namespaces in @tags (like @var, @see, @return).

Within this issue there are basically two categories:

  1. Non-existing namespaces
  2. Existing namespaces without a leading backslash

I agree with being burned before on non-sniff changes, so I created a sniff for 2. here: #3281300: @param tags must use fully-qualified class names, even when the full namespace is given without the leading backslash..

That sniff (if it is approved) will only fix a few of our issues (currently 22 to be exact), but the added value is that the changes are validated against the namespaces in the use-block of the Class.
That gives us the certainty that, at the moment of a sniff error and fix, the changed namespace actually exists.

I don't think any sniff/script can do that for all the missing backslash namespaces that float around, so IMHO although this is just a small improvement, the changes that are made with the sniff are, at the moment of changing, checked, which is a (small) win.

Let's await the approval of the sniff first, and landing of a version of drupal/coder that contains that sniff in Drupal Core first, before continuing here.

If it lands, there will be plenty un-sniffed changes left, but less is more!

spokje’s picture

Title: Undefined namespaces in PHP DocBlocks » [PP-1] Undefined namespaces in PHP DocBlocks
Status: Needs work » Postponed
spokje’s picture

Status: Postponed » Closed (outdated)