Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work when autoloading multiple directories into a single namespace #724

Closed
stancl opened this issue Nov 28, 2020 · 3 comments · Fixed by #725
Closed

Doesn't work when autoloading multiple directories into a single namespace #724

stancl opened this issue Nov 28, 2020 · 3 comments · Fixed by #725

Comments

@stancl
Copy link
Contributor

stancl commented Nov 28, 2020

  • Larastan Version: Latest
  • --level used: any

Description

When you use:

"autoload-dev": {
    "psr-4": {
        "Lean\\Tests\\": ["tests/"]
    }
},

Larastan will try to get all files in that namespace.

However, it won't loop through the ["tests/"] array, so it will pass ["tests/"] as a path to ClassMapGenerator::createMap(), when the method expects a string.

Screen Shot 2020-11-28 at 17 24 10

This results in:

Error thrown in /Users/samuel/Projects/lean/lean/vendor/composer/composer/src/Composer/Autoload/ClassMapGenerator.php on line 86 while loading bootstrap file /Users/samuel/Projects/lean/lean/vendor/phpstan/phpstan/../../nunomaduro/larastan/bootstrap.php: Call to a member function getPathname() on string

Code where the issue was found

ApplicationResolver line ~103

Solution

Loop through the paths, not just through the namespaces.

@szepeviktor
Copy link
Collaborator

Would you send a one-liner PR?

@szepeviktor
Copy link
Collaborator

BTW Using the same namespace in two different paths is risky.

@stancl
Copy link
Contributor Author

stancl commented Nov 28, 2020

Yup, I just had the array syntax for a single path by default because my VSCode plugin generated it.

Will send a bug fix shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants