I am trying to get static PHP code analysis to work on my OXID 6 eshop.
I am, however, hitting a brick wall when it comes to this:
When I run vendor/bin/phpstan analyse --configuration phpstan.neon source/modules/myvendor/mymodule
I always get errors like Class mynamespace\Article_parent not found
.
This is probably because in Oxid, the eshop classes are not directly overwritten, but instead declared like this
<?php
namespace mynamespace;
class Article extends Article_parent
{
...
and in a metadata.php
the overwritten class is defined:
'extend' => [
\OxidEsales\Eshop\Application\Model\Article::class => \mynamespace\Article::class,
],
Phpstan does not seem to be able to resolve this, I've tried many different configuration files, like this one
parameters:
level: max
inferPrivatePropertyTypeFromConstructor: true
autoload_files:
- vendor/oxid-esales/oxideshop-ce/source/oxfunctions.php
- vendor/oxid-esales/oxideshop-ce/source/overridablefunctions.php
or this one
parameters:
level: 7
autoload_files:
- vendor/oxid-esales/testing-library/base.php
- vendor/oxid-esales/oxideshop-ce/source/oxfunctions.php
- vendor/autoload.php
but to no avail. How can I get phpstan to work?
The \mynamespace\Article_parent
class does not exist and will be created at runtime as an alias. This is because it depends on your configuration / other modules installed where this alias points to.
My colleague Alfred Bez created the oxid-dump-autoload
tool, what will dump out the module chain based on your current configuration and setup, so that PHPStan / Psalm can find the classes:
https://github.com/alfredbez/oxid-dump-autoload
Hope I could help