Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Class Namespace is Calculated Twice: in Global and Its Own Namespace #210

Closed
buskamuza opened this issue Jul 7, 2015 · 2 comments
Labels
Milestone

Comments

@buskamuza
Copy link

Tested on version 2.1.0.

Preparations:

  • updated \PDepend\Metrics\Analyzer\CouplingAnalyzer::calculateCoupling() to collect names and namespaces of dependencies
// added
        $this->dependencyMap[
            $declaringType->getId()
        ]['ce_name'][
            $coupledType->getNamespaceName() . '|' . $coupledType->getName()
        ] = true;
  • updated \PDepend\Metrics\Analyzer\CouplingAnalyzer::postProcessTemporaryCouplingMap() to display the result
// added
            if ($efferentCoupling > 0) {
                print_r($metrics);
            }

Tested classes:

// file A.php
<?php

namespace A
{
    class AB
    {
    }
}
// file B.php
<?php
namespace B
{
    require __DIR__ . '/A.php';

    use A\AB;
    class BB
    {
        /**
         * @var AB
         */
        private $ab;

        /**
         * @param AB $ab
         */
        public function __construct(AB $ab)
        {
            $this->ab = $ab;
        }
    }
}

namespace {
    new \B\BB(new \A\AB());
}

Testing

Run ./vendor/bin/pdepend --summary-xml=sum.xml --debug B.php

Result:

Creating: \PDepend\Source\AST\ASTNamespace(A)Array
(
    [ce] => Array
        (
            [9a74e5f40008955331d573e1be4a7c65] => 1
            [c58960fdb6e366bb58224210d4b330b1] => 1
        )

    [ca] => Array
        (
        )

    [ce_name] => Array
        (
            [+global|AB] => 1
            [A|AB] => 1
        )

)

Any of the following fixes the issue and pdepend finds only one class AB:

  1. Remove phpDoc for the $ab field
  2. Declare whole namespace A in the same B.php file instead of requiring it
@buskamuza buskamuza changed the title Loaded Class is Considered in Global Namespace Partial Class Namespace is Calculated Twice: in Global and Its Own Namespace Jul 15, 2015
@buskamuza
Copy link
Author

Discovered that it happens only if pdepend analyzes a single file. If it analyzed a folder with both files (for class AB and BB), everything is calculated correctly.

@manuelpichler manuelpichler added this to the 2.3.0 milestone Sep 20, 2015
@tkolodziej-zz
Copy link

I have same issue. Efferent coupling depends on analyze scope.
In my case:
ce = 15 when only one file is analyzed
ce = 13 when my code is analyzed
In fact correct value is 11 because 2 classes are outside of scope (in vendor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants