Problem/Motivation

In PHPStorm there is an inspection for Undefined Classes, which currently has quite a lot of failures.

Undoubtedly, PHPStan will warn us at some point about them, but let's not wait until then.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3313038

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.

longwave’s picture

Is there no PHPCS or Coder sniff for this?

spokje’s picture

Is there no PHPCS or Coder sniff for this?

Apparently not...
One of them was caught by PHPStan Level 0, but that's about it.

longwave’s picture

Also is this a dupe of your own issue? :) #3226198: [PP-1] Undefined namespaces in PHP DocBlocks

spokje’s picture

Also is this a dupe of your own issue? :) #3226198: [PP-1] Undefined namespaces in PHP DocBlocks

Hmmm, I _knew_ I did something similar, but couldn't find it again.

It's not _exactly_ the same, but very close. Unsure if I should close the original one, since that's very out of date by now.

Also, as said in the IS, I don't _think_ we need to wait for a Rule in Coder, since it will be caught by PHPStan at some point/level.
Fixing some/most of them now improves DX IMHO.

spokje’s picture

mondrake’s picture

It's a pity that the coding standards say

Immediately after an @tag (@param, @return, @var, etc.), class and interface names must always include the fully-qualified namespace.

(even though I can't google that, I only see that referred in #3250534: @param tags not using a fully-qualified class names are not reported)

That's limiting readibility IMHO. Other packages use the use statements to import the FQCNs, and their PHPDoc only refer to the class name. PHPStan fully supports that.

So something like this

--- a/composer/Plugin/VendorHardening/Config.php
+++ b/composer/Plugin/VendorHardening/Config.php
@@ -84,7 +84,7 @@ class Config {
   /**
    * The root package.
    *
-   * @var Composer\Package\RootPackageInterface
+   * @var \Composer\Package\RootPackageInterface
    */
   protected $rootPackage;
 

would become something like this

--- a/composer/Plugin/VendorHardening/Config.php
+++ b/composer/Plugin/VendorHardening/Config.php
@@ -84,7 +84,7 @@ class Config {
   /**
    * The root package.
    *
-   * @var Composer\Package\RootPackageInterface
+   * @var RootPackageInterface
    */
   protected $rootPackage;
 

that is, BTW, also what would happen once the property will be typehinted instead of annotated.

spokje’s picture

Status: Active » Needs review
spokje’s picture