PHPCD\PHPCD::location PHP Method

location() public method

Fetch function or class method's source file path and their defination line number.
public location ( string $class_name, string $method_name = null ) : [path,
$class_name string class name
$method_name string method or function name
return [path,
    public function location($class_name, $method_name = null)
    {
        try {
            if ($class_name) {
                $reflection = new \ReflectionClass($class_name);
                if (!$method_name) {
                    $method_name = '__construct';
                }
                if ($reflection->hasMethod($method_name)) {
                    $reflection = $reflection->getMethod($method_name);
                } elseif ($reflection->hasConstant($method_name)) {
                    // 常量则返回 [ path, 'const CONST_NAME' ]
                    return [$this->getConstPath($method_name, $reflection), 'const ' . $method_name];
                }
            } else {
                $reflection = new \ReflectionFunction($method_name);
            }
            return [$reflection->getFileName(), $reflection->getStartLine()];
        } catch (\ReflectionException $e) {
            return ['', null];
        }
    }