I'm currently trying to remove all errors and warnings I have in my project the Inspection tool from my PHPStorm give to me.
I encounter a snippet PHPStorm says "Unused private method _xxx" while it's actually used, but in a dynamical way. Here is a simplifyed snippet:
<?php
class A
{
private function _iAmUsed()
{
//Do Stuff...
}
public function run($whoAreYou)
{
$methodName = '_iAm' . $whoAreYou;
if (method_exists($this, $methodName)) {
$this->$methodName();
}
}
}
$a = new A();
$a->run('Used');
?>
In this snippet, PHPStorm will tell me "Unused private method _iAmUsed" while, in fact, it is used... How can I, by adding PHPDocs or something, whatever, make my IDE understand my method is actually used?
Note that I give to my "run" call, a static string, but we can imagine also this:
<?php
$a->run($_POST['whoYouAre']); //$_POST['whoYouAre'] == 'Used'
?>
Thanks a lot!
protected
instead ofprivate
. PhpStorm (as well as any other PHP IDE around here) cannot detect such highly dynamic usage using only static (and near static) code checking (as already mentioned above) – Hiddenite