-
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
Rework extension attribute handling for standalone modules #179
Rework extension attribute handling for standalone modules #179
Conversation
@mattwellss mind checking if this implementation will work for your use case? Thanks! |
@shochdoerfer sorry about the delay! I'm working odd hours around the holidays. I was curious about how the extension behaves when installed globally (something I've never tested). Here's what I did
When testing a file calling an extension attribute method is "provided by" a disabled module, the expected error occurs:
While debugging the above analysis, I see PHPStan checks for a composer autoloader in the current project. That means local/vendored code is autoloadable, and that also Magento modules are able to register themselves. Given those results, would you be willing to go into more detail about the issues here?
Specifically, I'm wondering about:
I know this is bitExpert's module, and any input on its direction is at your discretion. So while I would love to maintain the ability to limit I've did check out this PR, though! It works, but doesn't identify the problem of using a nonexistent method like |
@mattwellss thanks for your feedback. So far I did not test global Composer installs, good to know that this will work fine as well. I tested installing phpstan and the extension in a different directory and then let it examine a Magento module in another directory, that was a request by someone else because they install QA tools independently from their projects. In that case Composer autoloading does not work, because Composer does only know about the local dependencies but not the ones from the other project. None of the other phpstan extensions I checked, made use of the framework or library classes they are written for. My assumption is, that it could lead to side-effects when loading those classes and analyzing their code in parallel. In our case, having the mock/stub implementations in place (to fix doc block issues) that get loaded automatically might even cause more trouble. For sure, I would like to support enabled/disabled modules. For now, I am just not sure if the effort would be worth it. In our own projects, we don't really have disabled modules in our code-bases. Does this happen often in your case? |
Use Composer autoloader to check if the interface definition for the extension attributes does in fact exist.
4875435
to
d159afe
Compare
Fixes #174
In contrast to my plan outlined in #174, I took a different route as I realized that it can be problematic to depend on Magento framework classes (loading and analyzing framework classes at the same time). Additionally, it was not possible to install PHPStan and this extension in a different directory as then the Composer autoloader would not work for the project-specific classes (e.g. for the class_exists, interface_exists, and trait_exists checks).
What happens now is that all
extension_attributes.xml
found inetc
directories are loaded recursively and evaluated regardless of whether the module is active or not. By default, the current working directory (the directory you placed yourphpstan.neon
file in) will be used as a starting point. If you need to change that, you can configure themagentoRoot
parameter and point it to a different location.To deal with inactive modules, we could either add a directory blacklist configuration or add some logic to evaluate the
config.php
settings and only take active modules into account.