Skip to content

missing check when using factory, di inyection and preference #224

Open
@esteban-serfe

Description

@esteban-serfe

My current module has a preference over a class set on the di.xml file.

I'm using the factory on the constructor of a overwrite.

When using a method that only exists on the overwrited class that is created through the Factory, PHPStan reports the method as not existent.

di.xml

<preference for="Magento\Framework\View\Result\Page"                 type="ClassA" />
<preference for="Magento\Framework\View\Page\Config\Renderer" type="ClassB" />

Class with factory on constructor:

class ClassA extends Magento\Framework\View\Result\Page  {
public function __construct(
 ....
 classBFactory $pageConfigRendererFactory
) {
 ...
 parent::__construct(.... );
}

public function overwritenFunction( .... ) {
  ....
  $this->pageConfigRenderer->onlyOnThisClassMethod();
  ....
}

Class B:

class ClassB extends \Magento\Framework\View\Page\Config\Renderer 
{
  public function onlyOnThisClassMethod() { .... }
}

This is reported as:
Call to an undefined method Magento\\Framework\\View\\Page\\Config\\RendererInterface::renderExtraFooter()

Complete code has been tested and battle proven on production, so it works as expected.

For now I'm just ignoring the issue reported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions