phploc输出说明 [英] phploc output explanation
问题描述
如果我对我的一个PHP项目(开放源代码)运行 phploc
,则会看到此输出。
<$ p Sebastian Bergmann编写的$ p>
phploc 1.6.4。
目录:3
文件:33
代码行(LOC):2358
复杂度/代码行:0.08
代码注释行(CLOC):903
非注释代码行(NCLOC):1455
命名空间:0
接口:3
类:28
摘要:1(3.57%)
混凝土:27(96.43%)
平均课堂长度(NCLOC):49
方法:149
范围:
非静态:128(85.91%)
静态:21(14.09%)
可见性:
公众:103(69.13%)
非公开:46(30.87%)
平均方法长度(NCLOC):9
循环复杂性/方法数量:1.69
匿名函数:0
函数:3
常数:9
全局常数:0
类常数:9
通过这种静态分析,如何判断此代码库是好是坏?还是写得好或不好?
- 如果圈复杂度太低或太高,则循环复杂度好吗?
- 具有
3.57%
抽象类是好是坏? -
14.09%
静态方法。 - 没有使用命名空间,是好是坏?
最后一个问题您如何使用phploc的输出分析代码库?
低圈复杂度好,高则不好; 静态元素很难进行单元测试,但是(尽管有些人认为它们与评估一样糟糕),它们确实可以达到目的。
但是您应该真正将phploc与其他工具(例如)一起使用pdepend 和 phpmd 。 pdepend站点特别说明了很多分析方法,而phpmd输出非常不言自明
编辑
作为比较,我当前正在使用的代码( https://github.com/ MarkBaker / PHPGeodetic ):我对抽象/具体类的级别感到满意,尽管它可能会更高一些。我有一种方法具有较高的圈数复杂度,足以使这些数字有些偏斜,但这种方法并不容易分解。以及一些更长的方法(但不足以触发phpmd警告)。
代码行(LOC):4003
循环复杂度/代码行:0.07
评论代码行(CLOC):1580
非注释代码行(NCLOC):2423
命名空间:0
接口:1
特性:0
类:25
摘要:4(16.00%)
具体:21(84.00%)
平均类长度(NCLOC):103
方法:160
范围:
非静态:129(80.62%)
静态: 31(19.38%)
可见性:
公众:131(81.88%)
非公开:29(18.12%)
平均方法长度(NCLOC):16
圈复杂度/方法数量:2.12
匿名函数:2
函数:0
常数:66
全局常数:0
类常量:66
总的来说,我很想使用80:20的公共规则/私人,非静态/静态和具体/摘要;但是很大程度上取决于您实际编码的内容
可能更重要的是循环复杂度/方法数量...我不希望这个数字过高;但是如果它升到2.5以上的平均值,我会更仔细地查看phpmd统计信息
If I run phploc
against one of my PHP project (open source) I see this output.
phploc 1.6.4 by Sebastian Bergmann.
Directories: 3
Files: 33
Lines of Code (LOC): 2358
Cyclomatic Complexity / Lines of Code: 0.08
Comment Lines of Code (CLOC): 903
Non-Comment Lines of Code (NCLOC): 1455
Namespaces: 0
Interfaces: 3
Classes: 28
Abstract: 1 (3.57%)
Concrete: 27 (96.43%)
Average Class Length (NCLOC): 49
Methods: 149
Scope:
Non-Static: 128 (85.91%)
Static: 21 (14.09%)
Visibility:
Public: 103 (69.13%)
Non-Public: 46 (30.87%)
Average Method Length (NCLOC): 9
Cyclomatic Complexity / Number of Methods: 1.69
Anonymous Functions: 0
Functions: 3
Constants: 9
Global constants: 0
Class constants: 9
With this static analysis how do tell if this code-base is good or bad? Or how well or badly written?
- Is cyclomatic complexity good if its too low or high ?
- Having
3.57%
abstract class is good or bad ? 14.09%
static methods. Should it be lower on OOP code-base?- There is no namespace used, is it good or bad ?
The final question How do you analyse a code-base with phploc's output?
Low cyclomatic complexity is good, high is bad; statics are hard to unit test, but (while some people consider them as bad as eval) they do serve a purpose; other measures from phploc are subject to interpretation.
But you should really be using phploc alongside other tools like pdepend, and phpmd. The pdepend site in particular explains a lot of the analytics used, and the phpmd output is pretty self-explanatory
EDIT
As a comparison, the code that I'm currently working on (https://github.com/MarkBaker/PHPGeodetic): I'm reasonably happy with the level of abstract/concrete classes, though it could go a bit higher; I've one method with a higher cyclomatic complexity that's enough to skew those figures a bit, but that doesn't readily lend itself to being broken down; and a handful of longer methods (but not long enough to trigger phpmd warnings).
Lines of Code (LOC): 4003
Cyclomatic Complexity / Lines of Code: 0.07
Comment Lines of Code (CLOC): 1580
Non-Comment Lines of Code (NCLOC): 2423
Namespaces: 0
Interfaces: 1
Traits: 0
Classes: 25
Abstract: 4 (16.00%)
Concrete: 21 (84.00%)
Average Class Length (NCLOC): 103
Methods: 160
Scope:
Non-Static: 129 (80.62%)
Static: 31 (19.38%)
Visibility:
Public: 131 (81.88%)
Non-Public: 29 (18.12%)
Average Method Length (NCLOC): 16
Cyclomatic Complexity / Number of Methods: 2.12
Anonymous Functions: 2
Functions: 0
Constants: 66
Global constants: 0
Class constants: 66
Overall, I'm tempted to work with the 80:20 rule for Public/Private, Non-Static/Static and for Concrete/Abstract; but a great deal depends on what you're actually coding
Probably more important is Cyclomatic Complexity/Number of Methods... I don't like that figure being too high; but if it gets up above a 2.5 average I'll be looking at phpmd stats a lot more closely
这篇关于phploc输出说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!