Problem/Motivation
I get a large PHPStan error when trying to run against some custom modules but the important part is this:
UnexpectedValueException thrown in /Users/xxx/Sites/mysite/vendor/nette/finder/src/Utils/Finder.php on line 209 while loading bootstrap file /Users/xxx/Sites/mysite/vendor/mglaman/phpstan-drupal/drupal-autoloader.php: RecursiveDirectoryIterator::__construct(/Users/xxx/Sites/mysite/core/includes): failed to open dir: No such file or directory
My issue is /Users/xxx/Sites/mysite/core/includes indeed DOES NOT exist because my vendor folder lives above docroot. If that path was correct, it would be /Users/xxx/Sites/mysite/docroot/core/includes
This got me investigating the package mglaman/phpstan-drupal. Specifically src/Drupal/DrupalAutoloader.php line 70.
$drupalRoot = $finder->getDrupalRoot(); which equates to /Users/xxx/Sites/mysite/
Then the code goes on to define $this->drupalRoot = $drupalRoot; so what I did was:
$this->drupalRoot = $drupalRoot . '/docroot'; and this fixed the PHPStan error and it was able to check the modules successfully.
Steps to reproduce
Have your vendor folder outside of docroot and try to scan a module. PHPStan will fail.
Proposed resolution
Not sure if this is a bug relating to mglaman/phpstan-drupal, but it would be nice if we could have optional fields to override where docroot actually is.
Comments
Comment #2
mglamanSee #3229725: Warn if site's composer.json is named "drupal/drupal" but is a Composer build.
What is the
nameproperty in your root composer.json? If it's drupal/drupal, then the webflo/drupal-finder project will assume you're NOT using a Composer build and use the wrong directory.See the relevant code here in drupal-finder: https://github.com/webflo/drupal-finder/blob/master/src/DrupalFinder.php...
And specifically this comment which resolved another user's error:
#3229725-17: Warn if site's composer.json is named "drupal/drupal" but is a Composer build
Comment #3
rondog469 commentedah, yes, my composer.json name is indeed drupal/drupal. So renaming that would have solved my issue is what you are saying? That is interesting and I would have never guessed that.
Comment #4
mglaman@rondog469 Renaming would have solved, and I would have never guessed it either. Until I spent some time on a screen share helping someone resolve their upgrade errors around this. That's why I want to get a warning added to Upgrade Status.
Are you able to give this a try later and verify? Such as changing it to
"name": "agency/client"Comment #5
rondog469 commentedI have already upgraded that project using my method I initially posted, but I have tons of other sites that I am still in the process of upgrading so when I run into another site where composer is not in the docroot I will try and surely update you. Thanks for the reply! I posted this same question on your github issue queue so you can ignore that one and just point to this thread.
Comment #6
gábor hojtsyMarking duplicate of #3229725: Warn if site's composer.json is named "drupal/drupal" but is a Composer build then.