如果我对我的一个
PHP项目(开源)运行PHPloc,我会看到这个输出.
- 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
通过这种静态分析,如何判断这个代码库是好还是坏?或者写得有多好或多坏?
>如果太低或太高,圈复杂性是否良好?
> 3.57%的抽象类是好还是坏?
> 14.09%静态方法.它应该在OOP代码库中更低吗?
>没有使用命名空间,是好还是坏?
低圈复杂度好,高度差;
statics are hard to unit test,但(虽然有些人认为它们和eval一样糟糕)但它们确实有用;来自PHPloc的其他措施需要解释.
但你真的应该使用PHPloc和其他工具,如pdepend和phpmd.pdepend网站特别解释了很多使用的分析,而PHPmd输出是非常明显的
编辑
作为比较,我正在处理的代码(https://github.com/MarkBaker/PHPGeodetic):我对抽象/具体类的级别感到满意,尽管它可能会更高一些;我有一种方法具有更高的圈复杂度,足以使这些数字略微偏斜,但这并不容易导致被破坏;以及一些较长的方法(但不足以触发PHPmd警告).
- 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
总的来说,我很想使用公共/私人,非静态/静态和混凝土/抽象的80:20规则;但很大程度上取决于你实际编码的内容
可能更重要的是Cyclomatic Complexity / Methods of Methods …我不喜欢这个数字太高;但如果它高于2.5平均值,我会更加密切地关注PHPmd统计数据