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

detect unused parameters #117

Closed staabm closed 6 months ago

staabm commented 6 months ago

I think this extension has all the information available to decide that optional method parameters are never used from a caller point of view and therefore mark them as obsolete.

e.g.

Class X {
  public function doFoo($a, $b, $c = null, $d = 123) {
  }
}

$x = new X();
$x->doFoo(1, 2);
$x->doFoo(3, 4);

-> since no calls exist which provide a value for $c and/or $d, both parameters are "unused" and could be turned into local variables or even removed altogether.

is this something you would accept as a PR?

TomasVotruba commented 6 months ago

Thanks for proposal, this would be out of simple scope of this package. It could be great separate package, as you can look for unused variables, assigns, etc. Still I think this is already handled by PHPStan and Rector well :+1: