输出看起来像这样:
FILE: /home/superCoolUser/mySuperProject/src/Model/SuperModel.php------------------------------------------------------------------------------------------FOUND 6 ERRORS AND 1 WARNINGS AFFECTING 7 LINES------------------------------------------------------------------------------------------ 2 | ERROR | [ ] Missing file doc comment 14 | ERROR | [ ] Missing @category tag in class comment 20 | ERROR | [ ] Missing doc comment for function __construct() 34 | WARNING | [ ] Line exceeds 85 characters; contains 93 characters 57 | ERROR | [x] Opening parenthesis of a multi-line function call must be the last content on the line 60 | ERROR | [ ] Expected "if (...) {\n"; found "if(...) {\n" 63 | ERROR | [x] Closing parenthesis of a multi-line function call must be on a line by itself----------------------------------------------------------------------------PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY----------------------------------------------------------------------------正如您所看到的,phpcbf可以通过键入以下内容自动修复两个错误:
$ phpmd src/ html cleancode --reportfile ~/phpmd.html
复制代码
如果选择
xml
复制代码
输出,您将获得有关规则集的更多信息,如下所示:
The method notThatCoolMethod has a boolean flag argument $badBoolean, which is a certain sign of a Single Responsibility Principle violation. The method superMethod uses an else expression. Else is never necessary and you can simplify the code to work without else. 您可以看到例如违反规则的优先级。然后,您可以使用
这将输出类似的东西:
Size Lines of Code (LOC) 61 Comment Lines of Code (CLOC) 0 (0.00%) Non-Comment Lines of Code (NCLOC) 61 (100.00%) Logical Lines of Code (LLOC) 23 (37.70%) Classes 17 (73.91%) Average Class Length 17 Minimum Class Length 17 Maximum Class Length 17 Average Method Length 3 Minimum Method Length 1 Maximum Method Length 7 Functions 0 (0.00%) Average Function Length 0 Not in classes or functions 6 (26.09%)Cyclomatic Complexity Average Complexity per LLOC 0.26 Average Complexity per Class 7.00 Minimum Class Complexity 7.00 Maximum Class Complexity 7.00 Average Complexity per Method 2.20 Minimum Method Complexity 1.00 Maximum Method Complexity 4.00Dependencies Global Accesses 0 Global Constants 0 (0.00%) Global Variables 0 (0.00%) Super-Global Variables 0 (0.00%) Attribute Accesses 7 Non-Static 7 (100.00%) Static 0 (0.00%) Method Calls 14 Non-Static 14 (100.00%) Static 0 (0.00%)Structure Namespaces 1 Interfaces 0 Traits 0 Classes 1 Abstract Classes 0 (0.00%) Concrete Classes 1 (100.00%) Methods 5 Scope Non-Static Methods 5 (100.00%) Static Methods 0 (0.00%) Visibility Public Methods 3 (60.00%) Non-Public Methods 2 (40.00%) Functions 0 Named Functions 0 (0.00%) Anonymous Functions 0 (0.00%) Constants 1 Global Constants 0 (0.00%) Class Constants 1 (100.00%)这些数据可以为您提供有关该项目的一些线索:
Comment lines of code
复制代码
永远不会好。不加思索地摆脱它。
太高
Average Class length
复制代码
通常也不好。拆分 神班 。
太高
Average Method length
复制代码
也不好。为了解雇你的同事,分开他们。
Cyclomatic complexity
复制代码
可以指出一切和任何东西。信任 CRAP之类的 东西可能更明智。
避免不必要
Dependencies
复制代码
。
简而言之:一个非常简单而有价值的工具。
[h2]PHPCPD(PHP复制过去检测器)[/h2]
Github上
PHPCPD将扫描您的代码库并输出重复的代码。
您可以输入以下命令来使用它:
$ phpcpd src/
复制代码
PHPCPD将产生这种输出:
phpcpd 4.0.0 by Sebastian Bergmann.Found 1 clones with 44 duplicated lines in 2 files: - /home/superUser/src/superFile.php:11-55 /home/superUser/src/superFolder/superFile.php:11-555.04% duplicated lines out of 873 total lines of code.Time: 29 ms, Memory: 4.00MB您可以包含多个文件而不是整个目录,排除某些文件(或路径),甚至可以将结果输出到XML文件中。
但请记住:如果您在代码库中使用DRY原则违规,请记住, 代码重复并不一定意味着DRY违规。
[h2]PHPMND(PHP魔数检测器)[/h2]