Jump to content
MakeWebGames

How big is my project?


Recommended Posts

Posted

Always fun to know as a developer how much you coded, so here is a nice script I use to <censored>yse my own browsergame http://www.landofdestiny.com. It counts the amount of images, lines and characters so perfect for browsergames:

edit: place it in a folder and it will check that folder + all directories in it.

 

<?php
$map = "./";

class Stats
{
private $map;
private $ext_img = array();
public $directories = array();
public $stats;

public function __construct($map)
{
	$this->map = $map;
	$this->ext_img = array("jpg","gif","jpeg","png","bmp");

	$this->getFilesRecursive($this->map);
	$this->stat();
}
private function getFilesRecursive($dir="")
{
	$dir = $dir."/";
	$handle = opendir($dir);

	$this->directories[$dir] = array();

	while (false !== ($file = readdir($handle)))
	{
		if (is_dir($dir.$file) && $file != "." && $file != "..")
		{
			$this->getFilesRecursive($dir.$file);
		}
		elseif (is_file($dir.$file))
		{
			$this->directories[$dir][] = $file;
		}
	}
}
private function stat()
{
	foreach ($this->directories as $dir => $files)
	{
		foreach ($files as $file)
		{
			$ext = explode(".",$file);
			$ext = strtolower($ext[count($ext)-1]);
			$contents = file_get_contents($dir."/".$file);

			if ($ext == "php" || $ext == "js")
			{
				$strlen = strlen(str_replace(array("\n","\r","\t"),"",$contents));
				$lines = count(explode("\n",$contents));

				(int)$this->stats['strlen'] += $strlen;
				(int)$this->stats['lines'] += $lines;

				$this->directories[$dir]['^strlen'] += $strlen;
				$this->directories[$dir]['^lines'] += $lines;
			}
			elseif (in_array($ext,$this->ext_img))
			{
				(int)$this->stats['images']++;
				$this->directories[$dir]['^images']++;
			}
		}
	}
}
}

$stats = new Stats($map);
echo "<pre>";
print_r($stats->directories);
echo "</pre>";

echo "<pre>";
print_r($stats->stats);
echo "</pre>";
?>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...