Problem/Motivation
After running PHPstan Drupal at level 9, I got the following errors.
------ ------------------------------------------------------------------------------------------------------------------------------------------------
Line src/Plugin/views/display/ViewsBlockOverride.php
------ ------------------------------------------------------------------------------------------------------------------------------------------------
71 Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::optionsSummary() has no return type specified.
71 Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::optionsSummary() has parameter $categories with no type specified.
71 Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::optionsSummary() has parameter $options with no type specified.
155 \Drupal calls should be avoided in classes, use dependency injection instead
172 \Drupal calls should be avoided in classes, use dependency injection instead
236 Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::blockSubmit() has no return type specified.
242 Argument of an invalid type mixed supplied for foreach, only iterables are supported.
242 Cannot access offset string|null on mixed.
243 Argument of an invalid type mixed supplied for foreach, only iterables are supported.
274 Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::preBlockBuild() has no return type specified.
290 Access to an undefined property Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::$block.
💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property
296 Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::execute() has no return type specified.
297 Access to an undefined property Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::$block.
💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property
329 Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::usesExposed() has no return type specified.
336 Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::displaysExposed() has no return type specified.
343 Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::buildOptionsForm() has no return type specified.
343 Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::buildOptionsForm() has parameter $form with no type specified.
------ ------------------------------------------------------------------------------------------------------------------------------------------------
[ERROR] Found 17 errors Steps to reproduce
Install PHPstan Drupal and the needed packages, run on level 9. The errors listed above are displayed.
Proposed resolution
Fix the errors.
Remaining tasks
The code has already been modified and the errors fixed, I now just need to test thoroughly on both an existing site (not my D9 clean install) and also on a D10 instance.
Then review by someone else and merge the code.
User interface changes
None
API changes
None
Data model changes
None
Issue fork views_block_override-3374860
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
dtfabio commentedAfter testing on an existing site and briefly going through the views, I got the following error. This was because the parent execute function did not always return an empty array, it also returned NULL. To prevent this, I made the return type of the modules execute function nullable.
Comment #4
dtfabio commentedComment #5
tim-dielsJust tested and still has errors on level 9:
Comment #6
dtfabio commentedComment #7
dtfabio commentedComment #10
dtfabio commentedHi Tim,
I tried to fix the last issues, but saw there were merge conflicts so wanted to merge the dev branch into my branch.
Had apparently accidentally used the 1.2.x branch where changes happened to it, preventing me from creating a working patch. I then tried to fix this, without success.
I finally decided to just make a new branch with the latest changes, only with this I still can't make a working patch. I don't immediately see what the problem is, so I just provided the code and maybe you know the reason?
Greetings,
Fabio
Comment #11
anna d commentedAdded comments to the MR and honestly don't understand why I'm anonymous above.UPD: it was fixed after adding this comment. Hmm.. drupal.org bug?
Comment #12
anna d commentedAdded .gitlab-ci for automated GitLab tests. Phpcs and phpstan pipelines still fails.
Comment #13
dhruv.mittal commentedWorking on it
Comment #14
dhruv.mittal commentedHello @anna!!
I have solved the phpcs errors and tried to solve phpstan error but there is a error in code in use of elseif that is causing the another error.
I think that one need to be solved first.
Comment #15
anna d commentedComment #16
tim-dielsYou should focus on fixing one task at a time to make it easier to follow up. You can create separate tasks to fix other things and I would suggest on doing so. I will then make some time to review tasks when they are split to simpler tasks.
Comment #17
anna d commentedHello @tim-diels,
I didn't see that the 1.0.x-dev version was targeted instead of 1.2.x-dev. I created a separate issue for GitLab CI/CD for 1.2.x-dev, and there are only two PHPStan errors:
Line src/Plugin/views/display/ViewsBlockOverride.php
------ ----------------------------------------------------------------------
181 \Drupal calls should be avoided in classes, use dependency injection
instead
198 \Drupal calls should be avoided in classes, use dependency injection
instead
------ ----------------------------------------------------------------------
[ERROR] Found 2 errors
I've created a separate issue specifically to address the dependency injection in the class. I'm not sure if you'd prefer to fix everything separately for 1.0.x-dev or just close this issue.
Comment #18
tim-dielsIssues are resolves in the other ticket. Thanks for that.