=> 0, ''lineNum'' => 0, ''fileNum'' => 0);
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($this->skipDir($file)) continue;
if (is_dir($dir . ''/'' . $file)) {
$result = $this->readDir($dir . ''/'' . $file);
$num[''totalLine''] += $result[''totalLine''];
$num[''lineNum''] += $result[''lineNum''];
$num[''fileNum''] += $result[''fileNum''];
} else {
if ($this->skipFile($file)) continue;
list($num1, $num2) = $this->readfiles($dir . ''/'' . $file);
$num[''totalLine''] += $num1;
$num[''lineNum''] += $num2;
$num[''fileNum'']++;
}
}
closedir($dh);
} else {
echo ''open dir <'' . $dir . ''> error!'' . "\r";
}
return $num;
}
/**
* 读取文件
* @param string $file 文件
*/
private function readfiles($file) {
$str = file($file);
$linenum = 0;
foreach ($str as $value) {
if ($this->skipLine(trim($value))) continue;
$linenum++;
}
$totalnum = count(file($file));
if (!$this->showEveryFile) return array($totalnum, $linenum);
echo $file . "\r\n";
echo ''TotalLine in the file:'' . $totalnum . "\r\n";
echo ''TotalLine with no comment and empty in the file:'' . $linenum . "\r\n";
return array($totalnum, $linenum);
}
/**
* 执行跳过的目录规则
* @param string $dir 目录名
*/
private function skipDir($dir) {
if (in_array($dir, $this->dirSkip)) return true;
return false;
}
/**
* 执行跳过的文件规则
* @param string $file 文件名
*/
private function skipFile($file) {
if (strtolower(strrchr($file, ''.'')) != $this->ext) return true;
if (!$this->fileSkip) return false;
foreach ($this->fileSkip as $skip) {
if (strpos($file, $skip) === 0) return true;
}
return false;
}
/**
* 执行文件中行的跳过规则
* @param string $string 行内容
*/
private function skipLine($string) {
if ($string == '''') return true;
foreach ($this->lineSkip as $tag) {
if (strpos($string, $tag) === 0) return true;
}
return false;
}
}