<?php
/**
* @author Xiaoxiao <x_824@sina.com> 2011-1-12
* @link http://xiaoyaoxia.cnblogs.com/
* @license
* Number of rows and total files in the statistics directory · Remove annotations
*/
$obj = new Caculatefiles ();
If set to False, this does not display information for each file, otherwise the display
$obj->setshowflag (FALSE);
Skips all files beginning with all
$obj->setfileskip (' all '));
$obj->run ("D:\PHPAPP\php\_tests");
All files, (the default format is. php)
$obj->setfileskip (Array ());
$obj->run ("D:\PHPAPP\php");
$obj->setshowflag (TRUE);
Skip all files starting with I and a, such as interfaces and abstract classes begin
$obj->setfileskip (Array (' I ', ' A '));
$obj->run ("D:\PHPAPP\php");
/**
* Statistics of files in the execution directory (including file number and total number of rows)
*
* 1, skip the file when:
* The matching rule only starts with the filename, and the matching rule is only at the beginning.
* 2, skip the comment line in the file:
* The matching rules are only matched from the header of the annotation paragraph, and if the line and empty rows at the beginning of the///and #及/* are skipped. So like/* This hyperhidrosis annotation, each line must be preceded by a * number, otherwise it will not be able to match the annotation.
* 3, Directory filter:
* The matching rule is to match the full name of the directory name
*/
Class Caculatefiles {
/**
* The suffix of statistics
*/
Private $ext = ". php";
/**
* Show statistics for each file
*/
Private $showEveryFile = true;
/**
* Skip rule for file
*/
Private $fileSkip = Array ();
/**
* Skip line rule for statistics
*/
Private $lineSkip = Array ("*", "/*", "//", "#");
/**
* Statistics skipped directory rules
*/
Private $dirSkip = Array (".", "..", '. svn ');
The Public function __construct ($ext = ', $dir = ', $showEveryFile = true, $dirSkip = Array (), $lineSkip = Array (), $fileSki p = Array ()) {
$this->setext ($ext);
$this->setdirskip ($DIRSKIP);
$this->setfileskip ($FILESKIP);
$this->setlineskip ($LINESKIP);
$this->setshowflag ($showEveryFile);
$this->run ($dir);
}
Public Function Setext ($ext) {
Trim ($ext) && $this->ext = Strtolower (Trim ($ext));
}
Public Function Setshowflag ($flag = True) {
$this->showeveryfile = $flag;
}
Public Function Setdirskip ($dirSkip) {
$dirSkip && Is_array ($dirSkip) && $this->dirskip = $dirSkip;
}
Public Function Setfileskip ($fileSkip) {
$this->fileskip = $fileSkip;
}
Public Function Setlineskip ($lineSkip) {
$lineSkip && Is_array ($lineSkip) && $this->lineskip = Array_merge ($this->lineskip, $lineSkip);
}
/**
* Implementation Statistics
* @param a directory of string $dir statistics
*/
Public function Run ($dir = ') {
if ($dir = = ") return;
if (!is_dir ($dir)) exit (' Path error! ');
$this->dump ($dir, $this->readdir ($dir));
}
/**
* Show Statistic results
* @param string $dir directory
* @param array $result Statistical results (including total number of rows, valid functions, number of files
*/
Private function Dump ($dir, $result) {
$totalLine = $result [' Totalline '];
$lineNum = $result [' LineNum '];
$fileNum = $result [' FileNum '];
echo "*************************************************************\r\n<br/>";
Echo $dir. ":\r\n<br/>";
echo "Totalline:". $totalLine. "\r\n<br/>";
echo "Totalline with no comment and empty:". $lineNum. "\r\n<br/>";
Echo ' Totalfiles: '. $fileNum. "\r\n<br/>";
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.