Skip to content

Instantly share code, notes, and snippets.

@suin
Created February 3, 2012 14:34
Show Gist options
  • Save suin/1730441 to your computer and use it in GitHub Desktop.
Save suin/1730441 to your computer and use it in GitHub Desktop.
あるファイルに使われている関数を数えて返す ref: http://qiita.com/items/2013
<?php
$filename = '/path/to/file.php';
$contents = file_get_contents($filename);
$tokens = token_get_all($contents);
$functions = array();
while ( count($tokens) > 0 )
{
$token = array_shift($tokens);
if ( $token[0] !== T_STRING )
{
continue;
}
$isFunction = false;
while ( count($tokens) > 0 )
{
$_token = array_shift($tokens);
if ( $_token[0] === T_WHITESPACE )
{
continue;
}
else
{
if ( $_token[0] === '(' )
{
$isFunction = true;
}
break;
}
}
if ( $isFunction === true )
{
$functions[] = $token[1];
}
}
$functions = array_count_values($functions);
arsort($functions);
print_r($functions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment