Skip to content

Instantly share code, notes, and snippets.

@phoshp
Last active Nov 27, 2020
Embed
What would you like to do?
A basic php script for lazy devs to know how much line they have coded
<?php
$dirs = [
// ADD YOUR DIRS
];
$targetExtensions = [
// EXAMPLE
"php" => true,
"css" => true
];
$codeline = 0;
foreach($dirs as $dir){
$dir = str_replace("\\", "/", $dir);
if(!is_dir($dir)){
print_r("There is not a directory with path name: " . $dir . "\n");
continue;
}
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $file){
$path = $file->getPathname();
if(isset($targetExtensions[$file->getExtension()])){
$content = file_get_contents($path);
$codeline += substr_count($content, "\n") + 1;
}
}
}
print_r("Total Code Line: " . $codeline);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment