Last active
October 24, 2016 12:57
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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