phpmetrics / PhpMetrics

Beautiful and understandable static analysis tool for PHP
https://phpmetrics.github.io/website/
MIT License
2.47k stars 259 forks source link

PhpMetrics v3.0.0-rc6 hanging #510

Open andrii-pukhalevych opened 2 weeks ago

andrii-pukhalevych commented 2 weeks ago

Bug report

PhpMetrics v3.0.0-rc6 Composer version 2.8.1 2024-10-04 11:31:01 PHP version 8.1.29

I created directory PhpMetricsDemo with single class Hello inside:

<?php
class Hello {

    public function start(): void {
        echo 'start';
    }
}

Call of PhpMetrics/bin/phpmetrics PhpMetricsDemo results hanging after output

Parsing all files...
Executing system analyzes...

Hanging seems to be caused by Composer analyzer, because composer is not present in my folder. It should not happens, not all projects have composer.

niconoe- commented 1 week ago

Tested with your snippet using Docker image PHP php:8.1.29-cli and PhpMetrics v3.0.0-rc6 and got no issue (Docker image doesn't have Composer installed).

> docker container run -it --rm -v /tmp/:/app/ -v ~/Projects/GitHub/phpmetrics/PhpMetrics:/phpmetrics --workdir=/app/ php:8.1.29-cli /phpmetrics/bin/phpmetrics PhpMetricsDemo

Parsing all files...
Executing system analyzes...LOC
    Lines of code                               8
    Logical lines of code                       8
    Comment lines of code                       0
    Average volume                              0
    Average comment weight                      0
    Average intelligent content                 0
    Logical lines of code by class              8
    Logical lines of code by method             8

Object oriented programming
    Classes                                     1
    Interface                                   0
    Methods                                     1
    Methods by class                            1
    Lack of cohesion of methods                 1

Coupling
    Average afferent coupling                   0
    Average efferent coupling                   0
    Average instability                         0
    Depth of Inheritance Tree                   1

Package
    Packages                                    1
    Average classes per package                 1
    Average distance                            0
    Average incoming class dependencies         0
    Average outgoing class dependencies         0
    Average incoming package dependencies       0
    Average outgoing package dependencies       0

Complexity
    Average Cyclomatic complexity by class      1
    Average Weighted method count by class      1
    Average Relative system complexity          0
    Average Difficulty                          0

Bugs
    Average bugs by class                       0
    Average defects by class (Kan)              0.15

Violations
    Critical                                    0
    Error                                       0
    Warning                                     0
    Information                                 0

Done

Are you sure about your path? It could be hanging because lots of files are being analyzed.

andrii-pukhalevych commented 1 week ago

What application was used? I my case it was app with single class, but without composer.json/vendor. In system composer was installed.

niconoe- commented 1 week ago

I created a folder in /tmp only with your Hello class (in Hello.php), copy/pasted from this ticket. Nothing more, nothing less. No composer.json, no composer.lock, no vendor folder. Plus, the Docker image I used doesn't have composer installed. I firstly tried with another image with composer installed in system (i.e exactly your status), but I didn't report it here because I thought you didn't have composer at all. Anyway, in the 2 cases, PhpMetrics in v3.0.0-rc6 is behaving as expected.

andrii-pukhalevych commented 1 week ago

Thanks for checking. I found halt reason: I call PhpMetrics/bin/phpmetrics PhpMetricsDemo from directory with many projects. So composerJsonFinder->fetch() in getComposerJsonRequirements() returns composer.json files from all of these projects, not from PhpMetricsDemo only.

Not sure if it bug or another way of phpmetrics launch should be used.

niconoe- commented 1 week ago

This might be a bug similar to #463

I already gave it a try on it but I need to spend more time, and I can't find it right now.

In the meantime, try to run your command being located on your project folder only and it should be OK. Sorry for the inconvinience about it.