Skip to content

With deadMethods: false, deadConstants: true, class constants are always detected as unused #256

@mdio

Description

@mdio

I tried to set my config to:

parameters:
    shipmonkDeadCode:
        detect:
            deadMethods: false
            deadConstants: true

but ended up with all class constants in the project being detected as unused.

I set up a small repo to reproduce that: https://github.com/mdio/test-dead-code-detection-constants-only

Running vendor/bin/phpstan analyse -c phpstan-dead-code.neon with the current setup gives me:

 ------ ---------------------------------------------- 
  Line   ClassWithConstants.php                        
 ------ ---------------------------------------------- 
  11     Unused mdio\ClassWithConstants::DEFAULT_PORT  
         🪪  shipmonk.deadConstant                     
         at ClassWithConstants.php:11                  
 ------ ---------------------------------------------- 

Setting deadMethods: true correctly results in [OK] No errors.

Btw, thanks a lot for this tool! It makes working with a large legacy code base much nicer as it allows me to quickly find stuff I can delete to make it more manageable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions