codeclimate / codeclimate-phpmd

Code Climate PHPMD Engine
MIT License
10 stars 12 forks source link

PHPMD times out on Code Climate #30

Open josephdpurcell opened 7 years ago

josephdpurcell commented 7 years ago

Problem

Here is the error:

An engine timed out
E11

The phpmd engine failed to complete in time.

Engine timeouts are generally caused by either an abnormally large number of files under analysis or from attempting to analyze a file not typically intended for static analysis. We recommend excluding:

    Third party libraries
    Production assets, such as minimized or cross-compiled files
    Automated test suites

For more information, see our documentation on file and path exclusions.

I experienced this on these repos:

I expect this will be a common problem for other large PHP projects.

Proposed Solution

I see at least two options:

  1. Investigate to see why PHPMD takes longer than PHPCS or other engines.
  2. Set the default timeout limit just for the PHPMD engine to 30 mins instead of 15 mins.
josephdpurcell commented 7 years ago

I just ran:

 phpmd src/ text .phpmd.xml

on the platform repository and after 104 mins there was no activity, so either (a) PHPMD is still crunching data, or (b) there is a bug in PHPMD causing it to silently fail without exiting. There is an open ticket for phpmd to show progress: https://github.com/phpmd/phpmd/issues/94

josephdpurcell commented 7 years ago

I did a comparison of how much code is in Drupal 8.2 vs Platform:

Platform

Directories                                       3438
Files                                             9497

Size
  Lines of Code (LOC)                          1043550
  Comment Lines of Code (CLOC)                  206410 (19.78%)
  Non-Comment Lines of Code (NCLOC)             837140 (80.22%)
  Logical Lines of Code (LLOC)                  248106 (23.78%)
    Classes                                     204138 (82.28%)
      Average Class Length                          21
        Minimum Class Length                         0
        Maximum Class Length                       493
      Average Method Length                          3
        Minimum Method Length                        0
        Maximum Method Length                       61
    Functions                                        0 (0.00%)
      Average Function Length                        0
    Not in classes or functions                  43968 (17.72%)

Cyclomatic Complexity
  Average Complexity per LLOC                     0.12
  Average Complexity per Class                    4.12
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    143.00
  Average Complexity per Method                   1.61
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    37.00

Dependencies
  Global Accesses                                   21
    Global Constants                                 0 (0.00%)
    Global Variables                                 3 (14.29%)
    Super-Global Variables                          18 (85.71%)
  Attribute Accesses                             73446
    Non-Static                                   73079 (99.50%)
    Static                                         367 (0.50%)
  Method Calls                                  235211
    Non-Static                                  228363 (97.09%)
    Static                                        6848 (2.91%)

Structure
  Namespaces                                      3381
  Interfaces                                       497
  Traits                                            95
  Classes                                         8820
    Abstract Classes                               291 (3.30%)
    Concrete Classes                              8529 (96.70%)
  Methods                                        47850
    Scope
      Non-Static Methods                         46931 (98.08%)
      Static Methods                               919 (1.92%)
    Visibility
      Public Methods                             37056 (77.44%)
      Non-Public Methods                         10794 (22.56%)
  Functions                                       1631
    Named Functions                                  0 (0.00%)
    Anonymous Functions                           1631 (100.00%)
  Constants                                       3695
    Global Constants                                 0 (0.00%)
    Class Constants                               3695 (100.00%)

Drupal 8.2

Directories                                       1668
Files                                             6422

Size
  Lines of Code (LOC)                           907915
  Comment Lines of Code (CLOC)                  296583 (32.67%)
  Non-Comment Lines of Code (NCLOC)             611332 (67.33%)
  Logical Lines of Code (LLOC)                  197288 (21.73%)
    Classes                                     171241 (86.80%)
      Average Class Length                          27
        Minimum Class Length                         0
        Maximum Class Length                       619
      Average Method Length                          6
        Minimum Method Length                        0
        Maximum Method Length                      211
    Functions                                      830 (0.42%)
      Average Function Length                        0
    Not in classes or functions                  25217 (12.78%)

Cyclomatic Complexity
  Average Complexity per LLOC                     0.14
  Average Complexity per Class                    5.24
    Minimum Class Complexity                      1.00
    Maximum Class Complexity                    358.00
  Average Complexity per Method                   2.00
    Minimum Method Complexity                     1.00
    Maximum Method Complexity                    64.00

Dependencies
  Global Accesses                                  383
    Global Constants                               104 (27.15%)
    Global Variables                               240 (62.66%)
    Super-Global Variables                          39 (10.18%)
  Attribute Accesses                             49765
    Non-Static                                   49360 (99.19%)
    Static                                         405 (0.81%)
  Method Calls                                  170799
    Non-Static                                  154021 (90.18%)
    Static                                       16778 (9.82%)

Structure
  Namespaces                                      1617
  Interfaces                                       516
  Traits                                            90
  Classes                                         5671
    Abstract Classes                               307 (5.41%)
    Concrete Classes                              5364 (94.59%)
  Methods                                        28487
    Scope
      Non-Static Methods                         26687 (93.68%)
      Static Methods                              1800 (6.32%)
    Visibility
      Public Methods                             22929 (80.49%)
      Non-Public Methods                          5558 (19.51%)
  Functions                                        971
    Named Functions                                327 (33.68%)
    Anonymous Functions                            644 (66.32%)
  Constants                                        372
    Global Constants                                35 (9.41%)
    Class Constants                                337 (90.59%)

Commentary

Platform has ~25% more logical lines of code than Drupal 8.2. Drupal 8.2 has been taking on average around 11 mins to complete: https://codeclimate.com/github/josephdpurcell/drupal-8.2.x/builds. I would expect Platform to take ~25% longer, i.e. ~14 mins.

I think the next step would be to either (a) request Code Climate bump the Platform repo's timeout limit to an hour and see if it eventually completes, or (b) modify the PHPMD library locally to add some debug output and see why it took 104 mins last time without completion.