phploc output explanation

馋奶兔 提交于 2020-01-22 12:32:06

问题


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?

  1. Is cyclomatic complexity good if its too low or high ?
  2. Having 3.57% abstract class is good or bad ?
  3. 14.09% static methods. Should it be lower on OOP code-base?
  4. There is no namespace used, is it good or bad ?

The final question How do you analyse a code-base with phploc's output?


回答1:


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



来源:https://stackoverflow.com/questions/13937676/phploc-output-explanation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!