TomasVotruba / unused-public

Find Unused Public Elements in Your Code
https://tomasvotruba.com/blog/can-phpstan-find-dead-public-methods/
MIT License
151 stars 12 forks source link

union type support #119

Closed staabm closed 4 months ago

staabm commented 4 months ago

properties are reported unused even though they are used via union type:

<?php

class A {
    public float $amount;
}

class B {
    public float $amount;
}

/** @param A|B $aOrB */
function doFoo($aOrB): void {
    echo $aOrB->amount;
}

function doFooBar(A|B $aOrB): void {
    echo $aOrB->amount;
}

reports

 ------ -------------------------------------------------------------------------------------------------------- 
  Line   test.php
 ------ --------------------------------------------------------------------------------------------------------
  3      Public property "A::$amount" is never used
         💡 Either reduce visibility or annotate it or its class with @api
  7      Public property "B::$amount" is never used
         💡 Either reduce visibility or annotate it or its class with @api
staabm commented 4 months ago

(working on a fix right now)