Skip to content

Instantly share code, notes, and snippets.

@cordoval
Created February 17, 2012 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cordoval/1854632 to your computer and use it in GitHub Desktop.
Save cordoval/1854632 to your computer and use it in GitHub Desktop.
public function isEmpty()
{
$method = new \ReflectionMethod(
$this->_objectOrClassName,
$this->_methodName
);
list(,$path,) = explode(PHP_EOL, (string)$method);
preg_match('/(@@ )(.*\.php)( )(\d+)(\D*)(\d+)/', $path, $matches);
list ($path, $start, $end) = array(
$matches[2], $matches[4], $matches[6]
);
$code = '';
for ($i = $start; $i <= $end; $i++) {
$code .= Backtrace::readLine($path, $i);
}
$methodBodyPattern = "/(function\s+)(\w+)(\()[^\)]?(\))({)([^}]?)/";
preg_match($methodBodyPattern, $code, $matches);
$extract = isset($matches[6]) ?: '';
return empty($extract);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment