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

Command icon 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

dtfabio created an issue. See original summary.

dtfabio’s picture

After 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.

The website encountered an unexpected error. Please try again later.
TypeError: Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::execute(): Return value must be of type array, null returned in Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride->execute() (line 392 of modules/contrib/views_block_override/src/Plugin/views/display/ViewsBlockOverride.php).

dtfabio’s picture

Assigned: dtfabio » Unassigned
Status: Active » Needs review
tim-diels’s picture

Status: Needs review » Needs work

Just tested and still has errors on level 9:

 ------ -------------------------------------------------------------------------------------------------------------
  Line   src/Plugin/views/display/ViewsBlockOverride.php
 ------ -------------------------------------------------------------------------------------------------------------
  64     Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::__construct() has parameter
         $configuration with no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  84     Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::create() has parameter
         $configuration with no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  85     Unsafe usage of new static().
         💡 See: https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static
  99     Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::defineOptions() return type has
         no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  118    Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::blockSettings() has parameter
         $settings with no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  118    Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::blockSettings() return type has
         no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  177    Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::blockForm() has parameter $form
         with no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  177    Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::blockForm() return type has no
         value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  302    Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::blockSubmit() has parameter
         $form with no value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
  365    Method Drupal\views_block_override\Plugin\views\display\ViewsBlockOverride::execute() return type has no
         value type specified in iterable type array.
         💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
 ------ -------------------------------------------------------------------------------------------------------------



 [ERROR] Found 10 errors
dtfabio’s picture

Assigned: Unassigned » dtfabio
Status: Needs work » Active
dtfabio’s picture

dtfabio changed the visibility of the branch 3374860-fix-phpstan-errors to hidden.

dtfabio changed the visibility of the branch 3374860-fix-phpstan-errors to active.

dtfabio’s picture

Assigned: dtfabio » Unassigned
Status: Active » Needs work

Hi 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

anna d’s picture

Added 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?

anna d’s picture

Added .gitlab-ci for automated GitLab tests. Phpcs and phpstan pipelines still fails.

dhruv.mittal’s picture

Assigned: Unassigned » dhruv.mittal

Working on it

dhruv.mittal’s picture

Assigned: dhruv.mittal » Unassigned

Hello @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.

anna d’s picture

Version: 1.0.x-dev » 1.2.x-dev
tim-diels’s picture

You 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.

anna d’s picture

Hello @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.

tim-diels’s picture

Status: Needs work » Closed (won't fix)

Issues are resolves in the other ticket. Thanks for that.