Skip to content

Instantly share code, notes, and snippets.

@bdelespierre
Last active December 12, 2015 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdelespierre/4692858 to your computer and use it in GitHub Desktop.
Save bdelespierre/4692858 to your computer and use it in GitHub Desktop.
Ever wondered how many lines you've written in your PHP project ? This is almost the most useless script in history but I'm kinda curious so I wrote it anyway...
<?php
set_time_limit(0);
function glob_recursive($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
}
return $files;
}
$files = 0;
$lines = 0;
foreach (glob_recursive('*.php') as $file) {
if (strpos($file, 'jpgraph') !== false) continue;
$files++;
$file = new SplFileObject($file);
foreach ($file as $line) {
if (trim($line))
$lines++;
}
unset($file);
}
PHP_SAPI != 'cli' && header("Content-Type: text/plain");
echo dirname(__FILE__)." has $files PHP scripts with a total of $lines non empty code lines";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment