Issue summary generated with the help of an LLM.

Problem/Motivation

PHPStan currently flags several class.notFound errors across Drupal core where a @return PHPDoc annotation specifies a class is not found. This mostly points to misnamed FQN.

Those are candidates for easy fixes, and also remove some related issues from the baseline automatically.

Proposed resolution

  • Review all methods and functions flagged with class.notFound and fix them
  • Regenerate core/.phpstan-baseline.php to remove the resolved class.notFound entries.

Remaining tasks

  • Fix all class.notFound occurrences in core.
  • Regenerate core/.phpstan-baseline.php.
  • Verify PHPStan passes in GitLab CI.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork drupal-3641794

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

mallezie created an issue. See original summary.

mallezie’s picture

Status: Active » Needs review

Left out here are class.notFound issues in lib/Drupal/Core/Mailer
Those will need a seperate issue, since those require more non-trivial changes.

Most changes here, relate to updating incorrect phpdoc comments which reference incorrect classes.

One question here is, i've included changes for the Doctrine/Annotation fork which is pulled in drupal, might be better to ignore that component from phpstan, since this will be removed completely in D13 IIRC.

mstrelan’s picture

Status: Needs review » Needs work

Thanks for working on this. It looks pretty close, and should remove 227 violations from the baseline, mostly class.notFound (167). I just left some feedback on a few points.

znerol’s picture

Mailer should be fine with this change I believe:

diff --git a/core/lib/Drupal/Core/Mailer/TransportServiceFactory.php b/core/lib/Drupal/Core/Mailer/TransportServiceFactory.php
index 8950d44e364..fde81d977df 100644
--- a/core/lib/Drupal/Core/Mailer/TransportServiceFactory.php
+++ b/core/lib/Drupal/Core/Mailer/TransportServiceFactory.php
@@ -19,7 +19,7 @@ class TransportServiceFactory implements TransportServiceFactoryInterface {
   /**
    * Constructs a new transport service factory.
    *
-   * @param Iterable<TransportFactoryInterface> $factories
+   * @param Iterable<\Symfony\Component\Mailer\Transport\TransportFactoryInterface> $factories
    *   A list of transport factories.
    * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
    *   The config factory service.
diff --git a/core/lib/Drupal/Core/Mailer/TransportServiceFactoryTrait.php b/core/lib/Drupal/Core/Mailer/TransportServiceFactoryTrait.php
index c4aa2c736a4..76d474b56c0 100644
--- a/core/lib/Drupal/Core/Mailer/TransportServiceFactoryTrait.php
+++ b/core/lib/Drupal/Core/Mailer/TransportServiceFactoryTrait.php
@@ -16,7 +16,7 @@ trait TransportServiceFactoryTrait {
   /**
    * A list of transport factories.
    *
-   * @var Iterable<TransportFactoryInterface>
+   * @var Iterable<\Symfony\Component\Mailer\Transport\TransportFactoryInterface>
    */
   protected iterable $factories;