rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.78k stars 687 forks source link

How to add an autoload file? #1658

Closed vinioo closed 5 years ago

vinioo commented 5 years ago

Hello! I'm trying to run rector but i'm getting the following message: "Class x was not found while trying to
analyse it - autoloading is probably not configured properly.". Include your files in "parameters > autoload_paths".

What should i do? I tried to add a autoload file but i dont get it right. Thanks

vinioo commented 5 years ago

I'm running through docker

TomasVotruba commented 5 years ago

Hi, what happens what you try --autoload-file from README? https://github.com/rectorphp/rector#extra-autoloading

I don't use Docker, but @JanMikes might help you

JanMikes commented 5 years ago

Hi @vinioo what class is it please? Is it your class? Is it vendor class? Is it class that is introduced by some PHP extension?

If it is class added by PHP extension, you might want to check this https://github.com/rectorphp/rector/issues/1547

vinioo commented 5 years ago

Hello, thanks for the answers. I solved the problem, just had to add my project path to autoload_paths at rector.yaml.

But, now i am getting the error message "Ambigous class". The project has a lot of duplicated classes. Is there a way to skip it? Or will i need to get just one class anyway?

TomasVotruba commented 5 years ago

I solved the problem, just had to add my project path to autoload_paths at rector.yaml.

What does it mean? What does your full rector.yaml look like?

It's seem you're autoloading something twice

vinioo commented 5 years ago

rector.yaml

parameters:
    autoload_paths:
        - '/dados/webdesktop.git'

Just added the entire project

TomasVotruba commented 5 years ago

Ah, I never saw this usage. There should be only vendor/autoload.php or something similar

vinioo commented 5 years ago

how an autoload.php file should looks like?

TomasVotruba commented 5 years ago

Well, how do you autoload classes now? Composer or sth?

Minimal PHP code that Rector fails on would help, e.g.

vendor/bin/rector p src/SomeFile.php
# rector.yaml
services:
   XYRector: ~
TomasVotruba commented 5 years ago

Original question resolved, closing

afilina commented 5 years ago

In case someone ends up here because they need Rector in a different project from the code being processed:

parameters:
  autoload_paths:
    - '../project_to_process/vendor/autoload.php'
phazei commented 4 years ago

This link no longer exists: https://github.com/rectorphp/rector#extra-autoloading

But it's still given in the error

 1416/1416 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% [ERROR] Could not process "../project/src/AppBundle/AppBundle.php" file, due   
         to:                                                                    
         "Analyze error: "Class AppBundle\AppBundle was not found while trying  
         to analyse it - discovering symbols is probably not configured         
         properly.". Include your files in "parameters > autoload_paths".       
         See https://github.com/rectorphp/rector#extra-autoloading".     
TomasVotruba commented 4 years ago

The README was changed to drop 50 % of clutter code and show all the options in one file: https://github.com/rectorphp/rector#configuration

I'll update it, thanks :+1: