Skip to content

Commit

Permalink
Revert load vendor/autoload from getcwd and add documentation for usi…
Browse files Browse the repository at this point in the history
…ng globally (not recommended) (#1685)
  • Loading branch information
samsonasik committed Jan 16, 2022
1 parent 4ac5dd6 commit 6b965fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 0 additions & 3 deletions bin/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,10 @@ public function includeDependencyOrRepositoryVendorAutoloadIfExists(): void
/**
* 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
Expand Down
16 changes: 14 additions & 2 deletions build/target-repository/docs/static_reflection_and_autoload.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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": {
Expand Down

0 comments on commit 6b965fe

Please sign in to comment.