phpmd / phpmd

PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.

Home Page:https://phpmd.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change class namespace rises coupling between objects violation

astronom opened this issue · comments

  • PHPMD version: 2.12.0
  • PHP Version: 8.0.18
  • Installation type: composer
  • Operating System: Docker container php:8.0.17-fpm-alpine3.15

Current Behavior

Before changes. SomeHandlerTest has coupling between objects - 12 (13 is the max default value)

namespace App\Tests\functional\Action\Handler\SomeHandler;

use ....;
use App\Tests\functional\ApiTestCase;

final class SomeHandlerTest extends ApiTestCase
{
.... some code here
}

PHPMD reports that there is no violations

Then we want to replace namespace App\Tests\functional to App\Tests\Functional

After changes. No other code changed

namespace App\Tests\Functional\Action\Handler\SomeHandler;

use ....;
use App\Tests\Functional\ApiTestCase;

final class SomeHandlerTest extends ApiTestCase
{
.... some code here
}

PHPMD reports:

FILE: /var/www/html/tests/functional/Action/Handler/Player/PersonalBonus/SomeHandlerTest.php
----------------------------------------------------------------------------------------------------------
 24 | VIOLATION | The class CheckPersonalBonusHandlerTest has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13.
 24 | VIOLATION | The class CheckPersonalBonusHandlerTest has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13.

vendor/bin/phpmd /var/www/html/tests/functional/Action/Handler/SomeHandlerTest.php ansi design

On the next run there is no violations

Expected Behavior

Expect no vioalations

Checks before submitting

  • Be sure that there isn't already an issue about this. See: Issues list
  • Be sure that there isn't already a pull request about this. See: Pull requests
  • I have added every step to reproduce the bug.
  • If possible I added relevant code examples.
  • This issue is about 1 bug and nothing more.
  • The issue has a descriptive title. For example: "JSON rendering failed on Windows for filenames with space".