Search code examples
phpoopphpstormphpdoc

How to document usage of a method when called in an abstract form?


In a legacy project, I was confused when I tried finding the usage of a method in phpstorm and without success.

/**
 * @param SomeEntity[] $someEntity
 *
 * @return bool
 */
protected function warmupSomeEntity(array $brandUniverses)
{
     // I want to find this method's usage

}

Debugging a bit further, I found that the method is called on the fly in a rather abstract way via dynamic class method invocation:

/**
 * @param string $warmer
 * @param array $objects
 *
 * @throws RuntimeException
 */
public function warmupType($warmer, array $objects)
{
    $method = "warmup$warmer";
    if (method_exists($this, $
        $this->{$method}($objects);
    } else {
        throw new RuntimeException("There is no warmer '$warmer'");
    }
}

Is there a phpdoc syntax where I can document that the warmUpType method will call warmupSomeEntity, or warmupSomeOtherEntity so that I can find its usage again if I want to jump to the calling code block again?


Solution

  • The @uses keyword was what I was looking for as it:

    Display a link to the documentation for an element, and create a backlink in the other element's documentation to this

    It is supported by PhpStorm and the caller is found again.

    /**
     * @param string $warmer
     * @param array $objects
     * @uses warmupSomeEntity
     * @uses warmupSomeOtherEntity
     * @throws RuntimeException
     */
    public function warmupType($warmer, array $objects)
    {
     ...
    }