-
Notifications
You must be signed in to change notification settings - Fork 25
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
Determine tmpDir path relative to config file when appropriate #163
Conversation
Very much appreciated. Thanks a lot for improving this PHPStan extension! |
@@ -46,7 +46,11 @@ | |||
if (!empty($configFile)) { | |||
$neonConfig = Neon::decode(file_get_contents($configFile)); | |||
if(is_array($neonConfig) && isset($neonConfig['parameters']) && isset($neonConfig['parameters']['tmpDir'])) { | |||
$tmpDir = $neonConfig['parameters']['tmpDir']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a call to \Nette\DI\Helpers::expand() in the same way as PHPstan does it to make sure we are dealing with the same configuration: https://github.com/phpstan/phpstan-src/blob/master/src/Command/CommandHelper.php#L149
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in that case, we'll need to add nette/di
as a dependency (probably not a big deal). The class Nette/DI/Helpers
is marked @internal
, which my IDE treats like sorta like a deprecated class.
Given those points, are you comfortable using that method? I'd like to follow your lead on decisions like this.
autoload.php
Outdated
// otherwise, treat the tmpDir as a path relative to the directory of the config file | ||
$tmpDir = strpos($neonConfig['parameters']['tmpDir'], '/') === 0 | ||
? $neonConfig['parameters']['tmpDir'] | ||
: dirname($configFile) . '/' . $neonConfig['parameters']['tmpDir']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel we might not need this bock and rather add the same !isset() check as PHPStan uses: https://github.com/phpstan/phpstan-src/blob/master/src/Command/CommandHelper.php#L228-L231
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it this check that we should replace with the simpler isset: https://github.com/bitExpert/phpstan-magento/pull/163/files/137b8dfd770612cc9cc057d6aaf537cfb650dffc#diff-f79e1f84a3df304b5be8b1bd2f1a36d4bb8417d91e8ae7144e648379d697a57eL48?
If not, I think I need some clarification regarding the change you'd like to see.
@mattwellss sorry for not getting back to you earlier. I am still super busy with my work, this should hopefully get better next week. I had the chance to discuss things with Ondřej. He pointed out that the bootstrap files get a $container instance injected from which we can pull the dependencies instead of creating them on our own. Additionally, that means, we can omit the whole config parsing logic. See here how the bootstrap files are invoked: https://github.com/phpstan/phpstan-src/blob/master/src/Command/CommandHelper.php#L475 If you find some time to refactor the logic, feel free. Otherwise, I'll do it next week or the week after. My goal is to try and get the next extension release done before Christmas with both of your PR's included. |
@shochdoerfer wow, the autoloader is so much cleaner using the Does this change mean we can eliminate the |
@mattwellss agree, looks so much better. Yes, we don't need the Also, we can improve things a bit more ;) We can define the autoloader classes as services in the As it looks to me, we can declare the services in the
and then pull it from the container like this:
Since the require_once() in PHPStand is embedded in a closure already, we could also get rid of this I think:
|
- define autoloaders as an "extend-able" configuration - ensure autoloaders needing custom cache storage have it - warn when a container or autoloader service isn't found
OK, I got a little wild with the latest commit, happy to roll back some of my decisions if needed. 😄 The goal with my latest changes is to allow users of the extension to define their own autoloaders as needed. This results in a lot of extra configuration in extension.neon, and might be totally unnecessary, if this extension is intended to cover all potential autoloading needs. Curious to hear your thoughts. |
I like your way of thinking but we should adjust things a little bit ;)
What do you think? Is the FileCacheStorage directory correctly configured? You set it to |
Good suggestions re: defining autoloaders! I'll work on that. Oops, you're totally right about the |
I don't think we can pull the value from the DI container, because it's defined inline. Leave it as it is, for now, that's fine for me. I will try to figure out what was the reason for creating the FileCacheStorage class. Maybe we can drop that and depend on PHPStan's storage class. Then we could avoid the problem of having 2 cache directory definitions. Maybe we should add one minor thing to the |
PHPStan's built-in I'll add a type check for the autoloader instance |
@mattwellss the final PHPStan complaint needs to be fixed like this: https://github.com/bitExpert/phpstan-magento/blob/master/phpstan.neon#L11 Thanks for doing the annoying work ;) |
Neat! I don't mind adding types and such. That's just PHPStan forcing us to be careful |
And merged ;) |
@shochdoerfer I forgot to remove |
No worries, I have it on my list to fix ;) |
Fix #161