Hello, SonarQube is currently triggering false positive alerts for Unused "private" methods should be removed
when a private method is called externally via __call()
.
When using AOP programming, this is a common implementation.
Here’s a simplified implementation that generates the issue:
class Foo() {
public function __call($method, $arguments){
if (method_exists($this, $method)) {
//some logic called before the actual method is called
return call_user_func_array([$this, $method], $arguments);
}
trigger_error('Call to undefined method '.__CLASS__.'::'.$method.'()', E_USER_ERROR);
}
private function bar(){
//bar method implementation
}
}
$foo = new Foo();
$foo->bar(); // this will call the private method bar via the magic method __call()
SonarQube version: 10.0.0.68432
PHP version: 8.2