Skip to content

Migrate DrupalAutoloader off deprecated drupal-finder v1 APIs #962

@mglaman

Description

@mglaman

Problem

src/Drupal/DrupalAutoloader.php uses DrupalFinder\DrupalFinder and its locateRoot() method, which were deprecated in drupal-finder 1.3.0 and removed in 2.0.0. Currently phpstan-baseline.neon suppresses 5 errors related to this usage:

  • Call to deprecated method locateRoot() of class DrupalFinder\DrupalFinder
  • Instantiation of deprecated class DrupalFinder\DrupalFinder
  • Two type mismatch errors caused by the old API returning bool|string

When the composer constraint eventually allows drupal-finder 2.x, this will cause a hard runtime crash during analysis.

Proposed resolution

Replace DrupalFinder\DrupalFinder with DrupalFinder\DrupalFinderComposerRuntime, which accepts a starting path in its constructor and provides the same getDrupalRoot() / getVendorDir() methods without the deprecated locateRoot() call.

// Before
$finder = new DrupalFinder();
$finder->locateRoot(getcwd());
$this->drupalRoot = $finder->getDrupalRoot();

// After
$finder = new DrupalFinderComposerRuntime();
$this->drupalRoot = $finder->getDrupalRoot();

After migrating, the 5 baseline suppressions in phpstan-baseline.neon for DrupalAutoloader.php should be removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions