A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
PHP
项目大小和分析结构的工具。
-bash/zsh: phploc command not found #Debian apt-get install phploc #Ubuntu apt-get install phploc #Kali Linux apt-get install phploc #Fedora dnf install phploc #Raspbian apt-get install phploc ------------ 通过下载PHP Archive (PHAR) 方式: $ wget https://phar.phpunit.de/phploc.phar $ php phploc.phar --version 也可以通过 Phive 方式,Phive 是管理项目工具依赖项的推荐方式,建议用此方式: $ phive install phploc $ ./tools/phploc --version ------------ 注意,并不建议用 Composer 方式下载安装此工具.
当需要对 PHP 代码库的项目代码质量和结构有一个非常粗略的了解时,可以运行 phploc
。这是由 Sebastian Bergmann 开发而创建的开源工具。
phploc 统计结果类似如下:
$ php phploc.phar /web/php-code/ phploc 7.0.2 by Sebastian Bergmann. Directories 129 Files 1025 Size Lines of Code (LOC) 457878 Comment Lines of Code (CLOC) 63968 (13.97%) Non-Comment Lines of Code (NCLOC) 393910 (86.03%) Logical Lines of Code (LLOC) 51239 (11.19%) Classes 43050 (84.02%) Average Class Length 53 Minimum Class Length 0 Maximum Class Length 2961 Average Method Length 7 Minimum Method Length 0 Maximum Method Length 879 Average Methods Per Class 7 Minimum Methods Per Class 0 Maximum Methods Per Class 161 Functions 7405 (14.45%) Average Function Length 19 Not in classes or functions 784 (1.53%) Cyclomatic Complexity Average Complexity per LLOC 0.37 Average Complexity per Class 21.61 Minimum Class Complexity 1.00 Maximum Class Complexity 1027.00 Average Complexity per Method 3.96 Minimum Method Complexity 1.00 Maximum Method Complexity 387.00 Dependencies Global Accesses 315 Global Constants 188 (59.68%) Global Variables 23 (7.30%) Super-Global Variables 104 (33.02%) Attribute Accesses 19966 Non-Static 19066 (95.49%) Static 900 (4.51%) Method Calls 25039 Non-Static 20482 (81.80%) Static 4557 (18.20%) Structure Namespaces 74 Interfaces 31 Traits 2 Classes 778 Abstract Classes 53 (6.81%) Concrete Classes 725 (93.19%) Final Classes 5 (0.69%) Non-Final Classes 720 (99.31%) Methods 5813 Scope Non-Static Methods 4687 (80.63%) Static Methods 1126 (19.37%) Visibility Public Methods 4588 (78.93%) Protected Methods 281 (4.83%) Private Methods 944 (16.24%) Functions 371 Named Functions 328 (88.41%) Anonymous Functions 43 (11.59%) Constants 1181 Global Constants 44 (3.73%) Class Constants 1137 (96.27%) Public Constants 1120 (98.50%) Non-Public Constants 17 (1.50%)
phploc [options] <directory>
Options for selecting files: --suffix <suffix> Include files with names ending in <suffix> in the analysis (default: .php; can be given multiple times) --exclude <path> Exclude files with <path> in their path from the analysis (can be given multiple times) Options for analysing files: --count-tests Count PHPUnit test case classes and test methods Options for report generation: --log-csv <file> Write results in CSV format to <file> --log-json <file> Write results in JSON format to <file> --log-xml <file> Write results in XML format to <file>
phploc 分析一个目录并打印结果:
phploc path/to/directory
phploc 仅包含逗号分隔列表中的特定文件(允许使用 glob):
phploc path/to/directory --names files
phploc 从逗号分隔的列表中排除特定文件(允许使用 glob):
phploc path/to/directory --names-exclude files
从 phploc 分析中排除特定目录:
phploc path/to/directory --exclude path/to/exclude_directory
phploc 将结果记录到特定的 CSV 文件:
phploc path/to/directory --log-csv path/to/file
phploc 将结果记录到特定的 XML 文件中:
phploc path/to/directory --log-xml path/to/file
phploc 统计 PHPUnit
测试用例类和测试方法:
phploc path/to/directory --count-tests