Revert load vendor/autoload from getcwd and add documentation for using globally (not recommended) (#1685)

This commit is contained in:
Abdul Malik Ikhsan 2022-01-16 09:17:12 +07:00 committed by GitHub
parent 4ac5dd6420
commit 6b965fe744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -91,13 +91,10 @@ final class AutoloadIncluder
/**
* In case Rector is installed as vendor dependency,
* this autoloads the project vendor/autoload.php, including Rector
*
* This also accounts for running a globally installed Rector from the global composer vendor dir
*/
public function autoloadProjectAutoloaderFile(): void
{
$this->loadIfExistsAndNotLoadedYet(__DIR__ . '/../../../autoload.php');
$this->loadIfExistsAndNotLoadedYet(getcwd() . '/vendor/autoload.php');
}
public function autoloadFromCommandLine(): void

View File

@ -76,10 +76,14 @@ If the false positive still happen, you can skip the rule applied as last resort
]);
```
### Dealing with "Class ... was not found while trying to analyse it..."
## Dealing with "Class ... was not found while trying to analyse it..."
Sometimes you may encounter this error ([see here for an example](https://github.com/rectorphp/rector/issues/6688)) even if the class is there and it seems to work properly with other tools (e.g. PHPStan).
In this case you may want to try one of the following solutions:
### Register to `Option::AUTOLOAD_PATHS`:
```php
$parameters->set(Option::AUTOLOAD_PATHS, [
// the path to the exact class file
@ -91,7 +95,15 @@ In this case you may want to try one of the following solutions:
]);
```
Other solution is by register the path of the class to composer.json's `"files"` config, eg:
### Call command with `-a` option
This may happen when you're using rector globally (not recommended as autoload may overlapped)
```bash
rector process -a vendor/autoload.php
```
### Other solution is by register the path of the class to composer.json's `"files"` config, eg:
```javascript
"autoload-dev": {