-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Using --analysis with Drupal gives a lot of issues due to loose array types #277
Comments
Hey @mglaman, please let me know what you think about this, the code is pretty simple for this so made a PR in the hopes that you agree with me. |
Thanks for #278, @googletorp. However, it may be a better solution to make it possible include some configuration file, e.g. |
Please, just use PHPStan directly then. This package is meant to be an opinionated quick scan. Annotating array types can be annoying, but it helps fix buggy code. |
@mglaman I agree in general that annotating array types is a great thing, but with Drupal use of render and form arrays, you get a bunch or warnings every time you extend core, which seems to defeat the purpose of writing clean code, if the framework you are building upon doesn't follow the same standards. Can you offer some guidance on how to use this feature without getting overwhelmed by errors coming from Drupal Core? |
PHPStan will on analysis (level 6) give error if arrays are not correctly types, see more here: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type. This makes a lot of sense on a generic PHP application. You would like to get code like this:
instead of seeing code like this
This will make the analysis much better as it's possible to figure out what kind of data is inside the loop. The thing is that Drupal uses complex array structures for render arrays and Form API arrays, meaning that you will need to:
In order to explicitly say to PHPStan that we don't really know what the array contains. When extending a lot of core classes in custom code you want to analyze you will get these errors all over and they are not fixable if you use
{@inheritDox}
.This is not a bug in drupal-check, but I think it would make a lot of sense to ignore this error when using analysis.
The text was updated successfully, but these errors were encountered: