php收集多个统计数据(PHP实现统计代码行数小工具)
类别:编程学习 浏览量:2539
时间:2021-10-23 10:15:46 php收集多个统计数据
PHP实现统计代码行数小工具本文实例为大家分享了PHP实现统计代码行数小工具,供大家参考,具体内容如下
为了方面统计编程代码行数,做了一个小工具。
自动统计指定目录以及目录下的所有文件。
|
<?php class TotalCode { /** * 统计当前文件有多少行代码, * @return TotalCodeInfo */ public function totalByFile( $fullFileName ) { $fileContent = file_get_contents ( $fullFileName ); $lines = explode ( "\n" , $fileContent ); $lineCount = count ( $lines ); for ( $i = $lineCount -1; $i > 0; $i -= 1) { $line = $lines [ $i ]; if ( $line != "" ) break ; $lineCount -= 1; //最后几行是空行的要去掉。 } unset( $fileContent ); unset( $lines ); $totalCodeInfo = new TotalCodeInfo(); $totalCodeInfo ->setFileCount(1); $totalCodeInfo ->setLineCount( $lineCount ); return $totalCodeInfo ; } /** * 统计当前目录下(含子目录) * 有多少文件,以及多少行代码 * * totalInfo = array( "fileCount"=>?, "lineCount"=>? ); * * @return TotalCodeInfo */ public function totalByDir( $dirName ) { $fileList = scandir( $dirName ); $totalCodeDir = new TotalCodeInfo(); foreach ( $fileList as $fileName ) { if ( $fileName == "." || $fileName == ".." ) continue ; $fullFileName = $dirName . "/" . $fileName ; if ( is_file ( $fullFileName )) { $totalCodeSub = $this ->totalByFile( $dirName . "/" . $fileName ); } else if ( is_dir ( $fullFileName )) { $totalCodeSub = $this ->totalByDir( $dirName . "/" . $fileName ); } else { $totalCodeSub = new TotalCodeInfo(); } $totalCodeDir ->increaseByOther( $totalCodeSub ); } return $totalCodeDir ; } public function totalByDirOrFile( $dirOrFileName ) { if ( is_dir ( $dirOrFileName )) { return $this ->totalByDir( $dirOrFileName ); } else if ( is_file ( $dirOrFileName )) { return $this ->totalByFile( $dirOrFileName ); } else { return new TotalCodeInfo(); } } public function test() { $re = $this ->totalByDir( "/export/www/pm_web/configs" ); var_dump( $re ); } public function main( $dirList ) { $totalCodeAll = new TotalCodeInfo(); foreach ( $dirList as $dirName ) { $totalCodeSub = $this ->totalByDirOrFile( $dirName ); $totalCodeAll ->increaseByOther( $totalCodeSub ); } print_r( $totalCodeAll ); } } class TotalCodeInfo { private $fileCount = 0; private $lineCount = 0; public function getFileCount() { return $this ->fileCount; } public function getLineCount() { return $this ->lineCount; } public function setFileCount( $fileCount ) { $this ->fileCount = $fileCount ; return $this ; } public function setLineCount( $lineCount ) { $this ->lineCount = $lineCount ; return $this ; } /** * 累加 */ public function increaseByOther( $totalCodeInfo ) { $this ->setFileCount( $this ->fileCount + $totalCodeInfo ->getFileCount()); $this ->setLineCount( $this ->lineCount + $totalCodeInfo ->getLineCount()); return $this ; } } $dirList = array (); $dirList [] = "/your/path" ; $obj = new TotalCode(); $obj ->main( $dirList ); |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持开心学习网。
原文链接:https://blog.csdn.net/oushunbao/article/details/84794069
您可能感兴趣
- thinkphp5.1请求流程(ThinkPHP5.0框架使用build 自动生成模块操作示例)
- redis在php怎么使用(Windows服务器中PHP如何安装redis扩展)
- php命名空间真的存在吗(PHP中命名空间的使用例子)
- phpstudy8.0使用教程视频(phpstudy v8.1 Apache伪静态配置图文教程)
- dedecms的dedesql.class.php on line 489错误的解决方法(dedecms的dedesql.class.php on line 489错误的解决方法)
- php开发技巧和方法(php+ajax实现商品对比功能示例)
- php运行实例(php实例化一个类的具体方法)
- phpstudy默认不支持64位php的解决方法(phpstudy默认不支持64位php的解决方法)
- php怎样创建新文件详情(php文件后缀不强制为.php的实操方法)
- vuephp后台开发框架(Vue+thinkphp5.1+axios实现文件上传)
- php微信支付步骤(PHP实现微信提现企业付款到零钱)
- phpstudy怎么升级mysql(phpStudy中升级MySQL版本到5.7.17的方法步骤)
- php面向对象编程代码(php面向对象程序设计入门教程)
- wordpress的静态php页面在哪(如何让PHPnow支持wordpress静态化链接的方法)
- php判断类的属性的修饰(PHP whois查询类定义与用法示例)
- php怎么实现动态配置(php实现映射操作实例详解)
- 清华大学难考吗(清华大学考研录取分数线)
- 观花盆栽佛肚竹盆景制作及养护(观花盆栽佛肚竹盆景制作及养护)
- 春天养佛肚竹,做好这几件事,叶绿根壮寓意好 越养越旺家(春天养佛肚竹做好这几件事)
- 律界衣品最好,时尚圈学识数高,41岁的Amal堪称现实版的傲骨贤妻(时尚圈学识数高)
- 刘智泰确认出演《Good Wife》 担纲男一号(刘智泰确认出演Good)
- 《傲骨之战》剧终 律政女魔头Diane,为什么是大女主天花板(傲骨之战剧终律政女魔头Diane)
热门推荐
- linux如何安装php7.1.5环境(vmware linux系统安装最新的php7图解)
- mvc中Scripts.Render、Styles.Render
- , , 的区别
- php全栈之路教程(PHP进阶学习之依赖注入与Ioc容器详解)
- 创建jsp时如何默认生成的是utf-8(js判断文件是否为utf-8编码的方法)
- dedecms默认模板目录(DEDECMS 5.7 将data目录迁移后,网站地图无法打开和更新的解决方法)
- laravel多线程处理请求(Laravel 6 将新增为指定队列任务设置中间件的功能)
- php代码打包环境加密(php实现对文件压缩简单的方法)
- linux中ipconfig命令的功能(Linux ipcs命令的使用)
- divcss页面布局步骤(横向两列布局左列固定,右列自适应的4种CSS实现方式)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9