Skip to content

checkTooWideReturnTypesInProtectedAndPublicMethods only works for inheriting methods #13939

@etienneroudeix

Description

@etienneroudeix

Bug report

Following this update in version 2.1.31, a new parameter checkTooWideReturnTypesInProtectedAndPublicMethods was added to look for unexpectedly thrown exceptions in protected/public methods.

However this seems to work only for methods inheriting from a parent.

See : https://phpstan.org/r/12bd44c9-c653-4ef9-9b23-e57509f35255

However, checkTooWideThrowTypesInProtectedAndPublicMethods: true cannot be set in playground.

The result is :

 ------ --------------------------------------------------------------------------- 
  Line   Foo.php                         
 ------ --------------------------------------------------------------------------- 
  25     Method Bar::foo() has MyOtherE in PHPDoc @throws tag but it's not thrown.  
         🪪  throws.unusedType                                                      
 ------ --------------------------------------------------------------------------- 


Reading the code from TooWideMethodThrowTypeRule, I believe it is linked to the $isFirstDeclaration check but I am afraid I am not sure of the purpose.

Code snippet that reproduces the problem

https://phpstan.org/r/12bd44c9-c653-4ef9-9b23-e57509f35255

Expected output

 ------ --------------------------------------------------------------------------- 
  Line   Foo.php                         
 ------ --------------------------------------------------------------------------- 
  12     Method Foo::foo() has MyOtherE in PHPDoc @throws tag but it's not thrown.  
         🪪  throws.unusedType                                                      

  25     Method Bar::foo() has MyOtherE in PHPDoc @throws tag but it's not thrown.  
         🪪  throws.unusedType                                                      
 ------ --------------------------------------------------------------------------- 

Did PHPStan help you today? Did it make you happy in any way?

Everyday 🫶

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions