Introduce ComposerHelper for composer related config operations#1384
Introduce ComposerHelper for composer related config operations#1384ondrejmirtes merged 1 commit intophpstan:1.7.xfrom
Conversation
...Reflection/BetterReflection/SourceLocator/ComposerJsonAndInstalledJsonSourceLocatorMaker.php
Outdated
Show resolved
Hide resolved
|
Otherwise - awesome, I didn't even know about the Also - I believe there are few more hardcoded places for |
I guess this one is fine. It's always |
6f11f57 to
c83c1e9
Compare
src/Internal/ComposerHelper.php
Outdated
There was a problem hiding this comment.
Alright, some more ideas. There's an inconsistency - getComposerJsonPath returns an absolute path, but getVendorDir returns a relative path. Both should return absolute paths.
There was a problem hiding this comment.
Also, I don't like the optional , ?array $composerConfig = null) parameter. In that case the function does something completely different. I'd like two different functions - one that you call if you have the JSON array, another one if you don't.
There was a problem hiding this comment.
Ok, I refactored it little bit. Then it became clear that I don't need two methods. First getComposerConfig should be called and if returns null that means composer.json is not found or it's not a valid json file, so getVendorDirFromComposerConfig shouldn't be called.
src/Internal/ComposerHelper.php
Outdated
There was a problem hiding this comment.
There might be garbage in this setting. We should normalize that by doing trim($dir, '/').
bin/phpstan
Outdated
There was a problem hiding this comment.
This can return null which means it's gonna get concatenated lower leading to double // in the path...
| if ($composer !== null) { | ||
| $vendorDirectory = ComposerHelper::getVendorDirFromComposerConfig(getcwd(), $composer); | ||
| } else { | ||
| $vendorDirectory = getcwd() . '/' . 'vendor'; |
There was a problem hiding this comment.
This still uses the hardcoded vendor But this was the only way I could think of. Anyway, this case should be fairly rare.
|
Thank you very much! |
|
Did some additional improvements: 39bbdb9...1232186 |
This PR is mostly for #1355
It extracts a helper class to determine Composer
vendor-dir