phpmetrics / PhpMetrics

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

Wrong LCOM metric when using promoted properties in constructor #485

Closed omidulus closed 1 year ago

omidulus commented 1 year ago

Bug report

v2.8.1

When using constructor promoted properties the application is unable to establish a relationship between the __construct method and other class method, thus artificially increasing LCOM metric.

Example: LCOM here is 2 but should be 1.

<?php
......

class ExpectationExecutionMessageHandler
{
    public function __construct(
        public ExecutorService $executorService
    ) {
    }

    /** @throws ExceptionInterface */
    public function __invoke(DispatchExpectation $dispatchExpectation): void
    {
        $this->executorService->execute($dispatchExpectation->getExpectationUuid());
    }
}
niconoe- commented 1 year ago

This is fixed in the incoming version v3. You can give it a try via composer installation using composer require phpmetrics/phpmetrics:dev-3.x-dev

niconoe- commented 1 year ago

@omidulus The v3.0.0rc1 has just been released. Please give it a try and share your feedback regarding this issue, as it should now be solved.

Thanks a lot!

niconoe- commented 1 year ago

Fixed since v3.0.0rc1. Closing.