Closed (fixed)
Project:
Drupal core
Version:
11.x-dev
Component:
composer
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
2 Nov 2024 at 20:28 UTC
Updated:
13 May 2026 at 07:45 UTC
Jump to comment: Most recent
Regenerating the baseline is documented here but I always forget the exact commands and have to look them up.
phpstan-baseline script to the root composer.json so you can just run composer phpstan-baseline when needed.phpstan, so you can run composer phpstanStart 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
nicxvan commentedIs there a way to overwrite the current baseline with this starter file?
It runs much more consistently and with lower memory starting empty:
Comment #3
berdirThis would definitely be useful. I've added ddev commands for now:
And a phpstan without the --generate-baseline.
Comment #4
mstrelan commentedI think we should drop the word "generate" and just have:
I think we should also use these commands in ci for consistency. Then if we need to tweak it in future it will be updated in both places.
Comment #5
berdirthe CI job runs phpstan like 3 times with different output formats and arguments, so I don't think we can reuse that.
Comment #6
nicxvan commentedI figured out why I needed the empty baseline.
It was because during the conversion there were thousands of changes. A normal baseline process doesn't need that.
Comment #7
mondrakeAdding related issue
Comment #9
andypostit also require to set memory limit
Comment #11
longwaveAfter copy-pasting for the nth time I remembered about this issue.
You can now run phpstan on file(s)
or generate the baseline:
Comment #12
mstrelan commentedFor my setup I need to also set the memory limit to -1. Should we include that here too?
Comment #13
longwaveOK, done.
Comment #14
longwaveComment #15
longwaveI didn't realise phpstan had the option itself, thanks!
Comment #16
mstrelan commentedI would RTBC but can't do the T part until next week
Comment #17
dcam commentedThis is kind of funny. First, because I had no idea the phpcs/phpcbf commands existed in the composer.json file. I guess I don't spend much time looking at it. Second, because I just use good ol' bash aliases. The recent mock object issues prompted me to finally add entries for PHPStan alongside the aliases for other CLI utilities when I had to regenerate baselines so often. So this is pretty fresh in my mind.
But putting them in Composer is good! I'm sure it will save someone time down the road. Especially if anyone ends up on a fresh dev environment for any reason (I'm thinking ahead to when this laptop needs to be replaced). They'll always be here for us.
Anyway, the new commands exactly match the examples given in our own PHPStan in Core documentation. I tested them all (including the old ones) out on my local environment. They worked just like I expected based on my experience with my old aliases. LGTM.
Comment #18
benjifisherI am updating the issue summary to match the MR that is now RTBC.
Comment #19
quietone commentedEverything has been addressed here and I have updated credit.
Comment #20
alexpottCommitted and pushed fd70826e021 to main and 567eff6ff11 to 11.x. Thanks!
Comment #24
wim leersFYI (in case this helps some contrib module maintainer): Canvas did something similar a few months ago over at #3575399: DX+CI: Add `composer run phpstan-regenerate-ignores-for-11.3-and-higher` — to simplify updating baseline errors due to PHPStan running on 11.2, fail CI job if out of sync — although Canvas' baseline is intentionally different: Canvas started with PHPStan level 8 (so in principle: empty baseline).
Many contrib modules — including Canvas — target some core minor as the minimum supported version. For Canvas, that's 11.2.x. And of course, like any contrib module, we try to be as forward-compatible as possible. That means for example already providing a
default_contentevent subscriber. Which in turn triggers PHPStan errors (because we execute PHPStan against the minimum supported core version — 11.2.x in our case).So, Canvas' baseline is specifically for PHPStan errors specific to upcoming Drupal core versions. For example:
Canvas provides
composer run phpstan-regenerate-ignores-for-11.3-and-higherto simplify keeping this up-to-date.See #3575399: DX+CI: Add `composer run phpstan-regenerate-ignores-for-11.3-and-higher` — to simplify updating baseline errors due to PHPStan running on 11.2, fail CI job if out of sync.