Problem/Motivation
My composer is in /app, the website is in /app/docroot, but the phpstan stuff is apparently trying to find Drupal core stuff in /app/core/includes instead of /app/docroot/core/includes. I cannot for the life of me figure out where that's coming from.
PHPStan command failed:
/app/vendor/bin/phpstan analyse --error-format=json -c /tmp/upgrade_status/deprecation_testing.neon /app/docroot/modules/custom/nodesymlinks_tng 2> /tmp/upgrade_status/phpstan_error_outputCommand output:
Empty.Command error:
UnexpectedValueException thrown in /app/vendor/nette/finder/src/Utils/Finder.php on line 209 while loading bootstrap file /app/vendor/mglaman/phpstan-drupal/drupal-autoloader.php: RecursiveDirectoryIterator::__construct(/app/core/includes): failed to open dir: No such file or directory
How can I find out where that's coming from? If it makes any difference, I'm running this locally in Lando using the Acquia recipe, but another site set up the same way worked fine.
This is what's in that .neon file, which looks right to me:
/app$ more /tmp/upgrade_status/deprecation_testing.neon
# FROM mglaman/drupal-check/phpstan/deprecation_testing.neon
parameters:
tmpDir: '/tmp/upgrade_status/phpstan'
drupal:
drupal_root: '/app/docroot'
customRulesetUsed: true
ignoreErrors:
- '#\Drupal calls should be avoided in classes, use dependency injection instead#'
- '#Plugin definitions cannot be altered.#'
- '#Missing cache backend declaration for performance.#'
- '#Plugin manager has cache backend specified but does not declare cache tags.#'
# FROM mglaman/drupal-check/phpstan/base_config.neon
reportUnmatchedIgnoredErrors: false
excludePaths:
- */tests/Drupal/Tests/Listeners/Legacy/*
- */tests/fixtures/*.php
- */settings*.php
- */bower_components/*
- */node_modules/*
includes:
- '/app/vendor/mglaman/phpstan-drupal/extension.neon'
- '/app/vendor/phpstan/phpstan-deprecation-rules/rules.neon'| Comment | File | Size | Author |
|---|---|---|---|
| #27 | Screen Shot 2021-10-13 at 3.58.55 PM.png | 99.25 KB | mglaman |
| #21 | 3229725.patch | 1006 bytes | gábor hojtsy |
| #7 | composer.json_.txt | 4 KB | seanr |
Issue fork upgrade_status-3229725
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
Comment #2
seanrComment #3
gábor hojtsyIt looks like the autoloader in phpstan-drupal is identifying the wrong directory. Will ping @mglaman to check this out. Are there multiple composer.json files in the project? That could confuse finding where the root is.
Comment #4
mglamanPHPStan Drupal is using
webflo/drupal-finderunder the hood to find the Drupal root location.What I find is more odd is that this isn't being respected
I'll make some time to look into this over the next few days. As stated in #3, multiple composer.json could be confusing it. But it shouldn't "care" since
drupal_rootis defined.Comment #5
seanrFYI, we only have one composer.json in the project root, appart from those included in modules. There isn't one in docroot.
Comment #6
mglamanInteresting. The DrupalFinder should take
/app/docrootand find the Drupal root (given directory) and vendor directory fine. The vendor directory seems to be discovered just fine as well.PHPStan Drupal should kill early if there were big errors. https://github.com/mglaman/phpstan-drupal/blob/main/src/Drupal/DrupalAut...
Then there is this: https://github.com/mglaman/phpstan-drupal/blob/548fa7cb31239997863bf695f...
Is the project a Composer template? Did someone symlink
webtodocrootinstead of modifying the scaffolding directories?Comment #7
seanrSomeone want to tell me why I can't just upload a .json file without changing the extension? Ugh.
I've attached my composer.json. We do not have a symlink involved (though we've got some other sites where that was done before I got there for whatever reason - what issues can we expect from that?).
Comment #8
mglamanI don't think any, but just asking.
Question: what happens when you run
drupal-checkversus upgrade status?So
Drupal Check is a custom PHPStan runner just like Upgrade Status. Just a CLI and not module. If drupal-check is OK then something weird is happening in Upgrade Status
Comment #9
seanrYeah, I snagged that while debugging this, was meaning to try that (for the first one of these for another site, I got both side-by-side to compare results and confirmed they matched).
Comment #10
seanrSame crud:
Comment #11
gábor hojtsyMaking title more specific.
Comment #12
seanrWondering if there's anything in particular I should try to help debug this? Happy to try anything since it's all local development anyway, just don't know quite where to start.
Comment #13
mglaman@seanr I wish I knew :/. Does lando let you do Xdebug over the CLI? I would try dropping a breakpoint on
$finder->locateRoot($drupalRoot);and see why it gets confused.Comment #14
dvmanjunath commented@mglaman @gábor-hojtsy i'm also facing same issue. But in my case i'm using docksal instead of lando but error is same. Same error when i tried to do drupal-check and rector as well.
It's looking for code at
/var/www/core/includesinstead /var/www/docroot/core/includesComment #15
gábor hojtsyI believe @mglaman tracked this down:
https://twitter.com/nmdmatt/status/1432735316952166401
There does not seem to be a webflo/drupal-finder issue yet though at https://github.com/webflo/drupal-finder/issues
Comment #16
mglamanI don't think this requires a fix in webflo/drupal-finder. Upgrade Status may need to warn users that they haven't modified their composer "name" property. Or that it says drupal/drupal but is a composer build.
Basically, upgrade_status can detect the error itself by running the finder and seeing if it errors as a preflight check.
Comment #17
dvmanjunath commented@mglaman @gábor-hojtsy Thanks a lot. after changing "name": "drupal/drupal" to "name": "drupal/project_specific_name" has worked.
Comment #18
mglamanRetitling and moving to Task. This can be an environment check to prevent phpstan-drupal failures.
Comment #19
mglamanComment #20
mglamanLinking to #3239749-3: Install issues w/ symfony/css-selector. I wonder if we need more preflight Composer checks as well.
Comment #21
gábor hojtsyAre we looking for something like this? I tried wording it in a way that people could also understand it as "wrong composer file found" in case they have multiple, and would not necessarily blindly fix the wrong one found. To be honest not sure how to know if we found a "wrong" composer file though? Do we have fingerprinting ways (look for presence of specific keys)?
On the other hand, looking at #3239749: Install issues w/ symfony/css-selector it looks like a pre-Drupal problem with composer, so we cannot add helpful guidance into the module for that.
Comment #23
gábor hojtsyOk LOL this fails on CI with
So if CI has this template and it still works, not sure why it fails for others? Are there other conditions besides the name value that would lead to the failure?
Comment #24
mglamanCI doesn't have Drupal has a Composer build, but full development trunk clone.
We need to check if the name is drupal/drupal AND it's a Composer build.
My thought was a preflight check which runs webflo/drupal-finder and sees if it fails.
Comment #26
mglamanAdded code to check if the
coredirectory cannot be found. If it cannot we try to load the composer.json and check the name property. Added extra warnings along the way to try and bring clarity to this obscure bug.Comment #27
mglamanI added commit https://git.drupalcode.org/project/upgrade_status/-/merge_requests/13/di... after reading #3230781: Scan and Export buttons are not-clickable. We can split off into a new one, but my dev stream was coming to a close. I opted to push up rather than let it sit for a week.
This makes it a bit more prominent as to why scans cannot be run.
Comment #28
gábor hojtsyI think displaying the dedicated error at the bottom is a very good idea. I think it would still be a good idea to ALSO add the error to the (top/global) messages list. Otherwise some people may end up processing (in their head) the output, picking which ones to scan, etc. just to end up at the bottom where the form tells them it was in vain. So I think displaying the error up top would still be useful. I think displaying it at the bottom is useful for people with banner blindness though :)
I think this would be a matter of not removing that one line where it is added to messages :D
Comment #29
mglamanPerfect! I'll put that back on Wednesday
Comment #30
gábor hojtsyComment #31
gábor hojtsyCommitted this one, thanks a lot!