phpstan-drupal icon indicating copy to clipboard operation
phpstan-drupal copied to clipboard

If Drupal cannot be detected, fallback to using Composer to detect the installed path

Open mglaman opened this issue 2 years ago • 2 comments

Feature request

Various hacks are needed if drupal/core is in the vendor directory. The drupal-finder package doesn't support this (and probably shouldn't.) But we can in the autoloader: https://github.com/mglaman/phpstan-drupal/blob/main/src/Drupal/DrupalAutoloader.php#L60-L69

        $drupalRoot = $finder->getDrupalRoot();
        $drupalVendorRoot = $finder->getVendorDir();
        if (! (bool) $drupalRoot || ! (bool) $drupalVendorRoot) {
            throw new \RuntimeException("Unable to detect Drupal at {$drupalParams['drupal_root']}");
        }

Instead of throwing a runtime exception here, try using Composer's installed paths to find drupal/core:

\Composer\InstalledVersions::getInstallPath('drupal/core')

Then less hacks are needed.

mglaman avatar Nov 11 '23 17:11 mglaman

See https://github.com/webflo/drupal-finder/pull/64

mglaman avatar Nov 13 '23 14:11 mglaman

I've added a PR to provide a temp workaround https://github.com/mglaman/phpstan-drupal/pull/702

AlexSkrypnyk avatar Jan 05 '24 07:01 AlexSkrypnyk