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

Global namespace dependecies are resolved invalidly within other namespaces #199

Open
montoriusz opened this issue Apr 30, 2015 · 1 comment
Assignees
Labels

Comments

@montoriusz
Copy link

montoriusz commented Apr 30, 2015

Namespace name (and package name) of any global namespace class (like SplObjectStorage in the following examples) is resolved to an empty string.

namespace EcAnalytic\Tables;

use SplObjectStorage;

class QueryBuilder implements IQueryBuilder {

    protected function buildQuery() {
        $this->exprToCol = new SplObjectStorage();
        $this->joins = new SplObjectStorage();
    }
}

The same issue with different usage:

namespace EcAnalytic\Tables;

class QueryBuilder implements IQueryBuilder {

    protected function buildQuery() {
        $this->exprToCol = new \SplObjectStorage();
        $this->joins = new \SplObjectStorage();
    }
}

I get this in xml report:

      <DependsUpon>
        <Package></Package>
      </DependsUpon>

instead of <Package>+spl</Package> in other cases (like a package in gobal namespace annotated with @Package).

The way I checked it was by modifying PDepend\Metrics\Analyzer\DependencyAnalyzer::visitMethod() like this:

public function visitMethod(ASTMethod $method)
    {
        $this->fireStartMethod($method);

        $namespace = $method->getParent()->getNamespace();
        foreach ($method->getDependencies() as $dependency) {
            if ($dependency->getNamespace()->getName() == '')) {
                echo "DEP: ".$namespace->getName().'\\'.$method->getParent()->getName().'::'.$method->getName().PHP_EOL;
                echo " -> ".$dependency->getNamespace()->getName().'::'.$dependency->getName().PHP_EOL;
            }
            $this->collectDependencies($namespace, $dependency->getNamespace());
        }

        $this->fireEndMethod($method);
    }
@montoriusz montoriusz changed the title Global namespace dependecies ale resolved invalidly within other namespaces Global namespace dependecies are resolved invalidly within other namespaces Apr 30, 2015
@manuelpichler manuelpichler self-assigned this Sep 20, 2015
@ravage84
Copy link
Member

This is what I get nowadays with PHP Depend 2.13.0 for both code examples above:

<?xml version="1.0" encoding="UTF-8"?>
<PDepend>
  <Packages>
    <Package name="EcAnalytic\Tables">
      <Stats>
        <TotalClasses>2</TotalClasses>
        <ConcreteClasses>2</ConcreteClasses>
        <AbstractClasses>0</AbstractClasses>
        <Ca>0</Ca>
        <Ce>1</Ce>
        <A>0</A>
        <I>1</I>
        <D>0</D>
      </Stats>
      <ConcreteClasses>
        <Class sourceFile="test.php">QueryBuilder</Class>
      </ConcreteClasses>
      <AbstractClasses/>
      <DependsUpon>
        <Package></Package>
      </DependsUpon>
      <UsedBy/>
    </Package>
  </Packages>
  <Cycles/>
</PDepend>

@ravage84 ravage84 added this to the 2.x (unspecific) milestone May 3, 2024
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