bitExpert / phpstan-magento

Magento specific extension for PHPStan
MIT License
133 stars 25 forks source link

Internal error: Class\Foo does not exist and has no extension interface in file class.php #309

Closed Morgy93 closed 7 months ago

Morgy93 commented 7 months ago

Hello,

i tried to run phpstan for third party code and it threw the following error:

Internal error: Foo\Bar\Api\Data\CategoryTextInterface does not exist and has no extension interface in file /var/www/html/src/Foo/Bar/Model/Data/BrandText.php

There's no mention of CategoryTextInterface in the code so I don't know what to do.

However, there's some using for CategoryTextExtensionInterface, but that class exists at dev/tests/unit/tmp/generated/code/Foo/Bar/Api/Data/CategoryTextExtensionInterface.php

Any help?

shochdoerfer commented 7 months ago

Short answer: Try to exclude the 3rd party code :)

Long answer: It's problematic. Since the interface name ends with "ExtensionInterface" we assume it's an Extension attributes implementation. Which apparently it isn't the case. When parsing the code, we only have the class names available, that's why need to make some guessing what we are dealing with. And in your edge case the guessing is wrong.

Morgy93 commented 7 months ago

Short answer: Try to exclude the 3rd party code :)

I'm fine with that. 😅

Long answer: It's problematic. Since the interface name ends with "ExtensionInterface" we assume it's an Extension attributes implementation. Which apparently it isn't the case. When parsing the code, we only have the class names available, that's why need to make some guessing what we are dealing with. And in your edge case the guessing is wrong.

Thanks for the explanation. Will remember if I ever encounter this issue again.

I'll just exclude that file. Closed~