This code will cause a UnusedPrivateMethod warning:


/**
 * Coder test.
 */
class Test {

  /**
   * Public.
   */
  public function publicMethod() {
    return self::privateMethod();
  }

  /**
   * Private.
   */
  private function privateMethod() {
    return TRUE;
  }

}

If privateMethod() is marked static, the problem goes away. A person cleaning up their code might just remove the apparently-used method and thereby break their code.

Comments

Liam Morland created an issue. See original summary.

twiesing’s picture

Component: Coder Sniffer » Code

I have a similar issue, I am calling a private method on another instance of the same class only, and it gets flagged.
Concretely I have a private method I am invoking inside a postLoad function of a custom entity class.