Comments (4)
Makes sense and I am still surprised that my tests with the magento/module-inventory-api
did seem to work fine. I manually disabled the extension interface autoloader and all the extension attribute errors popped up. After enabling the autoloader, the errors are gone. Not exactly sure what I did wrong, will try to replicate your tests.
How to solve this? I basically see 3 options:
- come up with an automated solution to guess if we have to deal with a Magento application project or a Magento module project. Not sure how that could look like, though
- add a configuration setting to "enable" the lookup via the component registrar
- maybe we could register the project root as a fake module to make the component registrar believe a module is installed
from phpstan-magento.
I found out why my tests have been misleading: The magento/module-inventory-api
uses the extension attribute interface but it does not define extension attributes via an extension_attributes.xml
file.
I tested it with a different Magento module and can confirm your findings.
I am thinking to fix this with the 2nd solution proposed: By default, the PHPStan extension will scan for all extension_attributes.xml
files in the project and take all of them into account. If the user wants to restrict this to only taking enabled modules into account, a configuration flag will be introduced to enable this feature.
from phpstan-magento.
I believe we can use the magentoRoot
parameter. Standalone modules do not employ this concept (no Magento application!), so we can make that parameter nullable and set the default to null
.
If we use magento root, here's how the constructor would change:
public function __construct(Cache $cache, ?string $magentoRoot = null)
{
$this->cache = $cache;
$this->componentRegistrar = new ComponentRegistrar();
if ($magentoRoot !== null) {
$this->moduleList = new ModuleList(
new DeploymentConfig(
new DeploymentConfigReader(
new DirectoryList($magentoRoot),
new Filesystem\DriverPool(),
new ConfigFilePool()
)
),
new Loader(
new ModuleDeclarationDom(),
new XmlParser(),
$this->componentRegistrar,
new FileDriver()
)
);
}
}
and then when finding module dirs we'd do this:
$moduleDirs = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE);
// If magentoRoot was specified, only extract extension attributes from enabled modules
if ($this->moduleList !== null) {
$moduleDirs = array_filter(
$moduleDirs,
function ($moduleName) {
return $this->moduleList->has($moduleName);
},
ARRAY_FILTER_USE_KEY
);
}
from phpstan-magento.
Regardless of the method we choose to switch between standalone and application module discovery, what should the default be (null
Magento root or cwd)?
from phpstan-magento.
Related Issues (20)
- Missing check when using factory constant HOT 1
- No coverage data is *not* sent to Coveralls
- Certain CI steps run several times without additional result HOT 1
- Move stubs out of src/ HOT 6
- DateTimeFactory Issue; HOT 6
- Use Magento root for TestFrameworkAutoloader HOT 8
- Project config file at path app/code/Vendor/Module does not exist. HOT 5
- Factory generation misnames output class HOT 4
- Current release version not updated HOT 5
- Wrong directory used as "magentoRoot" when current working direcory is not magento root HOT 2
- private string $magentoRoot; not work in PHP 7.2 HOT 4
- Generated class ProductExtension is passed on incorrectly to phpstan HOT 30
- Missing Interface class HOT 9
- Add support for PHP 8.2 HOT 3
- Compatibility with PHPstan 1.10.x HOT 4
- Failure with `phpstan/phpstan-phpunit` and PHPStan cache usage HOT 19
- Version 0.30.0 fails with errors about unexpected items in parameters HOT 4
- Extend ci_neon_lint script to validate parametersSchema
- Incompatibility with phpstan & rector and 2.4.6 HOT 1
- Internal error: Class\Foo does not exist and has no extension interface in file class.php HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpstan-magento.