Giter VIP home page Giter VIP logo

Comments (4)

shochdoerfer avatar shochdoerfer commented on July 4, 2024

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.

shochdoerfer avatar shochdoerfer commented on July 4, 2024

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.

mattwellss avatar mattwellss commented on July 4, 2024

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.

mattwellss avatar mattwellss commented on July 4, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.