rector: Can't load mglaman/phpstan-drupal as the DI container is not available

Bug Report

Subject Details
rector/rector v0.15.17
palantirnet/drupal-rector v0.15.0
phpstan/phpstan v1.10.0
mglaman/phpstan-drupal v1.1.29

I had mglaman/phpstan-drupal already installed and working and now installed palantirnet/drupal-rector as well. When executing vendor/bin/rector I get the following error message:

 [ERROR] "PHPStan\ShouldNotHappenException" thrown in                                                                   
         "/var/www/html/vendor/mglaman/phpstan-drupal/drupal-autoloader.php" on line 7 while loading bootstrap file     
         /var/www/html/vendor/mglaman/phpstan-drupal/drupal-autoloader.php: The autoloader did not receive the          
         container.

By adding some printf() outputs I could break this down to Rector\NodeTypeResolver\DependencyInjection\PHPStanExtensionsConfigResolver::resolve() detecting the drupal-autoloader.php of mglaman/phpstan-drupal. But that fails if the variable $container isn’t set correctly, which here is the case.

Minimal PHP Code Causing Issue

No custom PHP code is required to cause this issue, just install the packages in the versions mentioned above.

Expected Behaviour

When resolving the extensions, simply skip mglaman/phpstan-drupal.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 18 (10 by maintainers)

Most upvoted comments

@mfrieling @agentrickard The patch need to be in palantirnet/drupal-rector, with update:

-    $rectorConfig->bootstrapFiles([
+    $rectorConfig->autoloadPaths([
        __DIR__ . '/../drupal-phpunit-bootstrap-file.php'
    ]);

in both of files:

  • palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.php
  • palantirnet/drupal-rector/config/drupal-9/drupal-9-all-deprecations.php

we need failing test case repository which you need to invest the time so it can be fixed correctly 😃