Skip to content

Instantly share code, notes, and snippets.

@poteirard
Last active October 24, 2016 12:57
Show Gist options
  • Save poteirard/ff202033aa5ac46fc739aa1fff7da5a3 to your computer and use it in GitHub Desktop.
Save poteirard/ff202033aa5ac46fc739aa1fff7da5a3 to your computer and use it in GitHub Desktop.
List most used php functions in a tree of directories with php files
<?php
$baseDir = 'phpfiles/path/';
$dir = new RecursiveDirectoryIterator($baseDir);
$Iterator = new RecursiveIteratorIterator($dir);
$regexFiles = new RegexIterator($Iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);
$phpFunctions = get_defined_functions();
$functionsCount = array();
foreach ($regexFiles as $filename => $file) {
$tokens = token_get_all('<?php '.file_get_contents($file[0]) . ' ?>');
$tokens = array_filter($tokens, function($token) use ($phpFunctions) {
return $token[0] == T_STRING && in_array($token[1], $phpFunctions['internal']);
});
foreach ($tokens as $token){
$functionName = $token[1];
$functionsCount[$functionName] =
array_key_exists($functionName, $functionsCount)
? $functionsCount[$functionName]+1
: 1;
}
}
arsort($functionsCount);
print_r($functionsCount);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment