rector: Unexpected behavior when using `-e` option

Bug Report

Subject Details
Rector version 0.7.3 (invoke vendor/bin/rector --version)
Installed as prefixed Rector PHAR

Minimal PHP Code Causing Issue

I don’t know how to create a small demo from this.

I created 3 very similar tests using Github Actions, that demonstrate the issue: The demo is using Drupal and a module called metatag. When testing a certain path in this module there’s another library missing drupal/console.

 [OK] Rector is done!                                                           
 [ERROR] Could not process                                                      
         "/home/runner/work/rector/rector/test-paths/drupal-rector073/web/module
         s/contrib/metatag/src/Generator/MetatagGroupGenerator.php" file, due   
         to:                                                                    
         "Analyze error: "Class Drupal\Console\Core\Generator\Generator not     
         found and could not be autoloaded.". Include your files in "parameters 
         > autoload_paths".                                                     
         See https://github.com/rectorphp/rector#extra-autoloading".            

 [ERROR] Could not process                                                      
         "/home/runner/work/rector/rector/test-paths/drupal-rector073/web/module
         s/contrib/metatag/src/Generator/MetatagTagGenerator.php" file, due to: 
         "Analyze error: "Class Drupal\Console\Core\Generator\Generator not     
         found and could not be autoloaded.". Include your files in "parameters 
         > autoload_paths".                                                     
         See https://github.com/rectorphp/rector#extra-autoloading".            
 use Drupal\Console\Core\Generator\Generator;
 use Drupal\Console\Extension\Manager;
 use Drupal\Console\Core\Utils\TwigRenderer;
-
 /**
  * Drupal Console plugin for generating a group.
  */
-class MetatagGroupGenerator extends Generator {
-
-  /**
-   * The console manager.
-   *
-   * @var \Drupal\Console\Extension\Manager
-   */
-  protected $extensionManager;
-
-  /**
-   * The twig renderer.
-   *
-   * @var \Drupal\Console\Core\Utils\TwigRenderer
-   */
-  protected $renderer;
.
.
.
...

Expected Behaviour

When using -e option, I expect Rector to skip the files that are missing, without printing additional errors, but also without applying a code linting rule.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Looking at option e now, it was added to improve working with legacy projects that misses autoloading.

Yet, nowadays Rector and PHPStan that we use here 100 % needs classes to be autoloaded, so the e option willl be dropped. It only creates false positive bugs that cannot be solve without autoloading. PHPStan has same approach and shows these errors.