Last active
December 15, 2015 22:58
-
-
Save mrspartak/5336322 to your computer and use it in GitHub Desktop.
Count lines of code Usage: run in current directory, or just pass the path to directory as parameter in CLI. Returns:
json
This file contains hidden or 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 | |
| ini_set('xdebug.max_nesting_level', 0); | |
| $dir = $argv[1] ? $argv[1] : dirname(__FILE__); | |
| if(!is_dir($dir)) | |
| exit('Error'); | |
| $global = array(); | |
| read($dir); | |
| function read($path) { | |
| global $global; | |
| $dir = opendir($path); | |
| while (($file = readdir($dir)) !== false) { | |
| if ($file == '.' || $file == '..') | |
| continue; | |
| $filepath = $path . '/' . $file; | |
| if (is_link($filepath)) | |
| continue; | |
| if (is_file($filepath)) { | |
| $info = pathinfo($filepath); | |
| $global['ext'][ $info['extension'] ] += count( file($filepath) ); | |
| $global['files']++; | |
| } | |
| else if (is_dir($filepath)) { | |
| $global['recursions']++; | |
| read($filepath); | |
| } | |
| } | |
| closedir($dir); | |
| } | |
| echo json_encode($global); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment