-
-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to run PHPStan #365
Comments
first yes, you need to load the Mage.php, there is no way around it. I hope this helps a bit |
I'm down to 4584 errors, using this configuration:
and modifying these files:
Lots of them are like these:
and
Any suggestion on how to solve these? |
Guess the errors come from magic getter/setter mehtods. Please check this: https://github.com/fooman/phpstan-magento2-magic-methods. May you can add something similiar for M1? Btw ... i think this projects need some pleanup before PHPSTAN work properbly.
|
@sreichel about magic getter/setter methods ( |
Seems to come from wrong or not existing annotations ... when these are added phpstan seems to work really fine. I use https://github.com/inviqa/phpstan-magento1
You have to exclude controllers too, because autoloading doesnt work. If phpstan stops without error message, add It should be a call to helper/model with a variable name Happy analyzing :P |
@sreichel This could also be part of captainhook config ;) Example action: |
Hi It sounds like it would be good to join forces and have one fork which could be used in projects and to analyze OpenMage source code. |
Hi @tmotyl, thanks for mentioning me. I have created this repository https://github.com/vianetz/phpstan-magento1 as I also recognized that most phpstan forks for Magento 1 have been abandoned or were not updated since a long time. I'm using this phpstan library for checking all custom code in my Magento 1 projects and it's working fine so far. Best regards, |
@christophmassmann great to hear from you.
Then:
|
FYI, I managed to run phpstan without db connection, will publish it in near future. I would also recommend to move the code execution from beginning of the "Mage" file (so there is only class inside), to separate bootstrapping/autoloading logic from class definition. |
Here you go: |
I've made a PR which adds a phpstan configuration file to openMage #1837 |
@tmotyl very cool, nice work, thanks for your effort! Sorry that I didn't had the time yet to have a look into this issue myself 😢 While checking your modifications and comparing them with my version I noticed some things:
Anyway having the awesome |
@christophmassmann the slowness comes most probably from static reflection - the phpstan ability to analyze class without executing it. But its just a wild guess. I dont expect magento config to change too much so maintaining the copy doesnt sound as a big issue. But im open to other solutions. Thanks for the hint about local.xml - does your solution loads extension config (thus class aliases) then too? |
@tmotyl @christophmassmann great work!
I'll test your PR later :) |
but this should be the same in both approaches then, right?
Yes. |
afaik static analysis is somehow autodetected and used for classes which are not autoloaded. |
Little update: I've prepared a PR which makes almost whole openmage code being analyzed: I'm closing this issue as it's already resolved:
|
I'm trying to figure out how to run PHPStan on Magento LTS.
After dozens of tries I have a somewhat working instance.
These are the files I had to modify to make it run:
This is the configuration used for phpstan:
And this is the command:
vendor/bin/phpstan analyze -vvv -l 0 -c phpstan.neon app/code/
I'm sure I'm doing something wrong with the autoloading, as I get thousands of errors like "Call to static method app() on an unknown class Mage."
But if I use
%rootDir%/../../../app/Mage.php
instead of%rootDir%/../../../lib/Varien/Autoload.php
I get all sorts of other issues with PEAR classes and so on.Anyone interested in helping me out? Using phpstan would greatly help finding issues on magento, and would be a first step for the upcoming CI environment that's needed for the project.
The text was updated successfully, but these errors were encountered: