phpstan-magento icon indicating copy to clipboard operation
phpstan-magento copied to clipboard

Advice wanted about best practice

Open LauHypershop opened this issue 9 months ago • 5 comments

Hi,

An issue I run into occasionally is that it's pretty common in Magento for a concrete class to implement a lot of methods not covered by its interface.

For example, we're usually pretty confident that a Product class is going to have a getData() method, and the \Magento\Catalog\Model\Product uses it fairly extensively. But the \Magento\Catalog\Api\Data\ProductInterface doesn't list that method. Any time you fetch a product from a ProductRepositoryInterface, PHPStan is going to complain that this method doesn't exist.

What's a good way of handling this? I can put an ignoreErrors in my phpstan.neon like this:

- '#Call to an undefined method Magento\\Catalog\\Api\\Data\\ProductInterface::getData\(\).#'

However, this is going to lead to a fairly bloated file. It's also awkward to scale across multiple projects, to keep that list consistent as you discover more examples. Is there a better way to go about it?

LauHypershop avatar Apr 09 '25 07:04 LauHypershop