Problem/Motivation

Used the PHPStan tool on level 0 and found 4 errors, need to fix them.

------ ----------------------------------------------------------------------------------- 
  Line   src/Controller/AdminFeedbackController.php                                         
 ------ ----------------------------------------------------------------------------------- 
  55     Unsafe usage of new static().                                                      
         💡 See: https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ----------------------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------------------- 
  Line   src/Form/AdminFeedbackAjaxForm.php                                                 
 ------ ----------------------------------------------------------------------------------- 
  54     Unsafe usage of new static().                                                      
         💡 See: https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ----------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------ 
  Line   src/Form/AdminFeedbackDeleteForm.php                                          
 ------ ------------------------------------------------------------------------------ 
  85     \Drupal calls should be avoided in classes, use dependency injection instead  
 ------ ------------------------------------------------------------------------------ 

 ------ ----------------------------------------------------------------------------------- 
  Line   src/Plugin/Block/AdminFeedbackBlock.php                                            
 ------ ----------------------------------------------------------------------------------- 
  51     Unsafe usage of new static().                                                      
         💡 See: https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ----------------------------------------------------------------------------------- 

Steps to reproduce

Use the command lando phpstan analyse web/modules/contrib/admin_feedback/

Proposed resolution

Fix manually.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#4 3310754-4.patch4.57 KBvitorbs
#3 noerrors.png18.34 KBvitorbs
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

vitorbs created an issue. See original summary.

vitorbs’s picture

I'm working on it.

vitorbs’s picture

StatusFileSize
new18.34 KB

1- I created a constructor and method 'create' in the 'AdminFeedbackDeleteForm' because doesn't had any of both.

2- Replaced /Drupal call in 'AdminFeedbackDeleteForm' with dependency injection.

3 - Removed the unused statement

use Drupal\Core\Entity\EntityTypeManagerInterface;

4- Made the constructor final to disallow overriding.

And now i see no errors after using the php stan analyse.

Please, review.

vitorbs’s picture

StatusFileSize
new4.57 KB
vitorbs’s picture

Assigned: vitorbs » Unassigned
Status: Active » Needs review
christyanpaim’s picture

Assigned: Unassigned » christyanpaim
christyanpaim’s picture

Assigned: christyanpaim » Unassigned
Status: Needs review » Reviewed & tested by the community

Works fine here!

  • bserem committed ff6f9df on 8.x-2.x
    Issue #3310754 by vitorbs, christyanpaim, bserem: Fix PHP Stan errors
    
bserem’s picture

Status: Reviewed & tested by the community » Fixed

Excellent work @vitorbs! The patch is spot on!

Btw, Drupal has a guide for using phpstan: https://www.drupal.org/docs/develop/development-tools/phpstan/handling-u...
For future reference :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.