1.代码质量 phploc phpcpd phpmd
PHPLOC 代码成分
https://github.com/sebastianbergmann/phploc yuezh:framework yuezh$ phploc YiiBase.php --log-xml=/Users/shushuy/Sites/phploc.xml
phploc 2.0.2 by Sebastian Bergmann.
Size
Lines of Code (LOC) 845
Comment Lines of Code (CLOC) 283 (33.49%)
Non-Comment Lines of Code (NCLOC) 562 (66.51%)
Logical Lines of Code (LLOC) 117 (13.85%)
Classes 108 (92.31%)
Average Class Length 108
Average Method Length 5
Functions 0 (0.00%)
Average Function Length 0
Not in classes or functions 9 (7.69%)
Complexity
Cyclomatic Complexity / LLOC 0.66
Cyclomatic Complexity / Number of Methods 4.33
Dependencies
Global Accesses 11
Global Constants 11 (100.00%)
Global Variables 0 (0.00%)
Super-Global Variables 0 (0.00%)
Attribute Accesses 48
Non-Static 1 (2.08%)
Static 47 (97.92%)
Method Calls 25
Non-Static 6 (24.00%)
Static 19 (76.00%)
Structure
Namespaces 0
Interfaces 0
Traits 0
Classes 1
Abstract Classes 0 (0.00%)
Concrete Classes 1 (100.00%)
Methods 21
Scope
Non-Static Methods 0 (0.00%)
Static Methods 21 (100.00%)
Visibility
Public Method 20 (95.24%)
Non-Public Methods 1 (4.76%)
Functions 0
Named Functions 0 (0.00%)
Anonymous Functions 0 (0.00%)
Constants 7
Global Constants 7 (100.00%)
Class Constants 0 (0.00%)
PHPCpd 代码复制
https://github.com/sebastianbergmann/phpcpd
Time: 603 ms, Memory: 36.25Mb
yuezh:commands yuezh$ phpcpd --names *.php
phpcpd 2.0.0 by Sebastian Bergmann.
Found 43 exact clones with 2154 duplicated lines in 14 files:
- /Users/shushuy/Sites/finance-fork-yuezh/apps/finance/protected/commands/FinanceRejoStatsCommand.php:146-178
/Users/shushuy/Sites/finance-fork-yuezh/apps/finance/protected/commands/FinanceRejoStatsCommand.php:484-516
- /Users/shushuy/Sites/finance-fork-yuezh/apps/finance/protected/commands/FinanceRmaStatsCommand.php:251-273
/Users/shushuy/Sites/finance-fork-yuezh/apps/finance/protected/commands/FinanceRmaStatsCommand.php:590-612
- /Users/shushuy/Sites/finance-fork-yuezh/apps/finance/protected/commands/LogisticCodStatsByWareHouseCommand.php:64-92
/Users/shushuy/Sites/finance-fork-yuezh/apps/finance/protected/commands/LogisticCodStatsCommand.php:16-44
- /Users/shushuy/Sites/finance-fork-yuezh/apps/finance/protected/commands/LogisticCodStatsByWareHouseCommand.php:439-471
/Users/shushuy/Sites/finance-fork-yuezh/apps/finance/protected/commands/LogisticCodStatsCommand.php:342-374
- /Users/shushuy/Sites/finance-fork-yuezh/apps/finance/protected/commands/LogisticCodStatsByWareHouseCommand.php:470-517
/Users/shushuy/Sites/finance-fork-yuezh/apps/finance/protected/commands/LogisticCodStatsCommand.php:373-420
9.41% duplicated lines out of 22885 total lines of code.
Time: 566 ms, Memory: 34.75Mb
PHPmd 代码建议
http://phpmd.org/download/release/1.5.0/changelog.html
http://tech.it168.com/a2011/0511/1189/000001189319_all.shtml
2.代码标准 phpcs
https://github.com/opensky/Symfony2-coding-standard
http://phpgeek.diandian.com/post/2011-11-20/6957719
3.代码文档 phpdoc
http://www.phpdoc.org/
memory_limit = 128M
brew install phpdocumentor
http://blog.163.com/yuki_1154/blog/static/712027712014111535094/
http://blog.163.com/lvshutao@126/blog/static/164637467201361015245978/
4.代码效率 xhprof
安装:
yum install php54-xhprof
cp xhprof_html xhprof_lib 到可执行php路径下,查看生成报告
配置:
[xhprof]
extension=xhprof.so;
xhprof.output_dir=/tmp/xhprof
语法:
- xhprof_disable — 停止 xhprof 分析器
- xhprof_enable — 启动 xhprof 性能分析器
- xhprof_sample_disable — 停止 xhprof 性能采样分析器
- xhprof_sample_enable — 以采样模式启动 XHProf 性能分析
http://blog.51yip.com/php/1099.html
报告:
http://aofengblog.blog.163.com/blog/static/6317021201341851510578/