Problem/Motivation

Reported by Ondřej Mirtes in Slack, PHPStan 2.2.13 has performance improvements:

2.2.8
composer phpstan  333.87s user 74.49s system 675% cpu 1:00.43 total

2.2.13
composer phpstan  285.42s user 24.15s system 752% cpu 41.122 total

Steps to reproduce

Proposed resolution

Update to PHPStan 2.2.13, also bump mglaman/phpstan-drupal while we're there.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3621326

Command icon 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

longwave created an issue. See original summary.

mondrake’s picture

composer update mglaman/phpstan-drupal phpstan/extension-installer phpstan/phpstan phpstan/phpstan-deprecation-rules phpstan/phpstan-phpunit

would update the whole bunch of PHPStan extensions

longwave’s picture

I did the other ones over in #3621275: Update Composer dependencies for 12.0.0-beta1 - everything there updates cleanly.

longwave’s picture

In fact maybe only the Drupal extensions are the problem here, maybe we can upgrade PHPStan itself in the other issue.

edit: no, see https://git.drupalcode.org/project/drupal/-/jobs/12034440

longwave’s picture

Status: Active » Needs review

The improvement is significant.

2.2.8 took about two minutes for a full run: https://git.drupalcode.org/project/drupal/-/jobs/11964790
2.2.13 takes 33 seconds: https://git.drupalcode.org/project/drupal/-/jobs/12034563

longwave’s picture

Unsure if we want to fix any of those new baselined errors here, a lot of them seem non trivial.

godotislate’s picture

Status: Needs review » Needs work

Merge conflict bc #3621275: Update Composer dependencies for 12.0.0-beta1 is in. (Gitlab UI strangely not showing even it says there's a conflict if I try to rebase.)

Also, do we need to wait on https://github.com/phpstan/phpstan/issues/15192?

longwave’s picture

Status: Needs work » Needs review

Rebased. The GitLab UI has been a bit laggy recently, it takes some minutes to update after something has been pushed.

I don't think we need to wait for that issue, it emits the warning but it appears it can be safely ignored.

godotislate’s picture

Status: Needs review » Reviewed & tested by the community

Ran composer require "mglaman/phpstan-drupal":"^2.1.2" "phpstan/phpstan":"^2.2.13" --dev and regenerated baseline and got the same changes.

lgtm

mstrelan’s picture

That's a few baseline additions. Maybe we should combine this with #3425412: [mid-Oct 2026] Bump PHPStan rule level to 3?

longwave’s picture

I think we should backport this to 11.x for the speed improvements alone, we won't bump the level there though.

mstrelan’s picture

IMHO if most of the baseline changes come from mglaman/phpstan-drupal we should split that out and review it separately so we can get the speed changes in without too much conflict.

longwave’s picture

@mstrelan we have very little time left until 12.0.0-beta1 and so I think adding to the baseline here is the pragmatic thing to do, breaking this down further just risks missing the deadline, and it's already RTBC.

mstrelan’s picture

Ok that's fine, I was just trying to avoid having two separate issues making large baseline changes to avoid conflicts, but happy to proceed.

longwave’s picture

Additionally I don't think the level 3 issue should land until after beta because it will likely disrupt many if not most open MRs.

catch’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed/pushed to main, thanks!

Moving to 11.x for backport.

catch’s picture

Version: 11.x-dev » main
Status: Patch (to be ported) » Needs work

No actually the commit never went through - three new errors introduced, I think we need a baseline update here again.

  • catch committed 6d6a6419 on main
    task: #3621326 Update to PHPStan 2.2.13
    
    By: longwave
    By: godotislate
    By...
catch’s picture

Version: main » 11.x-dev
Status: Needs work » Patch (to be ported)

Went ahead and regenerated the baseline locally and committed.

Back to 11.x for backport again.

The is_file() warning is noisy, but it's not affecting the CI job pass and I saw a fix got committed for it already, we can update to the next patch release when it comes out.

Had to do the actual commit with --no-verify because phpcs didn't like having nothing to analyse.

mondrake’s picture

#20 the bug upstream was fixed

https://github.com/phpstan/phpstan/issues/15192
https://github.com/phpstan/phpstan-src/pull/6397

It should be matter of days before a 2.2.14 will be out and we can bump to it.

longwave’s picture

Status: Patch (to be ported) » Needs review
catch’s picture

PHPStan is failing on main with https://git.drupalcode.org/project/drupal/-/jobs/12129494

------ ---------------------------------------------------------------------- 
  Line   core/tests/Drupal/KernelTests/Core/Entity/EntityLanguageTestBase.php  
 ------ ---------------------------------------------------------------------- 
  68     A file could not be loaded from                                       
         Drupal\Core\Extension\ModuleHandlerInterface::loadInclude             
         🪪  loadIncludes.fileNotLoadable                                      
 ------ ---------------------------------------------------------------------- 
catch’s picture

Passed with a re-run, not really sure what that means...

longwave’s picture

Hm there is something flaky going on here, look at the last commit where I had to baseline something additional like that, and now it's failed again.

longwave’s picture

Status: Needs review » Needs work
longwave’s picture

Maybe we can globally ignore loadIncludes.fileNotLoadable while we work this out?

catch’s picture

Yes I've just seen it again too - going to revert. Globally ignoring and then opening an issue (against phpstan probably) sounds good.

  • catch committed 2f56cc33 on main
    Revert "task: #3621326 Update to PHPStan 2.2.13"
    
    This reverts commit...
catch’s picture

Version: 11.x-dev » main
Status: Needs work » Needs review
catch’s picture

Status: Needs review » Needs work
mondrake’s picture

2.2.14 was released today

catch’s picture

Title: Update to PHPStan 2.2.13 » Update to PHPStan 2.2.14

quietone made their first commit to this issue’s fork.

quietone changed the visibility of the branch 3621326-update-to-phpstan to active.

quietone’s picture

Status: Needs work » Needs review
quietone’s picture

11.x has a failure in Drupal\Tests\Core\Test\WorkAllocatorTest::testAllocator which I don't know enough about and I am concentrating on other things right now.

catch’s picture

11.x is fixed now - was an HEAD failure due to a test-only backport. Rebased and the 11.x is green.

So I think it is just the main MR to update now.

quietone’s picture

I forgot to comment that I updated the main branch. That was a few hours ago. But I rebased again, because why not?

mondrake’s picture

Status: Needs review » Needs work

Unless I am missing something, I do not see #28/#29 addressed. Or maybe it's no longer a problem?

catch’s picture

The 11.x branch has https://git.drupalcode.org/project/drupal/-/merge_requests/17087/diffs?c... which looks like it should resolve it.

But I don't see that in the main commit.

quietone’s picture

Status: Needs work » Needs review
Related issues: +#3624168: [upstream, likely] Fix loadIncludes.fileNotLoadable phpstan violations

Darn! Added an ignore with an @todo in phpstan.neon.dist

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new631 bytes

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

quietone’s picture

Status: Needs work » Needs review

No, the diff applies.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new631 bytes

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

quietone’s picture

Status: Needs work » Needs review
Issue tags: +no-needs-review-bot
mondrake’s picture

It feels weird that in main we need a global ignore, whereas in 11.x not? Is there a difference in the code analysed?

catch’s picture

Status: Needs review » Reviewed & tested by the community

I checked the new baseline entries and it's mostly:

+$ignoreErrors[] = [
+	'message' => '#^Storing entity storage as a class property is not recommended\\. Call Drupal\\\\Core\\\\Entity\\\\EntityTypeManagerInterface\\:\\:getStorage\\(\\) at the call\\-site instead\\.$#',
+	'identifier' => 'drupal.entityStoragePropertyAssignment',
+	'count' => 1,
+	'path' => __DIR__ . '/modules/ckeditor5/src/Plugin/CKEditor5Plugin/MediaLibrary.php',
+];

This is something we should clean up so it's a valid new entry.

This all looks good to me now.

catch’s picture

The 11.x branch had the ignore at least a couple of days ago, but my link to it is breaks the gitlab UI... https://git.drupalcode.org/project/drupal/-/merge_requests/17087/diffs?c...

catch’s picture

Oh in 11.x they're individually added to the baseline, either that changed or I read it incorrectly:

$ignoreErrors[] = [
	'message' => '#^A file could not be loaded from Drupal\\\\Core\\\\Extension\\\\ModuleHandlerInterface\\:\\:loadInclude$#',
	'identifier' => 'loadIncludes.fileNotLoadable',
	'count' => 1,
	'path' => __DIR__ . '/tests/Drupal/KernelTests/Core/Entity/EntityLanguageTestBase.php',
];

I think we need to add the global ignore to 11.x too then. Leaving RTBC since we could probably change that as part of the backport.

godotislate’s picture

Status: Reviewed & tested by the community » Needs review

In the 11.x MR mglaman/phpstan-drupal is bumped to 2.2.0, and it's only 2.1.2 on main. I think these two should probably be in sync as well? There's also a 2.2.1 release as of today, so it might be easier to bump both of them to that.

godotislate’s picture

OK, bumped both MRs so they're in sync at mglaman/phpstan-drupal 2.2.1, and added the global ignore to 11.x.
This introduced some new baseline entries in the main MR. Also needed to manually update PinnedDevDependencies, since the builder was removed from main.

catch’s picture

Status: Needs review » Reviewed & tested by the community

I re-reviewed all the changes except the baseline (which I did review a bit before the most recent update from @godotislate), I think this is ready to commit again.

mondrake’s picture

I am still confused by the need to add a global ignore instead of adding to the baseline the actual errors - and for main only. To me it means the baseline would not be deterministic, and there would be random occasions where the error is reported and other not, which would be a primer in static analysis. Is that the case, can't we just add to the baseline as in 11.x?

godotislate’s picture

@mondrake latest update to 11.x has the same global ignore, noted in #54.

catch’s picture

@mondrake after the initial commit here we started to get seemingly random phpstan failures on various MRs, for example:

  Line   core/tests/Drupal/KernelTests/Core/Entity/EntityLanguageTestBase.php  
 ------ ---------------------------------------------------------------------- 
  68     A file could not be loaded from                                       
         Drupal\Core\Extension\ModuleHandlerInterface::loadInclude             
         🪪  loadIncludes.fileNotLoadable       

in https://git.drupalcode.org/project/drupal/-/jobs/12129494

Not every MR was affected but several were, iirc the errors were showing up in different tests on the MRs that failed too.

phpstan recently introduced a native PHP extension which is swapped in at runtime for child processes, maybe this (or something else new in this release) is struggling with includes - most modern PHP applications don't dynamically include files outside of autoloading, so it would be quite possible that what is for us a backwards compatibility layer is the only, or at least first, code that's hitting the bug.

#3624168: Fix loadIncludes.fileNotLoadable phpstan violations is open to look into this more, and we can try removing the global ignore there, see if we can get an MR run to fail. We could also try an experiment and remove the global ignore in HEAD too via that issue if that will help track down the problem and we can't reproduce on MR runs. But what I really don't want to do is introduce 80% random test failures when we're desperately trying to tag the beta alongside having dozens of RTBC issues in the queue.

mondrake’s picture

Sure, thanks for explaining!

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
godotislate’s picture

Status: Needs work » Reviewed & tested by the community

Both MRs rerolled and main baseline regenerated.

  • larowlan committed d3c27c1c on main
    task: #3621326 Update to PHPStan 2.2.14
    
    By: longwave
    By: mondrake
    By:...

  • larowlan committed b8c748bf on 11.x
    task: #3621326 Update to PHPStan 2.2.14
    
    By: longwave
    By: mondrake
    By:...
larowlan’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed to main and 11.x - thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.